def _test_resource_list_by_route(self, route, func=None): prefix = '{}.{}'.format(self.client.service_type, self.client.service_version) res_class, _ = get_resource_and_manager_class_by_route("{}.{}".format( prefix, str(route).lower())) if res_class.__name__ == Resource.__name__: raise Exception( 'Can not get resource class from route: {}'.format(route)) url = '/{}'.format(route.replace('.', '/')) base_route = route.split('.')[-1] httpretty.register_uri( httpretty.GET, self.domain + self.base_url + url, body=get_response_list_json_by_type(base_route), content_type='application/json', status=200, ) func = func or 'get_{}'.format(route.replace('.', '_')) res = getattr(self.rest_client, func)() self.assertIsInstance(res, list) self.assertIsInstance(res[0], dict) rep = ResponseParser(get_response_list_data_by_type(base_route), base_route).get_representations()[0] self._assert_equal_between_dicts(res[0], rep)
def _get_resource_class_by_name(self, resource_type): prefix = '{}.{}'.format(self.client.service_type, self.client.service_version ) return get_resource_and_manager_class_by_route( "{}.{}".format(prefix, resource_type) )
def _get_class_by_name(self, name): prefix = '{}.{}'.format(self.client.service_type, self.client.service_version) res_class, _ = get_resource_and_manager_class_by_route("{}.{}".format( prefix, str(name).lower())) if res_class.__name__ == Resource.__name__: raise Exception( 'Can not get resource class from route: {}'.format(name)) return res_class
def _set_resource_list(self, route): base_route = route.split('.')[-1] resource_response = get_response_data_by_type(base_route) prefix = '{}.{}'.format(self.client.service_type, self.client.service_version) res_class, _ = get_resource_and_manager_class_by_route("{}.{}".format( prefix, str(route).lower())) if res_class.__name__ == Resource.__name__: raise Exception( 'Can not get resource class from route: {}'.format(route)) id_field = res_class.id_field route_id = self._get_resource_id_from_resopnse(base_route, resource_response, id_field) url = '/{}/{}'.format(route.replace('.', '/'), route_id) httpretty.register_uri( httpretty.GET, self.domain + self.base_url + url, body=get_response_json_by_type(base_route), content_type='application/json', status=200, ) return route_id