Exemplo n.º 1
0
 def get(self, request):
     endpoint_request_url = urlparse(request.build_absolute_uri())._replace(query=None).geturl()
     enterprise_catalogs = get_enterprise_customer_catalogs(
         request.site,
         endpoint_request_url,
         enterprise_customer_uuid=request.GET.get('enterprise_customer'),
         page=request.GET.get('page', '1'),
     )
     return Response(data=enterprise_catalogs)
Exemplo n.º 2
0
    def test_get_enterprise_customer_catalogs(self):
        """
        Verify that "get_enterprise_customer_catalogs" works as expected with and without caching.
        """
        enterprise_customer_uuid = str(uuid.uuid4())
        base_url = self.LEGACY_ENTERPRISE_CATALOG_URL

        self.mock_access_token_response()
        self.mock_enterprise_catalog_api(enterprise_customer_uuid)

        # verify the caching
        with patch.object(TieredCache, 'set_all_tiers', wraps=TieredCache.set_all_tiers) as mocked_set_all_tiers:
            mocked_set_all_tiers.assert_not_called()

            response = get_enterprise_customer_catalogs(self.site, base_url, enterprise_customer_uuid, 1)
            self.assertEqual(mocked_set_all_tiers.call_count, 2)

            cached_response = get_enterprise_customer_catalogs(self.site, base_url, enterprise_customer_uuid, 1)
            self.assertEqual(response, cached_response)
            self.assertEqual(mocked_set_all_tiers.call_count, 2)
Exemplo n.º 3
0
    def test_get_enterprise_customer_catalogs_with_exception(self):
        """
        Verify that "get_enterprise_customer_catalogs" return default response on exception.
        """
        enterprise_customer_uuid = str(uuid.uuid4())
        base_url = self.LEGACY_ENTERPRISE_CATALOG_URL

        self.mock_access_token_response()
        self.mock_enterprise_catalog_api(enterprise_customer_uuid, raise_exception=True)

        with patch('ecommerce.enterprise.utils.logging.exception') as mock_logger:
            response = get_enterprise_customer_catalogs(self.site, base_url, enterprise_customer_uuid, 1)
            self.assertEqual(response, CUSTOMER_CATALOGS_DEFAULT_RESPONSE)
            self.assertTrue(mock_logger.called)