Skip to content

Commit

Permalink
tests: Add Hub tests
Browse files Browse the repository at this point in the history
  • Loading branch information
holesch committed Jan 22, 2024
1 parent fdb3320 commit 1690e15
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/test_hub.py
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

0 comments on commit 1690e15

Please sign in to comment.