def test_browse_assets_with_paging_returns_mocked_assets(self):
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?withContentRef=theContentRef&perPage=2&owner=testmock',
            'valid_metadata_assets_response_page_1')
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?owner=testmock&withContentRef=testmock&page=2&perPage=2',
            'valid_metadata_assets_response_page_2')
        under_test = self.client.metadata.assets

        response_list = [
            response for response in under_test.browse(
                'testmock',
                query_string='withContentRef=theContentRef&perPage=2')
        ]

        assert_that(response_list, has_length(2))
        assert_that(response_list[0].resources, has_length(2))
        assert_that(response_list[1].resources, has_length(2))
        assert_that(response_list[0].resources[0]['name'],
                    is_('016b9e5f-c184-48ea-a5e2-6e6bc2d62791'))
        assert_that(response_list[0].resources[1]['name'],
                    is_('192e78ad-25d1-47f8-b539-19053a2b4a6f'))
        assert_that(response_list[1].resources[0]['name'],
                    is_('3bf33965-41fe-4f94-8aa9-63b6b8a379da'))
        assert_that(response_list[1].resources[1]['name'],
                    is_('44c6170a-2c03-42ce-bfa3-101fec955188'))
    def test_browse_assets_with_query_string_returns_mocked_assets(self):
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?withContentRef=theContentRef&owner=testmock',
            'valid_metadata_assets_response')
        under_test = self.client.metadata.assets

        response = under_test.browse(
            'testmock', query_string='withContentRef=theContentRef')

        assert_that(response.resources, has_length(4))
        assert_that(response.resources[0]['name'],
                    '016b9e5f-c184-48ea-a5e2-6e6bc2d62791')
    def test_browse_linked_resources_without_inclusions_then_returns_mocked_assets(
            self):
        mocking.add_get_mapping_for_url(
            self.mock, 'data/contents\?owner=testmock',
            'content_with_more_than_1page_linked_assets_and_next_without_inclusions'
        )
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?fields=ref%2Cname%2CcontentRef%2Ctype%2CmediaType%2Curl%2CfileFormat%2Ctitle%2CfileSize%2Ctags&count=true&withContentRef=test%3AcontentsToChecktesting1&page=2&perPage=100',
            'linked_assets_second_page')

        under_test = self.client.metadata.contents

        contents_response = under_test.browse('testmock')
    def test_browse_assets_with_fields_returns_mocked_assets(self):
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?fields=name\%2Cref&owner=testmock&withContentRef=theContentRef',
            'valid_metadata_assets_response')
        my_criteria = criteria.Criteria()
        my_criteria.add(criterion=criteria.StringExpressionFactory.field(
            'contentRef').equal_to('theContentRef'))
        under_test = self.client.metadata.assets

        response = under_test.browse('testmock',
                                     my_criteria,
                                     fields=['name', 'ref'])

        assert_that(response.resources, has_length(4))
        assert_that(response.resources[0]['name'],
                    '016b9e5f-c184-48ea-a5e2-6e6bc2d62791')
