This repository was archived by the owner on Oct 23, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 656
/
Copy pathtests.py
97 lines (76 loc) · 2.74 KB
/
tests.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from raven.utils.testutils import TestCase
from raven.base import Client
# Some internal stuff to extend the transport layer
from raven.transport import Transport
from raven.transport.exceptions import DuplicateScheme
# Simplify comparing dicts with primitive values:
from raven.utils import json
import datetime
import calendar
import pytz
import zlib
class DummyScheme(Transport):
scheme = ['mock']
def __init__(self, timeout=5):
self.timeout = timeout
def send(self, url, data, headers):
"""
Sends a request to a remote webserver
"""
self._url = url
self._data = data
self._headers = headers
class TransportTest(TestCase):
def setUp(self):
try:
Client.register_scheme('mock', DummyScheme)
except DuplicateScheme:
pass
def test_basic_config(self):
c = Client(
dsn="mock://some_username:some_password@localhost:8143/1?timeout=1",
name="test_server"
)
assert c.remote.options == {
'timeout': '1',
}
def test_custom_transport(self):
c = Client(dsn="mock://some_username:some_password@localhost:8143/1")
data = dict(a=42, b=55, c=list(range(50)))
c.send(**data)
mock_cls = c._transport_cache['mock://some_username:some_password@localhost:8143/1'].get_transport()
print(mock_cls.__dict__)
expected_message = zlib.decompress(c.encode(data))
actual_message = zlib.decompress(mock_cls._data)
# These loads()/dumps() pairs order the dict keys before comparing the string.
# See GH504
self.assertEqual(
json.dumps(json.loads(expected_message.decode('utf-8')), sort_keys=True),
json.dumps(json.loads(actual_message.decode('utf-8')), sort_keys=True)
)
def test_build_then_send(self):
c = Client(
dsn="mock://some_username:some_password@localhost:8143/1",
name="test_server")
mydate = datetime.datetime(2012, 5, 4, tzinfo=pytz.utc)
d = calendar.timegm(mydate.timetuple())
msg = c.build_msg('raven.events.Message', message='foo', date=d)
expected = {
'project': '1',
'sentry.interfaces.Message': {
'message': 'foo',
'params': (),
'formatted': None,
},
'server_name': 'test_server',
'level': 40,
'tags': {},
'time_spent': None,
'timestamp': 1336089600,
'message': 'foo',
}
# The event_id is always overridden
del msg['event_id']
self.assertDictContainsSubset(expected, msg)