Beispiel #1
0
    def test_profile_get_all_sorting(self):
        values = [{'id': '001', 'name': 'profile1', 'type': 'C'},
                  {'id': '002', 'name': 'profile3', 'type': 'B'},
                  {'id': '003', 'name': 'profile2', 'type': 'A'}]

        for v in values:
            shared.create_profile(self.ctx, **v)

        # Sorted by name,type
        profiles = db_api.profile_get_all(self.ctx, sort='name,type')
        self.assertEqual(3, len(profiles))
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('003', profiles[1].id)
        self.assertEqual('002', profiles[2].id)

        # Sorted by type,name (ascending)
        profiles = db_api.profile_get_all(self.ctx, sort='type,name')
        self.assertEqual(3, len(profiles))
        self.assertEqual('003', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('001', profiles[2].id)

        # Sorted by type,name (descending)
        profiles = db_api.profile_get_all(self.ctx, sort='type:desc,name:desc')
        self.assertEqual(3, len(profiles))
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('003', profiles[2].id)
Beispiel #2
0
    def test_profile_get_all_sort_keys_and_dir(self):
        values = [
            {"id": "001", "name": "profile1", "type": "C"},
            {"id": "002", "name": "profile3", "type": "B"},
            {"id": "003", "name": "profile2", "type": "A"},
        ]

        for v in values:
            shared.create_profile(self.ctx, **v)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=["name", "type"], sort_dir="asc")
        self.assertEqual(3, len(profiles))
        # Sorted by name
        self.assertEqual("001", profiles[0].id)
        self.assertEqual("003", profiles[1].id)
        self.assertEqual("002", profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=["type", "name"], sort_dir="asc")
        self.assertEqual(3, len(profiles))
        # Sorted by levels (ascending)
        self.assertEqual("003", profiles[0].id)
        self.assertEqual("002", profiles[1].id)
        self.assertEqual("001", profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=["type", "name"], sort_dir="desc")
        self.assertEqual(3, len(profiles))
        # Sorted by statuses (descending)
        self.assertEqual("001", profiles[0].id)
        self.assertEqual("002", profiles[1].id)
        self.assertEqual("003", profiles[2].id)
