forked from rc/aircox
write tests for serializers; add controllers.streamers + tests
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import itertools
|
||||
import os
|
||||
|
||||
from datetime import datetime, time
|
||||
@@ -74,21 +75,53 @@ def station():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def station_ports(station):
|
||||
items = [
|
||||
models.Port(
|
||||
station=station,
|
||||
direction=models.Port.DIRECTION_INPUT,
|
||||
type=models.Port.TYPE_HTTP,
|
||||
def stations(station):
|
||||
objs = [
|
||||
models.Station(
|
||||
name=f"test-{i}",
|
||||
slug=f"test-{i}",
|
||||
path=working_dir,
|
||||
default=(i == 0),
|
||||
active=True,
|
||||
),
|
||||
models.Port(
|
||||
station=station,
|
||||
direction=models.Port.DIRECTION_OUTPUT,
|
||||
type=models.Port.TYPE_FILE,
|
||||
active=True,
|
||||
),
|
||||
)
|
||||
for i in range(0, 3)
|
||||
]
|
||||
models.Station.objects.bulk_create(objs)
|
||||
return [station] + objs
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def station_ports(station):
|
||||
return _stations_ports(station)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def stations_ports(stations):
|
||||
return _stations_ports(*stations)
|
||||
|
||||
|
||||
def _stations_ports(*stations):
|
||||
items = list(
|
||||
itertools.chain(
|
||||
*[
|
||||
(
|
||||
models.Port(
|
||||
station=station,
|
||||
direction=models.Port.DIRECTION_INPUT,
|
||||
type=models.Port.TYPE_HTTP,
|
||||
active=True,
|
||||
),
|
||||
models.Port(
|
||||
station=station,
|
||||
direction=models.Port.DIRECTION_OUTPUT,
|
||||
type=models.Port.TYPE_FILE,
|
||||
active=True,
|
||||
),
|
||||
)
|
||||
for station in stations
|
||||
]
|
||||
)
|
||||
)
|
||||
models.Port.objects.bulk_create(items)
|
||||
return items
|
||||
|
||||
@@ -180,3 +213,50 @@ def metadata_string(metadata_data):
|
||||
"\n".join(f"{key}={value}" for key, value in metadata_data.items())
|
||||
+ "\nEND"
|
||||
)
|
||||
|
||||
|
||||
# -- streamers
|
||||
class FakeStreamer(controllers.Streamer):
|
||||
calls = {}
|
||||
|
||||
def fetch(self):
|
||||
self.calls["fetch"] = True
|
||||
|
||||
|
||||
class FakeSource(controllers.Source):
|
||||
def __init__(self, id, *args, **kwargs):
|
||||
self.id = id
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self.calls = {}
|
||||
|
||||
def fetch(self):
|
||||
self.calls["sync"] = True
|
||||
|
||||
def sync(self):
|
||||
self.calls["sync"] = True
|
||||
|
||||
def push(self, path):
|
||||
self.calls["push"] = path
|
||||
return path
|
||||
|
||||
def skip(self):
|
||||
self.calls["skip"] = True
|
||||
|
||||
def restart(self):
|
||||
self.calls["restart"] = True
|
||||
|
||||
def seek(self, c):
|
||||
self.calls["seek"] = c
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def streamers(stations, stations_ports):
|
||||
streamers = controllers.Streamers(streamer_class=FakeStreamer)
|
||||
# avoid unecessary db calls
|
||||
streamers.streamers = {
|
||||
station.pk: FakeStreamer(station) for station in stations
|
||||
}
|
||||
for streamer in streamers.values():
|
||||
streamer.sources = [FakeSource(i) for i in range(0, 3)]
|
||||
return streamers
|
||||
|
||||
Reference in New Issue
Block a user