Ejemplo n.º 1
0
    def test_connection_failure(self, safe_urlread, safe_urlopen):
        safe_urlopen.side_effect = Exception()

        result = fetch_url('http://example.com')

        safe_urlopen.assert_called_once_with(
            'http://example.com', allow_redirects=True, timeout=5)
        assert not safe_urlread.mock_calls

        assert result == BAD_SOURCE

        # ensure we use the cached domain-wide failure for the second call
        result = fetch_url('http://example.com/foo/bar')

        safe_urlopen.assert_called_once()

        assert result == BAD_SOURCE
Ejemplo n.º 2
0
    def test_read_failure(self, safe_urlread, safe_urlopen):
        safe_urlopen.return_value.headers = (('content-type', 'application/json'),)
        safe_urlread.side_effect = Exception()

        result = fetch_url('http://example.com')

        safe_urlopen.assert_called_once_with(
            'http://example.com', allow_redirects=True, timeout=5)
        safe_urlread.assert_called_once_with(safe_urlopen.return_value)

        assert result == BAD_SOURCE

        # ensure we use the cached failure for the second call
        result = fetch_url('http://example.com')

        safe_urlopen.assert_called_once()

        assert result == BAD_SOURCE
Ejemplo n.º 3
0
    def test_simple(self, safe_urlread, safe_urlopen):
        safe_urlopen.return_value.headers = (('content-type', 'application/json'),)
        safe_urlread.return_value = u'foo bar'

        result = fetch_url('http://example.com')

        safe_urlopen.assert_called_once_with(
            'http://example.com', allow_redirects=True, timeout=5)
        safe_urlread.assert_called_once_with(safe_urlopen.return_value)

        assert result.url == 'http://example.com'
        assert result.body == u'foo bar'
        assert result.headers == {'content-type': 'application/json'}

        # ensure we use the cached result
        result2 = fetch_url('http://example.com')

        safe_urlopen.assert_called_once()

        assert result == result2
Ejemplo n.º 4
0
Archivo: tests.py Proyecto: uber/sentry
    def test_with_token(self, safe_urlread, safe_urlopen):
        self.project.update_option('sentry:token', 'foobar')
        self.project.update_option('sentry:origins', ['*'])

        safe_urlopen.return_value.headers = (('content-type', 'application/json'),)
        safe_urlread.return_value = u'foo bar'

        result = fetch_url('http://example.com', project=self.project)

        safe_urlopen.assert_called_once_with(
            'http://example.com', allow_redirects=True, timeout=5,
            headers=[('X-Sentry-Token', 'foobar')])
        safe_urlread.assert_called_once_with(safe_urlopen.return_value)

        assert result.url == 'http://example.com'
        assert result.body == u'foo bar'
        assert result.headers == {'content-type': 'application/json'}

        # ensure we use the cached result
        result2 = fetch_url('http://example.com')

        safe_urlopen.assert_called_once()

        assert result == result2