Skip to content

Commit 857424a

Browse files
committed
Add tests.
1 parent 82b2e6f commit 857424a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/ext/httplib/test_httplib.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,55 @@ def test_correct_identify_https():
141141

142142
https_meta = subsegment.http
143143
assert https_meta['request']['url'].split(":")[0] == 'https'
144+
145+
146+
def test_ignore_url():
147+
from aws_xray_sdk.ext.httplib import add_ignored, reset_ignored
148+
path = '/status/200'
149+
url = 'https://{}{}'.format(BASE_URL, path)
150+
add_ignored(urls=[path])
151+
_do_req(url, use_https=True)
152+
assert len(xray_recorder.current_segment().subsegments) == 0
153+
reset_ignored()
154+
155+
156+
def test_ignore_hostname():
157+
from aws_xray_sdk.ext.httplib import add_ignored, reset_ignored
158+
path = '/status/200'
159+
url = 'https://{}{}'.format(BASE_URL, path)
160+
add_ignored(hostname=BASE_URL)
161+
_do_req(url, use_https=True)
162+
assert len(xray_recorder.current_segment().subsegments) == 0
163+
reset_ignored()
164+
165+
166+
def test_ignore_subclass():
167+
class TestClass(httplib.HTTPSConnection):
168+
pass
169+
from aws_xray_sdk.ext.httplib import add_ignored, reset_ignored
170+
path = '/status/200'
171+
add_ignored(subclass='TestClass')
172+
conn = TestClass(BASE_URL)
173+
conn.request('GET', path)
174+
conn.getresponse()
175+
assert len(xray_recorder.current_segment().subsegments) == 0
176+
reset_ignored()
177+
178+
179+
def test_ignore_multiple():
180+
class TestClass(httplib.HTTPSConnection):
181+
pass
182+
from aws_xray_sdk.ext.httplib import add_ignored, reset_ignored
183+
path = '/status/200'
184+
add_ignored(subclass='TestClass', hostname=BASE_URL)
185+
conn = TestClass(BASE_URL)
186+
conn.request('GET', path)
187+
conn.getresponse()
188+
assert len(xray_recorder.current_segment().subsegments) == 0
189+
reset_ignored()
190+
add_ignored(subclass='TestClass', hostname='fake.host')
191+
conn = TestClass(BASE_URL)
192+
conn.request('GET', path)
193+
conn.getresponse()
194+
assert len(xray_recorder.current_segment().subsegments) > 0
195+
reset_ignored()

0 commit comments

Comments
 (0)