def test_wsgi_application_200_migrated(self, LWThemeUpdate_mock, MigratedUpdate_mock): MigratedUpdate_mock.return_value.is_migrated = True MigratedUpdate_mock.return_value.get_json.return_value = ( u'{"foó": "ba"}') # From AMO we consume the ID as the `addon_id`. for path_info, call_args in six.iteritems(self.urls): environ = dict(self.environ, PATH_INFO=path_info) response = theme_update.application(environ, self.start_response) # wsgi expects a bytestring, rather than unicode response. assert response == [b'{"fo\xc3\xb3": "ba"}'] assert not LWThemeUpdate_mock.called MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('200 OK', mock.ANY) # From getpersonas.com we append `?src=gp` so we know to consume # the ID as the `persona_id`. self.environ['QUERY_STRING'] = 'src=gp' for path_info, call_args in six.iteritems(self.urls): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) call_args[2] = 'src=gp' assert not LWThemeUpdate_mock.called MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('200 OK', mock.ANY)
def test_wsgi_application_200_migrated(self, LWThemeUpdate_mock, MigratedUpdate_mock): urls = { '/themes/update-check/5': ['en-US', 5, None], '/en-US/themes/update-check/5': ['en-US', 5, None], '/fr/themes/update-check/5': ['fr', 5, None] } MigratedUpdate_mock.return_value.is_migrated = True # From AMO we consume the ID as the `addon_id`. for path_info, call_args in urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) assert not LWThemeUpdate_mock.called MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('200 OK', mock.ANY) # From getpersonas.com we append `?src=gp` so we know to consume # the ID as the `persona_id`. self.environ['QUERY_STRING'] = 'src=gp' for path_info, call_args in urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) call_args[2] = 'src=gp' assert not LWThemeUpdate_mock.called MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('200 OK', mock.ANY)
def test_404_for_migrated_but_updates_disabled(self, MigratedUpdate_mock): MigratedUpdate_mock.return_value.is_migrated = True for path_info, call_args in self.urls.items(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('404 Not Found', [])
def test_wsgi_application_404(self, ThemeUpdate_mock): urls = ["/xxx", "/themes/update-check/xxx", "/en-US/themes/update-check/xxx", "/fr/themes/update-check/xxx"] for path_info in urls: environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) assert not ThemeUpdate_mock.called self.start_response.assert_called_with("404 Not Found", [])
def test_404_for_migrated_but_updates_disabled( self, LWThemeUpdate_mock, MigratedUpdate_mock): MigratedUpdate_mock.return_value.is_migrated = True for path_info, call_args in six.iteritems(self.urls): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) assert not LWThemeUpdate_mock.called MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('404 Not Found', [])
def test_wsgi_application_404(self, ThemeUpdate_mock): urls = [ '/xxx', '/themes/update-check/xxx', '/en-US/themes/update-check/xxx', '/fr/themes/update-check/xxx' ] for path_info in urls: environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) assert not ThemeUpdate_mock.called self.start_response.assert_called_with('404 Not Found', [])
def test_wsgi_application_404(self, LWThemeUpdate_mock, MigratedUpdate_mock): urls = [ '/xxx', '/themes/update-check/xxx', '/en-US/themes/update-check/xxx', '/fr/themes/update-check/xxx' ] for path_info in urls: environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) assert not LWThemeUpdate_mock.called assert not MigratedUpdate_mock.called self.start_response.assert_called_with('404 Not Found', [])
def test_wsgi_application_200(self, LWThemeUpdate_mock, MigratedUpdate_mock): MigratedUpdate_mock.return_value.is_migrated = False # From AMO we consume the ID as the `addon_id`. for path_info, call_args in self.urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) LWThemeUpdate_mock.assert_called_with(*call_args) MigratedUpdate_mock.assert_called_with(*call_args) # From getpersonas.com we append `?src=gp` so we know to consume # the ID as the `persona_id`. self.environ['QUERY_STRING'] = 'src=gp' for path_info, call_args in self.urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) call_args[2] = 'src=gp' LWThemeUpdate_mock.assert_called_with(*call_args) MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('200 OK', mock.ANY)
def test_wsgi_application_200(self, ThemeUpdate_mock): urls = { '/themes/update-check/5': ['en-US', 5, None], '/en-US/themes/update-check/5': ['en-US', 5, None], '/fr/themes/update-check/5': ['fr', 5, None] } # From AMO we consume the ID as the `addon_id`. for path_info, call_args in urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) ThemeUpdate_mock.assert_called_with(*call_args) # From getpersonas.com we append `?src=gp` so we know to consume # the ID as the `persona_id`. self.environ['QUERY_STRING'] = 'src=gp' for path_info, call_args in urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) call_args[2] = 'src=gp' ThemeUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('200 OK', mock.ANY)
def test_wsgi_application_200(self, ThemeUpdate_mock): urls = { "/themes/update-check/5": ["en-US", 5, None], "/en-US/themes/update-check/5": ["en-US", 5, None], "/fr/themes/update-check/5": ["fr", 5, None], } # From AMO we consume the ID as the `addon_id`. for path_info, call_args in urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) ThemeUpdate_mock.assert_called_with(*call_args) # From getpersonas.com we append `?src=gp` so we know to consume # the ID as the `persona_id`. self.environ["QUERY_STRING"] = "src=gp" for path_info, call_args in urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info) theme_update.application(environ, self.start_response) call_args[2] = "src=gp" ThemeUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with("200 OK", mock.ANY)
def test_404_for_migrated_but_android( self, LWThemeUpdate_mock, MigratedUpdate_mock): urls = { '/themes/update-check/5': ['en-US', 5, None], '/en-US/themes/update-check/5': ['en-US', 5, None], '/fr/themes/update-check/5': ['fr', 5, None] } MigratedUpdate_mock.return_value.is_migrated = True for path_info, call_args in urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info, HTTP_USER_AGENT=ANDROID_UA) theme_update.application(environ, self.start_response) assert not LWThemeUpdate_mock.called MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('404 Not Found', []) # Then double check a desktop UA does still work for path_info, call_args in urls.iteritems(): environ = dict(self.environ, PATH_INFO=path_info, HTTP_USER_AGENT=DESKTOP_UA) theme_update.application(environ, self.start_response) assert not LWThemeUpdate_mock.called MigratedUpdate_mock.assert_called_with(*call_args) self.start_response.assert_called_with('200 OK', mock.ANY)