Skip to content

Commit

Permalink
fix test after prev change
Browse files Browse the repository at this point in the history
  • Loading branch information
willforde committed Aug 12, 2019
1 parent bd2d06e commit 829f2f7
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@pytest.fixture
def api():
obj = API()
obj = API(queue.Queue(10))
obj.timeout = 0.01
with mock.patch.object(obj, "running") as mocker:
mocker.is_set.side_effect = [True, False]
Expand Down Expand Up @@ -39,7 +39,7 @@ def callback(request, context):

def test_push(api, record):
assert api.queue.empty()
api.push(record)
api.queue.put(record)
assert not api.queue.empty()


Expand All @@ -53,7 +53,7 @@ def test_empty_queue(api, requests_mock, req_callback):


def test_run_201(api, record, requests_mock, req_callback):
api.push(record)
api.queue.put(record)
requests_mock.post(url, json=req_callback.resp({"success": True}), status_code=201)
api.run()

Expand All @@ -62,7 +62,7 @@ def test_run_201(api, record, requests_mock, req_callback):


def test_run_400(api, record, requests_mock, req_callback):
api.push(record)
api.queue.put(record)
requests_mock.post(url, json=req_callback.resp({"error": "field is missing"}), status_code=400)
api.run()

Expand All @@ -71,7 +71,7 @@ def test_run_400(api, record, requests_mock, req_callback):


def test_run_401(api, record, requests_mock, req_callback):
api.push(record)
api.queue.put(record)
requests_mock.post(url, json=req_callback.resp({"error": "permission required"}), status_code=401)
api.run()

Expand All @@ -80,7 +80,7 @@ def test_run_401(api, record, requests_mock, req_callback):


def test_run_403(api, record, requests_mock, req_callback):
api.push(record)
api.queue.put(record)
requests_mock.post(url, json=req_callback.resp({"error": "access forbidden"}), status_code=403)
api.run()

Expand All @@ -89,7 +89,7 @@ def test_run_403(api, record, requests_mock, req_callback):


def test_run_500(api, record, requests_mock, req_callback):
api.push(record)
api.queue.put(record)
requests_mock.post(url, text=req_callback.resp(""), status_code=500)
api.run()

Expand All @@ -98,15 +98,15 @@ def test_run_500(api, record, requests_mock, req_callback):


def test_exception_timeout(api, record):
api.push(record)
api.queue.put(record)
with mock.patch.object(api, "session") as mocker:
mocker.post.side_effect = requests.Timeout
api.run()
mocker.post.assert_called()


def test_exception_connection_error(api, record):
api.push(record)
api.queue.put(record)
with mock.patch.object(api, "session") as mocker:
mocker.post.side_effect = requests.ConnectionError
api.run()
Expand All @@ -115,7 +115,7 @@ def test_exception_connection_error(api, record):

def test_exception_connection_error_incoming(api):
record = Record(0, number="0876521354", line=1, ext=102)
api.push(record)
api.queue.put(record)
with mock.patch.object(api, "session") as mocker:
mocker.post.side_effect = requests.ConnectionError
api.run()
Expand All @@ -125,7 +125,7 @@ def test_exception_connection_error_incoming(api):
def test_exception_queue_full(api, record):
with mock.patch.object(api, "queue", spec=True) as queue_mock:
queue_mock.put_nowait.side_effect = queue.Full
api.push(record)
api.queue.put(record)

with mock.patch.object(api, "session") as req_mock:
req_mock.post.side_effect = requests.Timeout
Expand Down

0 comments on commit 829f2f7

Please sign in to comment.