예제 #5
0
    def test_browse_assets_with_paging_and_inclusions_returns_mocked_assets(
            self):
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?withContentRef=theContentRef&perPage=2&include=content&owner=testmock',
            'valid_metadata_assets_response_with_include_page_1')
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?owner=testmock&withContentRef=testmock&page=2&perPage=2&include=content',
            'valid_metadata_assets_response_with_include_page_2')
        under_test = self.client.metadata.assets

        inclusion_contents = criteria.Criteria().add(
            inclusion=criteria.Inclusion.resource('content'))

        response_list = [
            response for response in under_test.browse(
                'testmock',
                query_string='withContentRef=theContentRef&perPage=2',
                criteria=inclusion_contents)
        ]

        assert_that(response_list, has_length(2))
        assert_that(response_list[0].resources, has_length(2))
        assert_that(response_list[1].resources, has_length(2))
        assert_that(response_list[0].resources[0]['name'],
                    is_('016b9e5f-c184-48ea-a5e2-6e6bc2d62791'))
        assert_that(response_list[0].resources[1]['name'],
                    is_('192e78ad-25d1-47f8-b539-19053a2b4a6f'))
        assert_that(response_list[1].resources[0]['name'],
                    is_('3bf33965-41fe-4f94-8aa9-63b6b8a379da'))
        assert_that(response_list[1].resources[1]['name'],
                    is_('44c6170a-2c03-42ce-bfa3-101fec955188'))

        expected_requests = \
            [{'path': '/services/testmock', 'query': ''},
             {'path': '/oauth/token', 'query': ''},
             {'path': '/data/assets', 'query': 'withcontentref=thecontentref&perpage=2&include=content&owner=testmock'},
             {'path': '/data/assets', 'query': 'owner=testmock&withcontentref=testmock&page=2&perpage=2&include=content'}]

        performed_requests = [{
            'path': r.path,
            'query': r.query
        } for r in self.mock.request_history]
        assert_that(performed_requests, is_(expected_requests))
    def test_browse_assets_with_query_string_and_criteria_returns_mocked_assets(
            self):
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?withContentRef=theContentRef&owner=testmock&withType=type',
            'valid_metadata_assets_response')
        under_test = self.client.metadata.assets
        a_criteria = criteria.Criteria().add(
            criterion=criteria.StringExpressionFactory.field('type').equal_to(
                'type'))

        response = under_test.browse(
            'testmock',
            criteria=a_criteria,
            query_string='withContentRef=theContentRef')

        assert_that(response.resources, has_length(4))
        assert_that(response.resources[0]['name'],
                    '016b9e5f-c184-48ea-a5e2-6e6bc2d62791')
    def test_browse_assets_with_iteration_and_one_page_returns_mocked_assets(
            self):
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?withContentRef=theContentRef&perPage=2&owner=testmock',
            'valid_metadata_assets_response_page_2')
        under_test = self.client.metadata.assets

        response_list = [
            response for response in under_test.browse(
                'testmock',
                query_string='withContentRef=theContentRef&perPage=2')
        ]

        assert_that(response_list, has_length(1))
        assert_that(response_list[0].resources, has_length(2))
        assert_that(response_list[0].resources[0]['name'],
                    is_('3bf33965-41fe-4f94-8aa9-63b6b8a379da'))
        assert_that(response_list[0].resources[1]['name'],
                    is_('44c6170a-2c03-42ce-bfa3-101fec955188'))
    def test_browse_assets_paging_with_continue_returns_mocked_assets(self):
        mocking.add_get_mapping_for_url(
            self.mock, 'data/contents\?continue=true&perPage=2&owner=testmock',
            'pagination_continue_page_1')
        mocking.add_get_mapping_for_url(
            self.mock,
            '/data/contents\?continue=00abcdefghijklmnopqrstuvwxyz11&owner=test&perPage=2',
            'pagination_continue_page_2')
        mocking.add_get_mapping_for_url(
            self.mock,
            '/data/contents\?continue=00abcdefghijklmnopqrstuvwxyz22&owner=test&perPage=2',
            'pagination_continue_page_3')

        under_test = self.client.metadata.contents

        response_list = [
            response for response in under_test.browse(
                'testmock', query_string='continue=true&perPage=2')
        ]
        assert_that(response_list, has_length(3))
        assert_that(response_list[0].resources, has_length(2))
        assert_that(response_list[1].resources, has_length(2))
        assert_that(response_list[2].resources, has_length(1))
        assert_that(response_list[0].resources[0]['name'],
                    is_('001436b2-93b7-43c5-89a3-b95ceb50aa73'))
        assert_that(
            response_list[0].resources[1]['name'],
            is_('001436b2-93b7-43c5-89a3-b95ceb50aa73_aligned_primary'))
        assert_that(response_list[1].resources[0]['name'],
                    is_('001436b2-93b7-43c5-89a3-b95ceb50aa73_primary'))
        assert_that(response_list[1].resources[1]['name'],
                    is_('001436b2-93b7-43c5-89a3-b95ceb50aa73_textless'))
        assert_that(
            response_list[2].resources[0]['name'],
            is_('0065ab4e-caf9-4096-8b3b-df4a8f3f19dd_aligned_primary'))
    def test_browse_assets_with_model_query_string_returns_mocked_assets(self):
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?withContentRef=theContentRef&owner=testmock',
            'valid_metadata_assets_response')
        mocking.add_get_mapping_for_url(self.mock, 'descriptor',
                                        'workflow_descriptor_raw')
        self.client = Client('http://mock-registry/services/testmock',
                             grant_client_id='piksel-workflow',
                             grant_client_secret='blablabla',
                             adapters=[('http://', self.mock)],
                             model_resolution='all')
        under_test = self.client.metadata.assets

        response = under_test.browse(
            'testmock', query_string='withContentRef=theContentRef')

        assert_that(response.resources, has_length(4))
        assert_that(response.resources[0]['name'],
                    '016b9e5f-c184-48ea-a5e2-6e6bc2d62791')
        assert_that(response.model[0]['name'],
                    '016b9e5f-c184-48ea-a5e2-6e6bc2d62791')
