Sha256: bad609b7faed62cfd1885a1e4be7145dcc5e40e972a1921d5b8f1f66f5482db1

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

class TestRoleAssignment < TestYaoResource

  def test_role_assignment

    # https://docs.openstack.org/api-ref/identity/v3/?expanded=validate-and-show-information-for-token-detail,list-role-assignments-detail#list-role-assignments
    params = {
      "links" => {
        "assignment" => "http://example.com/identity/v3/domains/161718/users/313233/roles/123456"
      },
      "role" => {
        "id" => "123456"
      },
      "scope" => {
        "project" => {
          "id" => "456789"
        }
      },
      "user" => {
        "id" => "313233"
      }
    }

    role_assignment = Yao::RoleAssignment.new(params)
    assert_equal(role_assignment.scope, { "project" => { "id" => "456789" } })

    # map_attribute_to_resource
    assert_instance_of(Yao::Resources::Role, role_assignment.role)
    assert_equal(role_assignment.role.id, "123456")

    # map_attribute_to_resource
    assert_instance_of(Yao::Resources::User, role_assignment.user)
    assert_equal(role_assignment.user.id, "313233")
  end

  def test_project
    stub = stub_request(:get, "http://example.com:12345/tenants/456789").
      to_return(
        status: 200,
        body: <<-JSON,
        {
          "tenant": {
            "id": "456789"
          }
        }
        JSON
        headers: {'Content-Type' => 'application/json'}
      )

    params = {
      "scope" => {
        "project" => {
          "id" => "456789"
        }
      },
    }

    role_assignment = Yao::RoleAssignment.new(params)
    assert_instance_of(Yao::Resources::Tenant, role_assignment.project)
    assert_equal(role_assignment.project.id, "456789")

    assert_requested(stub)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yao-0.8.0 test/yao/resources/test_role_assignment.rb