Exemplo n.º 1
0
    def test_bad_requests(self):
        # Test missing long_url
        self.assertEqual(new(self._post('/new')).status_code, HTTP_BAD_REQUEST)

        # Test for slashes in the short_path
        data = {
            'long_url': self.long_url,
            'short_path': 'inva/lid'
        }
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_BAD_REQUEST)

        data['allow_slashes_in_prefix'] = True
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_BAD_REQUEST)

        # Test for slashes in the prefix
        data = {
            'long_url': self.long_url,
            'short_path': 'valid',
            'prefix': 'inva/lid'
        }
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_BAD_REQUEST)

        # Test for other invalid chars in the url ('%', '?', etc.)
        data = {
            'long_url': self.long_url,
            'short_path': 'inva&lid',
        }
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_BAD_REQUEST)
Exemplo n.º 2
0
    def test_new(self):
        self.data['long_url'] = 'http://www.work4labs.com/'

        self.assertEqual(
            new(self.factory.post('/new', self.data)).status_code, HTTP_OK)

        self.data['short_path'] = 'bar'
        self.data['prefix'] = 'foo'

        self.assertEqual(
            new(self.factory.post('/new', self.data)).status_code, HTTP_OK)
Exemplo n.º 3
0
    def test_bad_requests(self):
        # Test missing long_url
        self.assertEqual(
            new(self.factory.post('/new', self.data)).status_code,
            HTTP_BAD_REQUEST)

        self.data['long_url'] = 'http://work4.com'
        self.data['short_path'] = 'inva/lid'

        self.assertEqual(
            new(self.factory.post('/new', self.data)).status_code,
            HTTP_BAD_REQUEST)
Exemplo n.º 4
0
    def test_unauthorized(self, mock_statsd):
        # No auth sent
        response = new(self._post('/new', with_auth=False))
        self.assertEqual(response.status_code, HTTP_UNAUTHORIZED)
        self.assertTrue(response.has_header('WWW-Authenticate'))

        # Digest auth
        request = self._post(
            '/new', with_auth=False,
            HTTP_AUTHORIZATION='Digest username="******", ...invalid'
        )
        self.assertEqual(new(request).status_code, HTTP_UNAUTHORIZED)
        self.assertEqual(mock_statsd.increment.call_count, 0)
Exemplo n.º 5
0
    def test_new(self):
        self.data['long_url'] = 'http://www.work4labs.com/'

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_OK)

        self.data['short_path'] = 'bar'
        self.data['prefix'] = 'foo'

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_OK)

        self.data['prefix'] = 'inva/lid'
        self.data['allow_slashes_in_prefix'] = True

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_OK)
Exemplo n.º 6
0
 def test_forbidden_keyword(self, mock_statsd):
     data = {
         'long_url': self.long_url,
         'short_path': 'jobs'
     }
     self.assertEqual(new(self._post('/new', data)).status_code, HTTP_FORBIDDEN)
     self.assertEqual(mock_statsd.increment.call_count, 1)
Exemplo n.º 7
0
    def test_forbidden_keyword(self):
        self.data['long_url'] = 'http://work4.com'
        self.data['short_path'] = 'jobs'

        self.assertEqual(
            new(self.factory.post('/new', self.data)).status_code,
            HTTP_FORBIDDEN)
Exemplo n.º 8
0
    def test_bad_requests(self):
        # Test missing long_url
        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_BAD_REQUEST)

        self.data['long_url'] = 'http://work4.com'
        self.data['short_path'] = 'inva/lid'

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_BAD_REQUEST)

        self.data['allow_slashes_in_prefix'] = True

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_BAD_REQUEST)

        self.data['short_path'] = 'valid'
        self.data['prefix'] = 'inva/lid'
        del self.data['allow_slashes_in_prefix']

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_BAD_REQUEST)
Exemplo n.º 9
0
    def test_short_path_conflict(self, mock_statsd):
        # Create the base conflicting link
        data = {
            'long_url': self.long_url,
            'short_path': 'conflict'
        }
        new(self._post('/new', data))

        # Conflict when trying to replace an existing short_path with a different long_url target
        data['long_url'] = 'http://some.thi.ng/different'
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_CONFLICT)

        # Now check the same thing with urls that include a prefix - first create
        data['prefix'] = 'foobar'
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_OK)

        # Now trigger the conflict
        data['long_url'] = 'http://yet.aga.in/something/else'
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_CONFLICT)

        self.assertEqual(mock_statsd.increment.call_count, 4)
Exemplo n.º 10
0
    def test_new(self, mock_views_statsd, mock_models_statsd):  # pylint: disable=unused-argument
        data = {
            'long_url': self.long_url
        }
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_OK)

        data['short_path'] = 'bar'
        response = new(self._post('/new', data, secure=True))
        self.assertEqual(response.status_code, HTTP_OK)
        self.assertEqual(json.loads(response.content)['short_url'], "https://testserver/bar")

        data['short_path'] = 'bar'
        data['prefix'] = 'foo'
        response = new(self._post('/new', data))
        self.assertEqual(response.status_code, HTTP_OK)
        self.assertEqual(json.loads(response.content)['short_url'], "https://testserver/foo/bar")

        data['prefix'] = 'inva/lid'
        data['allow_slashes_in_prefix'] = True
        self.assertEqual(new(self._post('/new', data)).status_code, HTTP_OK)

        self.assertEqual(mock_views_statsd.increment.call_count, 4)
Exemplo n.º 11
0
    def test_short_path_conflict(self):
        self.data['long_url'] = 'http://work4.com'
        self.data['short_path'] = 'conflict'

        new(self.factory.post('/new', self.data))

        self.data['long_url'] = 'http://some.thi.ng/different'

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_CONFLICT)

        self.data['prefix'] = 'foobar'

        new(self.factory.post('/new', self.data))

        self.data['long_url'] = 'http://yet.aga.in/something/else'

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_CONFLICT)
Exemplo n.º 12
0
    def test_short_path_conflict(self):
        self.data['long_url'] = 'http://work4.com'
        self.data['short_path'] = 'conflict'

        new(self.factory.post('/new', self.data))

        self.data['long_url'] = 'http://some.thi.ng/different'

        self.assertEqual(
            new(self.factory.post('/new', self.data)).status_code,
            HTTP_CONFLICT)

        self.data['prefix'] = 'foobar'

        new(self.factory.post('/new', self.data))

        self.data['long_url'] = 'http://yet.aga.in/something/else'

        self.assertEqual(
            new(self.factory.post('/new', self.data)).status_code,
            HTTP_CONFLICT)
Exemplo n.º 13
0
    def test_forbidden_keyword(self):
        self.data['long_url'] = 'http://work4.com'
        self.data['short_path'] = 'jobs'

        self.assertEqual(new(self.factory.post('/new', self.data)).status_code, HTTP_FORBIDDEN)
Exemplo n.º 14
0
 def test_unauthorized(self):
     self.assertEqual(new(self.factory.post('/new')).status_code, HTTP_UNAUTHORIZED)
Exemplo n.º 15
0
 def test_unauthorized(self):
     self.assertEqual(
         new(self.factory.post('/new')).status_code, HTTP_UNAUTHORIZED)