Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit fa977ba

Browse files
authored
Add test for hook_libraries (#1185)
* Add test for hook_libraries
1 parent 3b1cb30 commit fa977ba

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/breadcrumbs/tests.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
from io import StringIO
1010

1111

12+
class DummyClass(object):
13+
def dummy_method(self):
14+
pass
15+
16+
1217
class BreadcrumbTestCase(TestCase):
1318

1419
def test_crumb_buffer(self):
@@ -163,3 +168,28 @@ def handler(logger, level, msg, args, kwargs):
163168
logger.debug('aha!')
164169
crumbs = client.context.breadcrumbs.get_buffer()
165170
assert len(crumbs) == 0
171+
172+
def test_hook_libraries(self):
173+
174+
@breadcrumbs.libraryhook('dummy')
175+
def _install_func():
176+
old_func = DummyClass.dummy_method
177+
178+
def new_func(self):
179+
breadcrumbs.record(type='dummy', category='dummy', message="Dummy message")
180+
old_func(self)
181+
182+
DummyClass.dummy_method = new_func
183+
184+
client = Client('http://foo:bar@example.com/0', hook_libraries=['requests'])
185+
with client.context:
186+
DummyClass().dummy_method()
187+
crumbs = client.context.breadcrumbs.get_buffer()
188+
assert 'dummy' not in set([i['type'] for i in crumbs])
189+
190+
client = Client('http://foo:bar@example.com/0', hook_libraries=['requests', 'dummy'])
191+
with client.context:
192+
DummyClass().dummy_method()
193+
crumbs = client.context.breadcrumbs.get_buffer()
194+
assert 'dummy' in set([i['type'] for i in crumbs])
195+

0 commit comments

Comments
 (0)