Beispiel #1
0
class TestGetRegion(TestCase):
    fixtures = fixture('user_2519', 'webapp_337141')

    def setUp(self):
        self.resource = SearchView()
        self.factory = RequestFactory()
        self.profile = UserProfile.objects.get(pk=2519)
        self.user = self.profile

    def region_for(self, region):
        req = self.factory.get('/', ({} if region is None else {
            'region': region
        }))
        req.API = True
        req.LANG = ''
        req.user = self.user
        req.amo_user = self.profile
        RegionMiddleware().process_request(req)
        ACLMiddleware().process_request(req)
        return self.resource.get_region_from_request(req)

    @patch('mkt.regions.middleware.RegionMiddleware.region_from_request')
    def test_get_region_all(self, mock_request_region):
        geoip_fallback = regions.PE  # Different than the default (restofworld).
        mock_request_region.return_value = geoip_fallback

        # Test string values (should return region with that slug).
        eq_(self.region_for('restofworld'), regions.RESTOFWORLD)
        eq_(self.region_for('us'), regions.US)

        # Test fallback to request.REGION (should return GeoIP region if region
        # isn't specified or is specified and empty).
        eq_(self.region_for(None), geoip_fallback)
        eq_(self.region_for(''), geoip_fallback)

        # Test fallback to restofworld (e.g. if GeoIP fails).
        with patch('mkt.regions.middleware.RegionMiddleware.'
                   'process_request') as mock_process_request:
            eq_(self.region_for(None), regions.RESTOFWORLD)
            ok_(mock_process_request.called)

    def test_get_region_none(self):
        eq_(self.region_for('None'), None)

    def test_get_region_worldwide(self):
        eq_(self.region_for('worldwide'), regions.RESTOFWORLD)
Beispiel #2
0
class TestGetRegion(TestCase):
    fixtures = fixture('user_2519', 'webapp_337141')

    def setUp(self):
        self.resource = SearchView()
        self.factory = RequestFactory()
        self.profile = UserProfile.objects.get(pk=2519)
        self.user = self.profile

    def region_for(self, region):
        req = self.factory.get('/', ({} if region is None else
                                     {'region': region}))
        req.API = True
        req.LANG = ''
        req.user = self.user
        req.amo_user = self.profile
        RegionMiddleware().process_request(req)
        ACLMiddleware().process_request(req)
        return self.resource.get_region_from_request(req)

    @patch('mkt.regions.middleware.RegionMiddleware.region_from_request')
    def test_get_region_all(self, mock_request_region):
        geoip_fallback = regions.PE  # Different than the default (restofworld).
        mock_request_region.return_value = geoip_fallback

        # Test string values (should return region with that slug).
        eq_(self.region_for('restofworld'), regions.RESTOFWORLD)
        eq_(self.region_for('us'), regions.US)

        # Test fallback to request.REGION (should return GeoIP region if region
        # isn't specified or is specified and empty).
        eq_(self.region_for(None), geoip_fallback)
        eq_(self.region_for(''), geoip_fallback)

        # Test fallback to restofworld (e.g. if GeoIP fails).
        with patch('mkt.regions.middleware.RegionMiddleware.'
                   'process_request') as mock_process_request:
            eq_(self.region_for(None), regions.RESTOFWORLD)
            ok_(mock_process_request.called)

    def test_get_region_none(self):
        eq_(self.region_for('None'), None)

    def test_get_region_worldwide(self):
        eq_(self.region_for('worldwide'), regions.RESTOFWORLD)
Beispiel #3
0
services.register(r'price-tier', PriceTierViewSet,
              base_name='price-tier')
services.register(r'price-currency', PriceCurrencyViewSet,
              base_name='price-currency')

