def test_filter_with_list(self): with database.session() as session: query = utils.model_query(session, models.Permission) filters = { 'name': [ 'list_permissions', 'list_switches' ] } resources = utils.model_filter(query, models.Permission, **filters) ret = [resource.to_dict() for resource in resources.all()] expected = [ { 'description': 'list all permissions', 'alias': 'list permissions', 'id': 1, 'name': 'list_permissions' }, { 'description': 'list all switches', 'alias': 'list switches', 'id': 2, 'name': u'list_switches' } ] for i, v in enumerate(ret): self.assertTrue( all(item in ret[i].items() for item in expected[i].items()) )
def test_filter_with_other_type(self): with database.session() as session: query = utils.model_query(session, models.Permission) filters = {"id": 1} resources = utils.model_filter(query, models.Permission, **filters) ret = [resource.to_dict() for resource in resources.all()] expected = {"id": 1} self.assertTrue(all(item in ret[0].items() for item in expected.items()))
def test_filter_with_other_type(self): with database.session() as session: query = utils.model_query(session, models.Permission) filters = {'id': 1} resources = utils.model_filter(query, models.Permission, **filters) ret = [resource.to_dict() for resource in resources.all()] expected = {'id': 1} self.assertTrue( all(item in ret[0].items() for item in expected.items()))
def _filter_test_dict_util(self, op, exp_name, exp_id, **kwargs): with database.session() as session: query = utils.model_query(session, models.Permission) filters = {} for key, value in kwargs.iteritems(): filters[key] = {op: value} resources = utils.model_filter(query, models.Permission, **filters) ret = [resource.to_dict() for resource in resources.all()] expected = {'name': exp_name, 'id': exp_id} return (expected, ret)
def _filter_test_dict_util(self, op, exp_name, exp_id, **kwargs): with database.session() as session: query = utils.model_query(session, models.Permission) filters = {} for key, value in kwargs.iteritems(): filters[key] = {op: value} resources = utils.model_filter(query, models.Permission, **filters) ret = [resource.to_dict() for resource in resources.all()] expected = {"name": exp_name, "id": exp_id} return (expected, ret)
def test_filter_with_list(self): with database.session() as session: query = utils.model_query(session, models.Permission) filters = {"name": ["list_permissions", "list_switches"]} resources = utils.model_filter(query, models.Permission, **filters) ret = [resource.to_dict() for resource in resources.all()] expected = [ { "description": "list all permissions", "alias": "list permissions", "id": 1, "name": "list_permissions", }, {"description": "list all switches", "alias": "list switches", "id": 2, "name": u"list_switches"}, ] for i, v in enumerate(ret): self.assertTrue(all(item in ret[i].items() for item in expected[i].items()))
def test_filter_with_list(self): with database.session() as session: query = utils.model_query(session, models.Permission) filters = {'name': ['list_permissions', 'list_switches']} resources = utils.model_filter(query, models.Permission, **filters) ret = [resource.to_dict() for resource in resources.all()] expected = [{ 'description': 'list all permissions', 'alias': 'list permissions', 'id': 1, 'name': 'list_permissions' }, { 'description': 'list all switches', 'alias': 'list switches', 'id': 2, 'name': u'list_switches' }] for i, v in enumerate(ret): self.assertTrue( all(item in ret[i].items() for item in expected[i].items()))
def test_model_query(self): with database.session() as session: model = models.Machine res = utils.model_query(session, model) self.assertIsNotNone(res)
def test_model_query(self): with database.session() as session: model = models.Machine res = utils.model_query(session, model) self.assertIsNotNone(res)