This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.py
More file actions
58 lines (46 loc) · 1.8 KB
/
tests.py
File metadata and controls
58 lines (46 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from urllib3_mock import Responses
from urllib3.exceptions import TimeoutError, MaxRetryError
import pytest
from opbeat.transport.base import TransportException
try:
import urlparse
except ImportError:
from urllib import parse as urlparse
from opbeat_python_urllib3 import Urllib3Transport, AsyncUrllib3Transport
responses = Responses('urllib3')
@responses.activate
def test_send():
transport = Urllib3Transport(urlparse.urlparse('http://localhost'))
responses.add('POST', '/', status=202,
adding_headers={'Location': 'http://example.com/foo'})
url = transport.send('x', {})
assert url == 'http://example.com/foo'
@responses.activate
def test_timeout():
transport = Urllib3Transport(urlparse.urlparse('http://localhost'))
responses.add('POST', '/', status=202,
body=MaxRetryError(None, None, reason=TimeoutError()))
with pytest.raises(TransportException) as exc_info:
transport.send('x', {})
assert 'timeout' in str(exc_info.value)
@responses.activate
def test_http_error():
url, status, body = (
'http://localhost:9999', 418, 'Nothing'
)
transport = Urllib3Transport(urlparse.urlparse(url))
responses.add('POST', '/', status=status, body=body)
with pytest.raises(TransportException) as exc_info:
transport.send('x', {})
for val in (status, body):
assert str(val) in str(exc_info.value)
@responses.activate
def test_generic_error():
url, status, message, body = (
'http://localhost:9999', 418, "I'm a teapot", 'Nothing'
)
transport = Urllib3Transport(urlparse.urlparse(url))
responses.add('POST', '/', status=status, body=Exception('Oopsie'))
with pytest.raises(TransportException) as exc_info:
transport.send('x', {})
assert 'Oopsie' in str(exc_info.value)