|
|
@ -19,7 +19,6 @@ from httmock import urlmatch, response, HTTMock, all_requests |
|
|
|
|
|
|
|
from ..connection import ConnectionManager |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
|
import unittest |
|
|
|
except ImportError: |
|
|
@ -30,9 +29,9 @@ class TestConnection(unittest.TestCase): |
|
|
|
|
|
|
|
def setUp(self): |
|
|
|
self._conn = ConnectionManager( |
|
|
|
base_url="http://localhost/", |
|
|
|
headers={}, |
|
|
|
timeout=60) |
|
|
|
base_url="http://localhost/", |
|
|
|
headers={}, |
|
|
|
timeout=60) |
|
|
|
|
|
|
|
@all_requests |
|
|
|
def response_content_success(self, url, request): |
|
|
@ -47,7 +46,6 @@ class TestConnection(unittest.TestCase): |
|
|
|
self.assertEqual(resp.status_code, 200) |
|
|
|
|
|
|
|
def test_raw_post(self): |
|
|
|
|
|
|
|
@urlmatch(path="/known_path", method="post") |
|
|
|
def response_post_success(url, request): |
|
|
|
headers = {'content-type': 'application/json'} |
|
|
@ -56,7 +54,7 @@ class TestConnection(unittest.TestCase): |
|
|
|
|
|
|
|
with HTTMock(response_post_success): |
|
|
|
resp = self._conn.raw_post("/known_path", |
|
|
|
{'field': 'value'}) |
|
|
|
{'field': 'value'}) |
|
|
|
self.assertEqual(resp.content, b'response') |
|
|
|
self.assertEqual(resp.status_code, 201) |
|
|
|
|
|
|
@ -69,12 +67,11 @@ class TestConnection(unittest.TestCase): |
|
|
|
|
|
|
|
with HTTMock(response_put_success): |
|
|
|
resp = self._conn.raw_put("/known_path", |
|
|
|
{'field': 'value'}) |
|
|
|
{'field': 'value'}) |
|
|
|
self.assertEqual(resp.content, b'response') |
|
|
|
self.assertEqual(resp.status_code, 200) |
|
|
|
|
|
|
|
def test_raw_get_fail(self): |
|
|
|
|
|
|
|
@urlmatch(netloc="localhost", path="/known_path", method="get") |
|
|
|
def response_get_fail(url, request): |
|
|
|
headers = {'content-type': 'application/json'} |
|
|
@ -88,7 +85,6 @@ class TestConnection(unittest.TestCase): |
|
|
|
self.assertEqual(resp.status_code, 404) |
|
|
|
|
|
|
|
def test_raw_post_fail(self): |
|
|
|
|
|
|
|
@urlmatch(netloc="localhost", path="/known_path", method="post") |
|
|
|
def response_post_fail(url, request): |
|
|
|
headers = {'content-type': 'application/json'} |
|
|
@ -102,7 +98,6 @@ class TestConnection(unittest.TestCase): |
|
|
|
self.assertEqual(resp.status_code, 404) |
|
|
|
|
|
|
|
def test_raw_put_fail(self): |
|
|
|
|
|
|
|
@urlmatch(netloc="localhost", path="/known_path", method="put") |
|
|
|
def response_put_fail(url, request): |
|
|
|
headers = {'content-type': 'application/json'} |
|
|
|