예제 #10
0
    def test_cache_modified_while_other_iterator_is_browsing(self):
        mocking.add_get_mapping_for_url(
            self.mock, 'data/contents\?include=assets&owner=testmock',
            'pagination_main_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            'data/contents\?include=assets&owner=testmock&page=2&perPage=100',
            'pagination_main_second_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            'data/contents\?include=assets&owner=testmock&page=3&perPage=100',
            'pagination_main_third_page')

        under_test = self.client.metadata.contents

        contents_response = under_test.browse('testmock',
                                              query_string='include=assets')

        response_count = 0
        for response in contents_response:
            response_count += len(response.resources)
            inner_response_count = 0
            for inner_response in contents_response:
                inner_response_count += len(inner_response.resources)
            assert_that(inner_response_count, is_(228))

        assert_that(response_count, is_(228))

        expected_requests = [{
            'path': '/services/testmock',
            'query': ''
        }, {
            'path': '/oauth/token',
            'query': ''
        }, {
            'path': '/data/contents',
            'query': 'include=assets&owner=testmock'
        }, {
            'path':
            '/data/contents',
            'query':
            'include=assets&owner=testmock&page=2&perpage=100'
        }, {
            'path':
            '/data/contents',
            'query':
            'include=assets&owner=testmock&page=3&perpage=100'
        }]

        performed_requests = [{
            'path': r.path,
            'query': r.query
        } for r in self.mock.request_history]
        assert_that(performed_requests, is_(expected_requests))
    def test_browse_linked_resources_with_returns_mocked_assets(self):
        mocking.add_get_mapping_for_url(
            self.mock, 'data/contents\?include=assets,offers&owner=testmock',
            'content_with_more_than_1page_linked_assets')
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?fields=ref%2Cname%2CcontentRef%2Ctype%2CmediaType%2Curl%2CfileFormat%2Ctitle%2CfileSize%2Ctags&count=true&withContentRef=test%3AcontentsToChecktesting1&page=2&perPage=100',
            'linked_assets_second_page')
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/offers\?fields=ref%2Cname%2Ctitle%2CcontentRefs&count=true&withContentRefs=test%3AcontentsToChecktesting1&page=2&perPage=100',
            'linked_offers_second_page')

        under_test = self.client.metadata.contents

        contents_response = under_test.browse(
            'testmock', query_string='include=assets,offers')

        asset_linked = contents_response.linked('assets')
        offers_linked = contents_response.linked('offers')

        assert_that(contents_response.resources, has_length(1))
        assert_that(contents_response.resources[0]['name'],
                    is_('contentsToChecktesting1'))

        assert_that(len(asset_linked.resources), is_(100))
        assert_that(asset_linked.resources[50]['name'],
                    is_('assetsToTest1testing53'))
        assert_that(len(offers_linked.resources), is_(100))
        assert_that(offers_linked.resources[50]['name'],
                    is_('offersToTest1testing53'))

        asset_linked_pages = [
            page for page in contents_response.linked('assets')
        ]
        assert_that(len(asset_linked_pages[0]), is_(100))
        assert_that(len(asset_linked_pages[1]), is_(1))

        offers_linked_pages = [
            page for page in contents_response.linked('offers')
        ]
        assert_that(len(offers_linked_pages[0]), is_(100))
        assert_that(len(offers_linked_pages[1]), is_(1))
    def test_browse_linked_resources_with_more_than_one_page_goes_throw_several_pages(
            self):
        mocking.add_get_mapping_for_url(
            self.mock, 'data/contents\?include=assets&owner=testmock',
            'pagination_main_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            'data/contents\?include=assets&owner=testmock&page=2&perPage=100',
            'pagination_main_second_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            'data/contents\?include=assets&owner=testmock&page=3&perPage=100',
            'pagination_main_third_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            '/data/assets\?fields=ref%2Cname%2CcontentRef%2Ctype%2Curl%2CfileFormat%2Ctitle%2CfileSize%2Ctags&count=true&withContentRef=testmock%3A0968d155-77ec-450c-ae68-47f8936e2121%7C%7Ctestmock%3A1f62e6bb-b995-4b50-be1e-9825dfecb275%7C%7Ctestmock%3A4569ad10-3912-42a1-b769-83456e69ae50%7C%7Ctestmock%3A5cc87697-bab8-4776-89a4-a788dc7acdda%7C%7Ctestmock%3A73601df6-9b99-4008-b6b1-4ccc80b93cfe%7C%7Ctestmock%3A92e7f35c-5b9b-41e1-ae4f-bbda1d89f0e1%7C%7Ctestmock%3AY3JpZDovL2JiYy5jby51ay8yODk0MDA0MjI%7C%7Ctestmock%3AY3JpZDovL2JiYy5jby51ay8yODk0MDA0MjM%7C%7Ctestmock%3Aba01f7f2-17c8-4775-8934-ceb2f3a0f810%7C%7Ctestmock%3Ad5b61cb8-955a-4f34-ad60-a1b22a240077&page=2&perPage=100',
            'pagination_second_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?count=true&fields=ref%2Cname%2CcontentRef%2Ctype%2Curl%2CfileFormat%2Ctitle%2CfileSize%2Ctags&owner=testmock&page=3&perPage=100&withContentRef=testmock%3A0968d155-77ec-450c-ae68-47f8936e2121%7C%7Ctestmock%3A1f62e6bb-b995-4b50-be1e-9825dfecb275%7C%7Ctestmock%3A4569ad10-3912-42a1-b769-83456e69ae50%7C%7Ctestmock%3A5cc87697-bab8-4776-89a4-a788dc7acdda%7C%7Ctestmock%3A73601df6-9b99-4008-b6b1-4ccc80b93cfe%7C%7Ctestmock%3A92e7f35c-5b9b-41e1-ae4f-bbda1d89f0e1%7C%7Ctestmock%3AY3JpZDovL2JiYy5jby51ay8yODk0MDA0MjI%7C%7Ctestmock%3AY3JpZDovL2JiYy5jby51ay8yODk0MDA0MjM%7C%7Ctestmock%3Aba01f7f2-17c8-4775-8934-ceb2f3a0f810%7C%7Ctestmock%3Ad5b61cb8-955a-4f34-ad60-a1b22a240077',
            'pagination_third_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?fields=ref%2Cname%2CcontentRef%2Ctype%2Curl%2CfileFormat%2Ctitle%2CfileSize%2Ctags&withContentRef=testmock%3A0968d155-77ec-450c-ae68-47f8936e2121%7C%7Ctestmock%3A1f62e6bb-b995-4b50-be1e-9825dfecb275%7C%7Ctestmock%3A4569ad10-3912-42a1-b769-83456e69ae50%7C%7Ctestmock%3A5cc87697-bab8-4776-89a4-a788dc7acdda%7C%7Ctestmock%3A73601df6-9b99-4008-b6b1-4ccc80b93cfe%7C%7Ctestmock%3A92e7f35c-5b9b-41e1-ae4f-bbda1d89f0e1%7C%7Ctestmock%3AY3JpZDovL2JiYy5jby51ay8yODk0MDA0MjI%7C%7Ctestmock%3AY3JpZDovL2JiYy5jby51ay8yODk0MDA0MjM%7C%7Ctestmock%3Aba01f7f2-17c8-4775-8934-ceb2f3a0f810%7C%7Ctestmock%3Ad5b61cb8-955a-4f34-ad60-a1b22a240077&page=3&perPage=100',
            'pagination_third_page')

        under_test = self.client.metadata.contents

        contents_response = under_test.browse('testmock',
                                              query_string='include=assets')

        asset_linked = contents_response.linked('assets')

        assert_that(contents_response.resources, has_length(100))
        assert_that(contents_response.resources[0]['name'],
                    is_('0968d155-77ec-450c-ae68-47f8936e2121'))
        assert_that(len(asset_linked.resources), is_(100))
        assert_that(asset_linked.resources[50]['name'],
                    is_('437366a3-a2c5-4633-803c-72dfcb4366f4'))

        asset_linked_pages = [
            page for page in contents_response.linked('assets')
        ]
        assert_that(len(asset_linked_pages[0]), is_(100))
        assert_that(len(asset_linked_pages[1]), is_(157))
        assert_that(len(asset_linked_pages[2]), is_(46))