urlpatterns = patterns('',
    url('', include('mkt.fireplace.urls')),
    url(r'^apps/', include(apps.urls)),
    url(r'^apps/app/', include(subapps.urls)),
    url(r'^apps/search/featured/', FeaturedSearchView.as_view(),
        name='featured-search-api'),
    url(r'^apps/search/suggest/', SuggestionsView.as_view(),
        name='suggestions-search-api'),
    url(r'^apps/search/rocketbar/', RocketbarView.as_view(),
        name='rocketbar-search-api'),
    url(r'^apps/search/', SearchView.as_view(), name='search-api'),
    url(r'^services/', include(services.urls)),
    url(r'^services/config/site/', site_config, name='site-config'),
    url(r'^fireplace/report_error/\d*', error_reporter, name='error-reporter'),
    url(r'^rocketfuel/', include(rocketfuel.urls)),
    url(r'^rocketfuel/collections/', include(subcollections.urls)),
    url(r'^apps/', include('mkt.versions.urls')),
    url(r'^apps/', include('mkt.ratings.urls')),
    url(r'^apps/features/', AppFeaturesList.as_view(),
        name='api-features-feature-list'),
    url('', include(abuse_api_patterns)),
    url('', include(account_api_patterns)),
    url('', include('mkt.installs.urls')),
    url('', include(reviewer_api_patterns)),
    url('', include('mkt.webpay.urls')),
    url('', include(dev_api_patterns)),
Beispiel #4
0
 def setUp(self):
     self.resource = SearchView()
     self.factory = RequestFactory()
     self.profile = UserProfile.objects.get(pk=2519)
     self.user = self.profile
Beispiel #5
0
 def _popular(self):
     return SearchView.as_view()(self.request)
Beispiel #6
0
 def setUp(self):
     self.resource = SearchView()
     self.factory = RequestFactory()
     self.profile = UserProfile.objects.get(pk=2519)
     self.user = self.profile
Beispiel #7
0
 def _popular(self):
     return SearchView.as_view()(self.request)
Beispiel #8
0
class TestGetRegion(TestCase):
    fixtures = fixture('user_2519', 'webapp_337141')

    def setUp(self):
        self.resource = SearchView()
        self.factory = RequestFactory()
        self.profile = UserProfile.objects.get(pk=2519)
        self.user = self.profile
        self.api_version = 1

    def region_for(self, region):
        req = self.factory.get('/', ({} if region is None else
                                     {'region': region}))
        req.API = True
        req.API_VERSION = self.api_version
        req.LANG = ''
        req.user = self.user
        req.user = self.profile
        RegionMiddleware().process_request(req)
        ACLMiddleware().process_request(req)
        return self.resource.get_region_from_request(req)

    @patch('mkt.regions.middleware.RegionMiddleware.region_from_request')
    def test_get_region_all_v1(self, mock_request_region):
        geoip_fallback = regions.PE  # Different than the default: restofworld.
        mock_request_region.return_value = geoip_fallback

        # Test string values (should return region with that slug).
        eq_(self.region_for('restofworld'), regions.RESTOFWORLD)
        ok_(not mock_request_region.called)

        eq_(self.region_for('us'), regions.US)
        ok_(not mock_request_region.called)

        # Test fallback to request.REGION (should return GeoIP region if region
        # isn't specified or is specified and empty).
        eq_(self.region_for(None), geoip_fallback)
        eq_(mock_request_region.call_count, 1)

        eq_(self.region_for(''), geoip_fallback)
        eq_(mock_request_region.call_count, 2)

        # Test fallback to restofworld (e.g. if GeoIP fails).
        with patch('mkt.regions.middleware.RegionMiddleware.'
                   'process_request') as mock_process_request:
            eq_(self.region_for(None), regions.RESTOFWORLD)
            ok_(mock_process_request.called)

    @patch('mkt.regions.middleware.RegionMiddleware.region_from_request')
    def test_get_region_all_v2(self, mock_request_region):
        geoip_fallback = regions.PE  # Different than the default: restofworld.
        mock_request_region.return_value = geoip_fallback

        self.api_version = 2

        # Test string values (should return region with that slug).
        eq_(self.region_for('restofworld'), regions.RESTOFWORLD)
        ok_(not mock_request_region.called)

        eq_(self.region_for('us'), regions.US)
        ok_(not mock_request_region.called)

        # Test fallback to request.REGION. We are using api v2, so we shouldn't
        # fall back on GeoIP and simply use RESTOFWORLD.
        eq_(self.region_for(None), regions.RESTOFWORLD)
        ok_(not mock_request_region.called)

        eq_(self.region_for(''), regions.RESTOFWORLD)
        ok_(not mock_request_region.called)

    def test_get_region_none(self):
        # When the client explicity requested `region=None` in the query string
        # we should not have a region set at all, not even restofworld.
        eq_(self.region_for('None'), None)

    def test_get_region_worldwide(self):
        eq_(self.region_for('worldwide'), regions.RESTOFWORLD)
Beispiel #9
0
class TestGetRegion(TestCase):
    fixtures = fixture('user_2519', 'webapp_337141')

    def setUp(self):
        self.resource = SearchView()
        self.factory = RequestFactory()
        self.profile = UserProfile.objects.get(pk=2519)
        self.user = self.profile
        self.api_version = 1

    def region_for(self, region):
        req = self.factory.get('/', ({} if region is None else {
            'region': region
        }))
        req.API = True
        req.API_VERSION = self.api_version
        req.LANG = ''
        req.user = self.user
        req.user = self.profile
        RegionMiddleware().process_request(req)
        ACLMiddleware().process_request(req)
        return self.resource.get_region_from_request(req)

    @patch('mkt.regions.middleware.RegionMiddleware.region_from_request')
    def test_get_region_all_v1(self, mock_request_region):
        geoip_fallback = regions.PE  # Different than the default: restofworld.
        mock_request_region.return_value = geoip_fallback

        # Test string values (should return region with that slug).
        eq_(self.region_for('restofworld'), regions.RESTOFWORLD)
        ok_(not mock_request_region.called)

        eq_(self.region_for('us'), regions.US)
        ok_(not mock_request_region.called)

        # Test fallback to request.REGION (should return GeoIP region if region
        # isn't specified or is specified and empty).
        eq_(self.region_for(None), geoip_fallback)
        eq_(mock_request_region.call_count, 1)

        eq_(self.region_for(''), geoip_fallback)
        eq_(mock_request_region.call_count, 2)

        # Test fallback to restofworld (e.g. if GeoIP fails).
        with patch('mkt.regions.middleware.RegionMiddleware.'
                   'process_request') as mock_process_request:
            eq_(self.region_for(None), regions.RESTOFWORLD)
            ok_(mock_process_request.called)

    @patch('mkt.regions.middleware.RegionMiddleware.region_from_request')
    def test_get_region_all_v2(self, mock_request_region):
        geoip_fallback = regions.PE  # Different than the default: restofworld.
        mock_request_region.return_value = geoip_fallback

        self.api_version = 2

        # Test string values (should return region with that slug).
        eq_(self.region_for('restofworld'), regions.RESTOFWORLD)
        ok_(not mock_request_region.called)

        eq_(self.region_for('us'), regions.US)
        ok_(not mock_request_region.called)

        # Test fallback to request.REGION. We are using api v2, so we shouldn't
        # fall back on GeoIP and simply use RESTOFWORLD.
        eq_(self.region_for(None), regions.RESTOFWORLD)
        ok_(not mock_request_region.called)

        eq_(self.region_for(''), regions.RESTOFWORLD)
        ok_(not mock_request_region.called)

    def test_get_region_none(self):
        # When the client explicity requested `region=None` in the query string
        # we should not have a region set at all, not even restofworld.
        eq_(self.region_for('None'), None)

    def test_get_region_worldwide(self):
        eq_(self.region_for('worldwide'), regions.RESTOFWORLD)
Beispiel #10
0
    services.register(r"error", ErrorViewSet, base_name="error")

services.register(r"carrier", CarrierViewSet, base_name="carriers")
services.register(r"region", RegionViewSet, base_name="regions")
services.register(r"price-tier", PriceTierViewSet, base_name="price-tier")
services.register(r"price-currency", PriceCurrencyViewSet, base_name="price-currency")

urlpatterns = patterns(
    "",
    url("", include("mkt.fireplace.urls")),
    url(r"^apps/", include(apps.urls)),
    url(r"^apps/app/", include(subapps.urls)),
    url(r"^apps/search/featured/$", FeaturedSearchView.as_view(), name="featured-search-api"),
    url(r"^apps/search/suggest/$", SuggestionsView.as_view(), name="suggestions-search-api"),
    url(r"^apps/search/rocketbar/$", RocketbarView.as_view(), name="rocketbar-search-api"),
    url(r"^apps/search/$", SearchView.as_view(), name="search-api"),
    url(r"^services/", include(services.urls)),
    url(r"^services/config/site/", site_config, name="site-config"),
    url(r"^fireplace/report_error/\d*", error_reporter, name="error-reporter"),
    url(r"^apps/", include("mkt.versions.urls")),
    url(r"^apps/", include("mkt.ratings.urls")),
    url(r"^apps/features/", AppFeaturesList.as_view(), name="api-features-feature-list"),
    url("", include(abuse_api_patterns)),
    url("", include(account_api_patterns)),
    url("", include("mkt.installs.urls")),
    url("", include(reviewer_api_patterns)),
    url("", include("mkt.webpay.urls")),
    url("", include(dev_api_patterns)),
    url("", include(payments_api_patterns)),
    url("", include(receipt_api_patterns)),
    url("", include("mkt.monolith.urls")),