def setup_class(cls): cls.access_json_dict = (open(os.path.join( os.path.dirname(__file__), "../../data/access.json")).read()) cls.access_dict = json.loads(cls.access_json_dict).get('access') cls.token_dict = cls.access_dict.get('token') cls.tenant_dict = cls.token_dict.get('tenant') cls.tenant = Tenant(id_=cls.tenant_dict.get('id'), name=cls.tenant_dict.get('name'), enabled=cls.tenant_dict.get('enabled'), description=cls.tenant_dict.get('description')) cls.token = Token(id_=cls.token_dict.get('id'), issued_at=cls.token_dict.get('issued_at'), expires=cls.token_dict.get('expires'), tenant=cls.tenant) cls.service_catalog_dict = cls.access_dict.get('serviceCatalog') cls.user_dict = cls.access_dict.get('user') cls.roles_dict = cls.user_dict.get('roles') cls.role_dict = cls.roles_dict[0] cls.service_dict = cls.service_catalog_dict[0] cls.another_service_dict = cls.service_catalog_dict[1] cls.endpoint_dict = cls.service_dict.get('endpoints')[0] cls.endpoint = Endpoint(id_=cls.endpoint_dict.get('id'), admin_url=cls.endpoint_dict.get('adminURL'), internal_url=cls.endpoint_dict.get( 'internalURL'), public_url=cls.endpoint_dict.get( 'publicURL'), region=cls.endpoint_dict.get('region')) cls.region = cls.endpoint_dict.get('region') cls.endpoints = EndpointList(endpoints=[cls.endpoint]) cls.endpoints_links = cls.service_dict.get('endpoints_links') cls.role = Role(id_=cls.role_dict.get('id'), name=cls.role_dict.get('name')) cls.roles = RoleList(roles=[cls.role]) cls.roles_links = cls.user_dict.get('roles_links') cls.user = User(id_=cls.user_dict.get('id'), name=cls.user_dict.get('name'), username=cls.user_dict.get('username'), roles=cls.roles, roles_links=cls.roles_links) cls.metadata_dict = cls.access_dict.get('metadata') cls.service_name = cls.service_dict.get('name') cls.service = Service(name=cls.service_name, type_=cls.service_dict.get('type'), endpoints=cls.endpoints, endpoint_links=cls.endpoints_links) cls.another_service = Service(name=cls.service_name, type_=cls.another_service_dict.get( 'type'), endpoints=cls.endpoints, endpoint_links=cls.endpoints_links) cls.services = [Service(name=service_dict.get('name'), type_=service_dict.get('type'), endpoints=EndpointList._list_to_obj( [service_dict.get('endpoints')[0]]), endpoint_links=service_dict.get( 'endpoints_links')) for service_dict in cls.service_catalog_dict] cls.service_catalog = ServiceCatalog(services=[cls.service]) cls.another_service_catalog = ServiceCatalog(services=cls.services) cls.access = Access(metadata=cls.metadata_dict, service_catalog=cls.another_service_catalog, user=cls.user, token=cls.token) cls.glance_service = Service(name="Glance")
def test_list_to_obj(self): assert self.endpoints == EndpointList._list_to_obj( [self.endpoint_dict]) assert self.service_catalog == ServiceCatalog._list_to_obj( [self.service_dict]) assert self.roles == RoleList._list_to_obj([self.role_dict])