-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
import not_my_board._hub as hubmodule | ||
import not_my_board._util as util | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def hub(): | ||
yield hubmodule.Hub() | ||
|
||
|
||
async def test_no_places_on_startup(hub): | ||
places = await hub.get_places() | ||
assert places["places"] == [] | ||
|
||
|
||
async def test_register_exporter(hub): | ||
class FakeExporter: | ||
def __init__(self, register_event): | ||
self._register_event = register_event | ||
|
||
async def io_loop(self): | ||
# wait forever | ||
await asyncio.Event().wait() | ||
|
||
async def get_place(self): | ||
self._register_event.set() | ||
return { | ||
"port": 1234, | ||
"parts": [ | ||
{ | ||
"compatible": "test-board", | ||
"tcp": { | ||
"test-if": { | ||
"host": "localhost", | ||
"port": 8080, | ||
}, | ||
}, | ||
}, | ||
], | ||
} | ||
|
||
exporter_ip = "1.1.1.3" | ||
register_event = asyncio.Event() | ||
fake_exporter = FakeExporter(register_event) | ||
coro = hub.exporter_communicate(exporter_ip, fake_exporter) | ||
async with util.background_task(coro): | ||
async with asyncio.timeout(2): | ||
await register_event.wait() | ||
|
||
places = await hub.get_places() | ||
assert len(places["places"]) == 1 |