Skip to content

Commit 60cadcb

Browse files
committed
Add tests for httpmanager and mock_blasthttp to reach 100% coverage
1 parent 1a7cce0 commit 60cadcb

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/httpmanager_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import pytest
2+
from baddns.lib.httpmanager import headers_to_dict
3+
from baddns.mock_blasthttp import MockBlastHTTP
4+
5+
6+
def test_headers_to_dict_passes_through_dict():
7+
headers = {"content-type": "text/html", "x-foo": "bar"}
8+
assert headers_to_dict(headers) is headers
9+
10+
11+
@pytest.mark.asyncio
12+
async def test_mock_blasthttp_pops_queued_responses_in_order():
13+
mock = MockBlastHTTP()
14+
mock.add_response(url="http://example.com/", status=200, body="first")
15+
mock.add_response(url="http://example.com/", status=500, body="second")
16+
17+
first = await mock.request("http://example.com/")
18+
second = await mock.request("http://example.com/")
19+
third = await mock.request("http://example.com/")
20+
21+
assert first.status == 200 and first.body == "first"
22+
assert second.status == 500 and second.body == "second"
23+
# one response left in queue — len(queue) == 1 path returns it without popping
24+
assert third is second

0 commit comments

Comments
 (0)