예제 #13
0
    def test_browse_linked_resources_with_prefetch_and_more_than_one_page_goes_throw_several_pages(
            self):
        mocking.add_get_mapping_for_url(
            self.mock, 'data/contents\?include=assets&owner=testmock',
            'pagination_main_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            'data/contents\?include=assets&owner=testmock&page=2&perPage=100',
            'pagination_main_second_page')

        mocking.add_get_mapping_for_url(
            self.mock,
            'data/contents\?include=assets&owner=testmock&page=3&perPage=100',
            'pagination_main_third_page')

        under_test = self.client.metadata.contents

        contents_response = under_test.browse('testmock',
                                              query_string='include=assets',
                                              prefetch_pages=3)

        asset_linked = contents_response.linked('assets')

        assert_that(contents_response.resources, has_length(100))
        assert_that(contents_response.resources[0]['name'],
                    is_('0968d155-77ec-450c-ae68-47f8936e2121'))
        assert_that(len(asset_linked.resources), is_(100))
        assert_that(asset_linked.resources[50]['name'],
                    is_('437366a3-a2c5-4633-803c-72dfcb4366f4'))

        asset_linked_pages = [
            page for page in contents_response.linked('assets')
        ]
        assert_that(len(asset_linked_pages[0]), is_(100))
        assert_that(len(asset_linked_pages[1]), is_(157))
        assert_that(len(asset_linked_pages[2]), is_(46))

        expected_requests = [{
            'path': '/services/testmock',
            'query': ''
        }, {
            'path': '/oauth/token',
            'query': ''
        }, {
            'path': '/data/contents',
            'query': 'include=assets&owner=testmock'
        }, {
            'path':
            '/data/contents',
            'query':
            'include=assets&owner=testmock&page=2&perpage=100'
        }, {
            'path':
            '/data/contents',
            'query':
            'include=assets&owner=testmock&page=3&perpage=100'
        }]

        performed_requests = [{
            'path': r.path,
            'query': r.query
        } for r in self.mock.request_history]
        assert_that(performed_requests, is_(expected_requests))