Beispiel #3
0
    def test_profile_get_all_sort_keys_and_dir(self):
        values = [{'id': '001', 'name': 'profile1', 'type': 'C'},
                  {'id': '002', 'name': 'profile3', 'type': 'B'},
                  {'id': '003', 'name': 'profile2', 'type': 'A'}]

        for v in values:
            shared.create_profile(self.ctx, **v)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=['name', 'type'],
                                          sort_dir='asc')
        self.assertEqual(3, len(profiles))
        # Sorted by name
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('003', profiles[1].id)
        self.assertEqual('002', profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=['type', 'name'],
                                          sort_dir='asc')
        self.assertEqual(3, len(profiles))
        # Sorted by levels (ascending)
        self.assertEqual('003', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('001', profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx, sort_keys=['type', 'name'],
                                          sort_dir='desc')
        self.assertEqual(3, len(profiles))
        # Sorted by statuses (descending)
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('003', profiles[2].id)
Beispiel #4
0
    def test_profile_get_all_diff_project(self):
        ids = ['profile1', 'profile2']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        new_ctx = utils.dummy_context(project='a-different-project')
        profiles = db_api.profile_get_all(new_ctx)
        self.assertEqual(0, len(profiles))
        profiles = db_api.profile_get_all(new_ctx, project_safe=False)
        self.assertEqual(2, len(profiles))
Beispiel #5
0
    def test_profile_get_all_diff_project(self):
        ids = ['profile1', 'profile2']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        new_ctx = utils.dummy_context(project='a-different-project')
        profiles = db_api.profile_get_all(new_ctx)
        self.assertEqual(0, len(profiles))
        profiles = db_api.profile_get_all(new_ctx, project_safe=False)
        self.assertEqual(2, len(profiles))
Beispiel #6
0
    def test_profile_get_all_used_sort_keys(self, mock_paginate):
        ids = ['profile1', 'profile2', 'profile3']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        sort_keys = consts.PROFILE_SORT_KEYS
        db_api.profile_get_all(self.ctx, sort=','.join(sort_keys))

        args = mock_paginate.call_args[0]
        sort_keys.append('id')
        self.assertEqual(set(sort_keys), set(args[3]))
Beispiel #7
0
    def test_profile_get_all_used_sort_keys(self, mock_paginate):
        ids = ['profile1', 'profile2', 'profile3']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        sort_keys = consts.PROFILE_SORT_KEYS
        db_api.profile_get_all(self.ctx, sort=','.join(sort_keys))

        args = mock_paginate.call_args[0]
        sort_keys.append('id')
        self.assertEqual(set(sort_keys), set(args[3]))
Beispiel #8
0
    def test_profile_get_all_with_filters(self):
        for name in ['profile1', 'profile2']:
            shared.create_profile(self.ctx, name=name)

        filters = {'name': ['profile1', 'profilex']}
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('profile1', results[0]['name'])

        filters = {'name': 'profile1'}
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('profile1', results[0]['name'])
Beispiel #9
0
    def test_profile_get_all_with_filters(self):
        for name in ["profile1", "profile2"]:
            shared.create_profile(self.ctx, name=name)

        filters = {"name": ["profile1", "profilex"]}
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual("profile1", results[0]["name"])

        filters = {"name": "profile1"}
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual("profile1", results[0]["name"])
Beispiel #10
0
    def test_profile_get_all_with_filters(self):
        for name in ['profile1', 'profile2']:
            shared.create_profile(self.ctx, name=name)

        filters = {'name': ['profile1', 'profilex']}
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('profile1', results[0]['name'])

        filters = {'name': 'profile1'}
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(1, len(results))
        self.assertEqual('profile1', results[0]['name'])
Beispiel #11
0
    def test_profile_get_all_used_sort_keys(self):
        ids = ["profile1", "profile2", "profile3"]
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        mock_paginate = self.patchobject(db_api.utils, "paginate_query")
        sort_keys = ["type", "name", "permission", "metadata", "created_time", "updated_time", "deleted_time"]

        db_api.profile_get_all(self.ctx, sort_keys=sort_keys)

        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        expected_keys = set(["id", "type", "name", "permission", "created_time", "updated_time", "deleted_time"])
        self.assertEqual(expected_keys, used_sort_keys)
Beispiel #12
0
    def test_profile_get_all_with_empty_filters(self):
        for name in ['profile1', 'profile2']:
            shared.create_profile(self.ctx, name=name)

        filters = None
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(2, len(results))
Beispiel #13
0
    def test_profile_get_all_used_sort_keys(self):
        ids = ['profile1', 'profile2', 'profile3']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        mock_paginate = self.patchobject(db_api.utils, 'paginate_query')
        sort_keys = ['type', 'name', 'permission', 'tags',
                     'created_time', 'updated_time', 'deleted_time']

        db_api.profile_get_all(self.ctx, sort_keys=sort_keys)

        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        expected_keys = set(['id', 'type', 'name', 'permission', 'tags',
                             'created_time', 'updated_time', 'deleted_time'])
        self.assertEqual(expected_keys, used_sort_keys)
Beispiel #14
0
    def test_profile_get_all_with_empty_filters(self):
        for name in ['profile1', 'profile2']:
            shared.create_profile(self.ctx, name=name)

        filters = None
        results = db_api.profile_get_all(self.ctx, filters=filters)
        self.assertEqual(2, len(results))
Beispiel #15
0
    def test_profile_get_all_with_limit_marker(self):
        ids = ['profile1', 'profile2', 'profile3']
        for pid in ids:
            timestamp = tu.utcnow(True)
            shared.create_profile(self.ctx, id=pid, created_at=timestamp)

        # different limit settings
        profiles = db_api.profile_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(profiles))

        # a large limit
        profiles = db_api.profile_get_all(self.ctx, limit=5)
        self.assertEqual(3, len(profiles))

        # use marker here
        profiles = db_api.profile_get_all(self.ctx, marker='profile1')
        self.assertEqual(2, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, marker='profile2')
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, marker='profile3')
        self.assertEqual(0, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, limit=1, marker='profile1')
        self.assertEqual(1, len(profiles))
