def test_404(self): path404 = self.path + 'foobar' with self.assertRaises(Http404): main(self.factory.get('/%s' % path404), path404) with self.assertRaises(Http404): main(self.factory.get('/%s/' % path404), path404 + '/')
def test_404(self, mock_statsd): # pylint: disable=unused-argument path404 = self.path + 'foobar' with self.assertRaises(Http404): main(self.factory.get('/%s' % path404), path404) with self.assertRaises(Http404): main(self.factory.get('/%s/' % path404), path404 + '/')
def test_redirect(self, mock_statsd): self.assertEqual( main(self.factory.get('/%s' % self.path), self.path).status_code, 302 ) self.assertEqual(self.link.reload().clicks, 1) mock_statsd.increment.assert_called_once()
def call_main(self, query): with patch('django_short_urls.views.statsd') as mock_statsd: response = main(self.factory.get('/' + query), query) self.assertEqual(mock_statsd.increment.call_count, 1) return response
def test_views(self, mock_mongoengine_is_primary, mock_statsd): response = main(self.factory.get('/%s' % self.path), self.path) # Make sure we're still redirecting self.assertEqual(response.status_code, HTTP_REDIRECT_PERMANENTLY) # But not logging clicks self.assertEqual(self.link.clicks, 0)
def test_views(self): response = main(self.factory.get('/%s' % self.path), self.path) # Make sure we're still redirecting self.assertEqual(response.status_code, 302) # But not logging clicks self.assertEqual(self.link.clicks, 0)
def test_redirect_with_utf8_query_param(self): with patch('django_short_urls.views.statsd'): response = main(self.factory.get('/' + self.path + '?bla=éàû'), self.path) self.assertEqual(response.status_code, HTTP_REDIRECT_PERMANENTLY) self.assertEqual( response['location'], 'http://www.work4.com/jobs?bla=%C3%A9%C3%A0%C3%BB&ref=shortener')
def expect_same_with_suffix(suffix): """Check that appending a certain suffix leaves the response unchanged""" path_with_suffix = self.path + suffix response_with_suffix = main(self.factory.get('/%s' % path_with_suffix), path_with_suffix) self.assertEqual(response_with_suffix.status_code, response.status_code) self.assertEqual(response_with_suffix.serialize_headers(), response.serialize_headers())
def test_views(self, mock_mongoengine_is_primary): with patch('django_short_urls.views.statsd'): response = main(self.factory.get('/%s' % self.path), self.path) # Make sure we're still redirecting self.assertEqual(response.status_code, HTTP_REDIRECT_PERMANENTLY) # But not logging clicks self.assertEqual(self.link.clicks, 0) mock_mongoengine_is_primary.assert_called_once_with()
def test_redirect(self, mock_statsd): response = main(self.factory.get('/%s' % self.path), self.path) self.assertEqual(response.status_code, HTTP_REDIRECT_PERMANENTLY) self.assertEqual(self.link.reload().clicks, 1) self.assertEqual(mock_statsd.increment.call_count, 1) def expect_same_with_suffix(suffix): """Check that appending a certain suffix leaves the response unchanged""" path_with_suffix = self.path + suffix response_with_suffix = main(self.factory.get('/%s' % path_with_suffix), path_with_suffix) self.assertEqual(response_with_suffix.status_code, response.status_code) self.assertEqual(response_with_suffix.serialize_headers(), response.serialize_headers()) expect_same_with_suffix('&foobar') expect_same_with_suffix('/%5C') expect_same_with_suffix('%C2%A0%E2%80%A6')
def test_redirect_suffix(self): response = main(self.factory.get('/%s/recruiter' % self.path), self.path + '/recruiter') self.assertEqual(response.status_code, 302)
def test_redirect_suffix(self, mock_statsd): # pylint: disable=unused-argument response = main(self.factory.get('/%s/recruiter' % self.path), self.path + '/recruiter') self.assertEqual(response.status_code, HTTP_REDIRECT_PERMANENTLY)
def test_act_as_proxy(self, mock_statsd, mock_proxy): # pylint: disable=W0613 self.link.act_as_proxy = True self.link.save() main(self.factory.get('/%s' % self.path), self.path) self.assertEqual(mock_proxy.call_count, 1)