예제 #14
0
    def test_browse_linked_resources_with_returns_mocked_assets(self):
        mocking.add_get_mapping_for_url(
            self.mock, 'data/contents\?include=assets,offers&owner=testmock',
            'content_with_more_than_1page_linked_assets')
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/assets\?fields=ref%2Cname%2CcontentRef%2Ctype%2CmediaType%2Curl%2CfileFormat%2Ctitle%2CfileSize%2Ctags&count=true&withContentRef=test%3AcontentsToChecktesting1&page=2&perPage=100',
            'linked_assets_second_page')
        mocking.add_get_mapping_for_url(
            self.mock,
            'data/offers\?fields=ref%2Cname%2Ctitle%2CcontentRefs&count=true&withContentRefs=test%3AcontentsToChecktesting1&page=2&perPage=100',
            'linked_offers_second_page')

        under_test = self.client.metadata.contents

        contents_response = under_test.browse(
            'testmock', query_string='include=assets,offers')

        asset_linked = contents_response.linked('assets')
        offers_linked = contents_response.linked('offers')

        assert_that(contents_response.resources, has_length(1))
        assert_that(contents_response.resources[0]['name'],
                    is_('contentsToChecktesting1'))

        assert_that(len(asset_linked.resources), is_(100))
        assert_that(asset_linked.resources[50]['name'],
                    is_('assetsToTest1testing53'))
        assert_that(len(offers_linked.resources), is_(100))
        assert_that(offers_linked.resources[50]['name'],
                    is_('offersToTest1testing53'))

        asset_linked_pages = [
            page for page in contents_response.linked('assets')
        ]
        assert_that(len(asset_linked_pages[0]), is_(100))
        assert_that(len(asset_linked_pages[1]), is_(1))

        offers_linked_pages = [
            page for page in contents_response.linked('offers')
        ]
        assert_that(len(offers_linked_pages[0]), is_(100))
        assert_that(len(offers_linked_pages[1]), is_(1))

        expected_requests = [{
            'path': '/services/testmock',
            'query': ''
        }, {
            'path': '/oauth/token',
            'query': ''
        }, {
            'path': '/data/contents',
            'query': 'include=assets,offers&owner=testmock'
        }, {
            'path':
            '/data/assets',
            'query':
            'fields=ref%2cname%2ccontentref%2ctype%2cmediatype%2curl%2cfileformat%2ctitle%2cfilesize%2ctags&count=true&withcontentref=test%3acontentstochecktesting1&page=2&perpage=100&owner=testmock'
        }, {
            'path':
            '/data/offers',
            'query':
            'fields=ref%2cname%2ctitle%2ccontentrefs&count=true&withcontentrefs=test%3acontentstochecktesting1&page=2&perpage=100&owner=testmock'
        }]

        performed_requests = [{
            'path': r.path,
            'query': r.query
        } for r in self.mock.request_history]
        assert_that(performed_requests, is_(expected_requests))