Beispiel #16
0
    def test_profile_get_all_with_limit_marker(self):
        ids = ['profile1', 'profile2', 'profile3']
        for pid in ids:
            timestamp = tu.utcnow(True)
            shared.create_profile(self.ctx, id=pid, created_at=timestamp)

        # different limit settings
        profiles = db_api.profile_get_all(self.ctx, limit=1)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, limit=2)
        self.assertEqual(2, len(profiles))

        # a large limit
        profiles = db_api.profile_get_all(self.ctx, limit=5)
        self.assertEqual(3, len(profiles))

        # use marker here
        profiles = db_api.profile_get_all(self.ctx, marker='profile1')
        self.assertEqual(2, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, marker='profile2')
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, marker='profile3')
        self.assertEqual(0, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, limit=1, marker='profile1')
        self.assertEqual(1, len(profiles))
Beispiel #17
0
    def test_profile_get_all_admin_context(self):
        ids = ['profile1', 'profile2']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        admin_ctx = utils.dummy_context(project='a-different-project',
                                        is_admin=True)
        profiles = db_api.profile_get_all(admin_ctx, project_safe=True)
        self.assertEqual(2, len(profiles))
Beispiel #18
0
    def test_profile_get_all_admin_context(self):
        ids = ['profile1', 'profile2']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        admin_ctx = utils.dummy_context(project='a-different-project',
                                        is_admin=True)
        profiles = db_api.profile_get_all(admin_ctx, project_safe=True)
        self.assertEqual(2, len(profiles))
Beispiel #19
0
    def test_profile_get_all_sort_keys_and_dir(self):
        values = [{
            'id': '001',
            'name': 'profile1',
            'type': 'C'
        }, {
            'id': '002',
            'name': 'profile3',
            'type': 'B'
        }, {
            'id': '003',
            'name': 'profile2',
            'type': 'A'
        }]

        for v in values:
            shared.create_profile(self.ctx, **v)

        profiles = db_api.profile_get_all(self.ctx,
                                          sort_keys=['name', 'type'],
                                          sort_dir='asc')
        self.assertEqual(3, len(profiles))
        # Sorted by name
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('003', profiles[1].id)
        self.assertEqual('002', profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx,
                                          sort_keys=['type', 'name'],
                                          sort_dir='asc')
        self.assertEqual(3, len(profiles))
        # Sorted by levels (ascending)
        self.assertEqual('003', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('001', profiles[2].id)

        profiles = db_api.profile_get_all(self.ctx,
                                          sort_keys=['type', 'name'],
                                          sort_dir='desc')
        self.assertEqual(3, len(profiles))
        # Sorted by statuses (descending)
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('003', profiles[2].id)
Beispiel #20
0
    def test_profile_get_all_default_sort_dir(self):
        profiles = []
        for x in range(3):
            profile = shared.create_profile(self.ctx, created_time=tu.utcnow())
            profiles.append(profile)

        results = db_api.profile_get_all(self.ctx, sort_dir="asc")
        self.assertEqual(3, len(results))
        self.assertEqual(profiles[0].id, results[0].id)
        self.assertEqual(profiles[1].id, results[1].id)
        self.assertEqual(profiles[2].id, results[2].id)
Beispiel #21
0
    def test_profile_get_all_used_sort_keys(self):
        ids = ['profile1', 'profile2', 'profile3']
        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        mock_paginate = self.patchobject(db_api.utils, 'paginate_query')
        sort_keys = [
            'type', 'name', 'permission', 'metadata', 'created_time',
            'updated_time', 'deleted_time'
        ]

        db_api.profile_get_all(self.ctx, sort_keys=sort_keys)

        args = mock_paginate.call_args[0]
        used_sort_keys = set(args[3])
        expected_keys = set([
            'id', 'type', 'name', 'permission', 'created_time', 'updated_time',
            'deleted_time'
        ])
        self.assertEqual(expected_keys, used_sort_keys)
Beispiel #22
0
    def test_profile_get_all_default_sort_dir(self):
        profiles = []
        for x in range(3):
            profile = shared.create_profile(self.ctx, created_time=tu.utcnow())
            profiles.append(profile)

        results = db_api.profile_get_all(self.ctx, sort_dir='asc')
        self.assertEqual(3, len(results))
        self.assertEqual(profiles[0].id, results[0].id)
        self.assertEqual(profiles[1].id, results[1].id)
        self.assertEqual(profiles[2].id, results[2].id)
Beispiel #23
0
    def test_profile_get_all(self):
        ids = ["profile1", "profile2"]

        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(2, len(profiles))
        profile_ids = [p.id for p in profiles]
        for pid in ids:
            self.assertIn(pid, profile_ids)

        # test show_deleted here
        db_api.profile_delete(self.ctx, profiles[1].id)

        # after delete one of them
        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, show_deleted=False)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, show_deleted=True)
        self.assertEqual(2, len(profiles))

        # after delete both profiles
        db_api.profile_delete(self.ctx, profiles[0].id)

        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(0, len(profiles))
        profiles = db_api.profile_get_all(self.ctx, show_deleted=True)
        self.assertEqual(2, len(profiles))
