This repository has been archived by the owner on Jun 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added test for requests
- Loading branch information
jalvz
committed
Feb 19, 2016
1 parent
ff4f658
commit 118a438
Showing
3 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import requests | ||
from requests.exceptions import InvalidURL, MissingSchema | ||
from urllib3.exceptions import ConnectionError | ||
|
||
import opbeat | ||
import opbeat.instrumentation.control | ||
from opbeat.traces import trace | ||
from tests.helpers import get_tempstoreclient | ||
from tests.utils.compat import TestCase | ||
|
||
|
||
class InstrumentRequestsTest(TestCase): | ||
def setUp(self): | ||
self.client = get_tempstoreclient() | ||
opbeat.instrumentation.control.instrument() | ||
|
||
def test_requests_instrumentation(self): | ||
self.client.begin_transaction("transaction.test") | ||
with trace("test_pipeline", "test"): | ||
try: | ||
requests.get('http://example.com') | ||
except ConnectionError: | ||
pass | ||
self.client.end_transaction("MyView") | ||
|
||
_, traces = self.client.instrumentation_store.get_all() | ||
self.assertIn('GET example.com', map(lambda x: x['signature'], traces)) | ||
|
||
def test_requests_instrumentation_via_session(self): | ||
self.client.begin_transaction("transaction.test") | ||
with trace("test_pipeline", "test"): | ||
s = requests.Session() | ||
try: | ||
s.get('http://example.com') | ||
except ConnectionError: | ||
pass | ||
self.client.end_transaction("MyView") | ||
|
||
_, traces = self.client.instrumentation_store.get_all() | ||
self.assertIn('GET example.com', map(lambda x: x['signature'], traces)) | ||
|
||
def test_requests_instrumentation_malformed_none(self): | ||
self.client.begin_transaction("transaction.test") | ||
with trace("test_pipeline", "test"): | ||
self.assertRaises(MissingSchema, requests.get, None) | ||
|
||
def test_requests_instrumentation_malformed_schema(self): | ||
self.client.begin_transaction("transaction.test") | ||
with trace("test_pipeline", "test"): | ||
self.assertRaises(MissingSchema, requests.get, '') | ||
|
||
def test_requests_instrumentation_malformed_path(self): | ||
self.client.begin_transaction("transaction.test") | ||
with trace("test_pipeline", "test"): | ||
self.assertRaises(InvalidURL, requests.get, 'http://') | ||
|
||
|