This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from mfelsche/m/traffic0
fix 400 errors on lizzy traffic
- Loading branch information
Showing
2 changed files
with
75 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pytest | ||
from unittest.mock import MagicMock | ||
import json | ||
|
||
from lizzy.apps.common import Application | ||
from lizzy.exceptions import ExecutionError | ||
|
||
|
||
@pytest.fixture | ||
def popen(monkeypatch): | ||
mock_popen = MagicMock() | ||
mock_popen.return_value = mock_popen | ||
mock_popen.returncode = 0 | ||
monkeypatch.setattr('lizzy.apps.common.Popen', mock_popen) | ||
return mock_popen | ||
|
||
|
||
def test_json_output(monkeypatch, popen): | ||
expected = {"foo": "bar"} | ||
popen.communicate.return_value = json.dumps(expected).encode(), b'stderr' | ||
|
||
app = Application("foo") | ||
output = app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=True) | ||
assert output == expected | ||
|
||
output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=True) | ||
assert output == json.dumps(expected) | ||
|
||
output = app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=False) | ||
assert output == expected | ||
|
||
output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=False) | ||
assert output == json.dumps(expected) | ||
|
||
|
||
def test_empty_output(monkeypatch, popen): | ||
expected = "" | ||
popen.communicate.return_value = expected.encode(), b'stderr' | ||
|
||
app = Application("foo") | ||
|
||
output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=True) | ||
assert output == expected | ||
|
||
output = app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=True) | ||
assert output == expected | ||
|
||
with pytest.raises(ExecutionError): | ||
app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=False) | ||
|
||
with pytest.raises(ExecutionError): | ||
app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=False) | ||
|
||
|
||
def test_invalid_json_output(monkeypatch, popen): | ||
expected = "[[}" | ||
popen.communicate.return_value = expected.encode(), b'stderr' | ||
|
||
app = Application("foo") | ||
output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=True) | ||
assert output == expected | ||
|
||
output = app._execute("bar", "a", "b", "c", expect_json=False, accept_empty=False) | ||
assert output == expected | ||
|
||
with pytest.raises(ExecutionError): | ||
app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=False) | ||
|
||
with pytest.raises(ExecutionError): | ||
app._execute("bar", "a", "b", "c", expect_json=True, accept_empty=True) |