Beispiel #24
0
    def test_profile_get_all(self):
        ids = ['profile1', 'profile2']

        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(2, len(profiles))
        profile_ids = [p.id for p in profiles]
        for pid in ids:
            self.assertIn(pid, profile_ids)

        # test show_deleted here
        db_api.profile_delete(self.ctx, profiles[1].id)

        # after delete one of them
        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, show_deleted=False)
        self.assertEqual(1, len(profiles))

        profiles = db_api.profile_get_all(self.ctx, show_deleted=True)
        self.assertEqual(2, len(profiles))

        # after delete both profiles
        db_api.profile_delete(self.ctx, profiles[0].id)

        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(0, len(profiles))
        profiles = db_api.profile_get_all(self.ctx, show_deleted=True)
        self.assertEqual(2, len(profiles))
Beispiel #25
0
    def test_profile_get_all_sorting(self):
        values = [{
            'id': '001',
            'name': 'profile1',
            'type': 'C'
        }, {
            'id': '002',
            'name': 'profile3',
            'type': 'B'
        }, {
            'id': '003',
            'name': 'profile2',
            'type': 'A'
        }]

        for v in values:
            shared.create_profile(self.ctx, **v)

        # Sorted by name,type
        profiles = db_api.profile_get_all(self.ctx, sort='name,type')
        self.assertEqual(3, len(profiles))
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('003', profiles[1].id)
        self.assertEqual('002', profiles[2].id)

        # Sorted by type,name (ascending)
        profiles = db_api.profile_get_all(self.ctx, sort='type,name')
        self.assertEqual(3, len(profiles))
        self.assertEqual('003', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('001', profiles[2].id)

        # Sorted by type,name (descending)
        profiles = db_api.profile_get_all(self.ctx, sort='type:desc,name:desc')
        self.assertEqual(3, len(profiles))
        self.assertEqual('001', profiles[0].id)
        self.assertEqual('002', profiles[1].id)
        self.assertEqual('003', profiles[2].id)
Beispiel #26
0
    def test_profile_get_all(self):
        ids = ['profile1', 'profile2']

        for pid in ids:
            shared.create_profile(self.ctx, id=pid)

        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(2, len(profiles))
        profile_ids = [p.id for p in profiles]
        for pid in ids:
            self.assertIn(pid, profile_ids)

        db_api.profile_delete(self.ctx, profiles[1].id)

        # after delete one of them
        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(1, len(profiles))

        # after delete both profiles
        db_api.profile_delete(self.ctx, profiles[0].id)

        profiles = db_api.profile_get_all(self.ctx)
        self.assertEqual(0, len(profiles))
Beispiel #27
0
 def test_profile_get_all_sort_keys_wont_change(self):
     sort_keys = ["id"]
     db_api.profile_get_all(self.ctx, sort_keys=sort_keys)
     self.assertEqual(["id"], sort_keys)
Beispiel #28
0
 def test_profile_get_all_sort_keys_wont_change(self):
     sort_keys = ['id']
     db_api.profile_get_all(self.ctx, sort_keys=sort_keys)
     self.assertEqual(['id'], sort_keys)