示例#1
0
 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())
             )
示例#2
0
 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()))
示例#3
0
 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()))
示例#4
0
 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)
示例#5
0
 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)
示例#6
0
 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()))
示例#7
0
 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()))
示例#8
0
 def test_model_query(self):
     with database.session() as session:
         model = models.Machine
         res = utils.model_query(session, model)
         self.assertIsNotNone(res)
示例#9
0
 def test_model_query(self):
     with database.session() as session:
         model = models.Machine
         res = utils.model_query(session, model)
         self.assertIsNotNone(res)