def setUp(self): self.url = IDENTITY_ENDPOINT_URL self.serialized_format = "json" self.deserialized_format = "json" self.auth_token = "AUTH_TOKEN" self.admin_extensions = "OS-KSADM" self.extensions_api_client = ExtensionsAPI_Client( url=self.url, auth_token=self.auth_token, serialized_format=self.serialized_format, deserialized_format=self.deserialized_format) self.role_id = "1" HTTPretty.enable()
def setUpClass(cls): super(BaseIdentityAdminTest, cls).setUpClass() cls.token_config = IdentityTokenConfig() cls.user_config = UserConfig() cls.endpoint_url = cls.token_config.authentication_endpoint cls.serialize_format = cls.token_config.serialize_format cls.deserialize_format = cls.token_config.deserialize_format cls.auth_token = {'headers': {'X-Auth-Token': None}} cls.token_client = TokenAPI_Client( url=cls.endpoint_url, deserialize_format=cls.deserialize_format, serialize_format=cls.serialize_format) cls.admin_auth_response = cls.token_client.authenticate( username=cls.token_config.username, password=cls.token_config.password, tenant_name=cls.token_config.tenant_name) cls.access_data = cls.admin_auth_response.entity cls.admin_token = cls.access_data.token cls.admin = cls.access_data.user cls.demo_auth_response = cls.token_client.authenticate( username=cls.user_config.username, password=cls.user_config.password, tenant_name=cls.user_config.tenant_name) cls.demo_access_data = cls.demo_auth_response.entity cls.demo_token = cls.demo_access_data.token cls.tenant_client = TenantsAPI_Client( url=cls.endpoint_url, auth_token=cls.admin_token.id_, deserialize_format=cls.deserialize_format, serialize_format=cls.serialize_format) cls.tenant_behavior = TenantsBehaviors(cls.tenant_client) cls.demo_tenant = cls.tenant_behavior.get_tenant_by_name(name="demo") cls.demo_user = cls.tenant_behavior.get_user_by_name(name="demo") cls.admin_role = cls.tenant_behavior.get_role_by_name( name="admin", user_id=cls.admin.id_, tenant_id=cls.admin_token.tenant.id_) cls.demo_tenant_client = TenantsAPI_Client( url=cls.endpoint_url, auth_token=cls.demo_token.id_, deserialize_format=cls.deserialize_format, serialize_format=cls.serialize_format) cls.extension_client = ExtensionsAPI_Client( url=cls.endpoint_url, auth_token=cls.admin_token.id_, serialized_format=cls.deserialize_format, deserialized_format=cls.deserialize_format) cls.demo_extension_client = ExtensionsAPI_Client( url=cls.endpoint_url, auth_token=cls.demo_token.id_, serialized_format=cls.deserialize_format, deserialized_format=cls.deserialize_format)
class ExtensionsClientTest(TestCase): def setUp(self): self.url = IDENTITY_ENDPOINT_URL self.serialized_format = "json" self.deserialized_format = "json" self.auth_token = "AUTH_TOKEN" self.admin_extensions = "OS-KSADM" self.extensions_api_client = ExtensionsAPI_Client( url=self.url, auth_token=self.auth_token, serialized_format=self.serialized_format, deserialized_format=self.deserialized_format) self.role_id = "1" HTTPretty.enable() def test_list_extensions(self): url = "{0}/v2.0/extensions".format(self.url) HTTPretty.register_uri(HTTPretty.GET, url, body=self._build_expected_body_response()) actual_response = self.extensions_api_client.list_extensions() self._build_assertions(actual_response, url) def test_list_roles(self): url = "{0}/v2.0/{1}/roles".format(self.url, self.admin_extensions) HTTPretty.register_uri(HTTPretty.GET, url, body=self._build_create_role_response()) actual_response = self.extensions_api_client.list_roles() self._build_assertions(actual_response, url) def test_create_role(self): url = "{0}/v2.0/{1}/roles".format(self.url, self.admin_extensions) HTTPretty.register_uri( HTTPretty.POST, url, body=self._build_create_role_response()) actual_response = self.extensions_api_client.create_role() self._build_assertions(actual_response, url) def test_delete_role(self): url = "{0}/v2.0/{1}/roles/{2}".format(self.url, self.admin_extensions, self.role_id) HTTPretty.register_uri(HTTPretty.DELETE, url) actual_response = self.extensions_api_client.delete_role( role_id=self.role_id) self._build_assertions(actual_response, url) def _build_assertions(self, actual_response, url): assert HTTPretty.last_request.headers['Content-Type'] == \ 'application/{0}'.format(self.serialized_format) assert HTTPretty.last_request.headers['Accept'] == \ 'application/{0}'.format(self.deserialized_format) assert HTTPretty.last_request.headers[ 'X-Auth-Token'] == self.auth_token assert 200 == actual_response.status_code assert url == actual_response.url def _build_expected_body_response(self): return {"extensions": [{"values": [ {"updated": "2011-08-19T13:25:27-06:00", "name": "Openstack Keystone Admin", "links": {"href": "https://github.com/openstack/identity-api", "type": "text/html", "rel": "describedby"}, "namespace": "http://docs.openstack" ".org/identity/api/ext/OS-KSADM/v1.0", "alias": "OS-KSADM", "description": "Openstack extensions to Keystone " "v2.0 API enabling Admin Operations."}]}]} def _build_create_role_response(self): return {"role": {"id": "25dfade062ca486ebdb4e00246c40441", "name": "response-test-221460"}}