diff --git a/tests/setup.py b/tests/setup.py index 9d8b41b..50b170d 100644 --- a/tests/setup.py +++ b/tests/setup.py @@ -4,6 +4,7 @@ import copy import datetime as dt import importlib.metadata +import itertools import os import tempfile from contextlib import contextmanager @@ -181,6 +182,32 @@ def build(_options: SetupOptions, _fixtures: Fixtures) -> Build: return BuildFactory() +def builds( + options: SetupOptions, _fixtures: Fixtures +) -> dict[str, list[Build]] | list[Build]: + builds_options = options.get("builds", {}) + machines = builds_options.get("machines", ["babette"]) + end_date = builds_options.get("end_time", now()) + num_days = builds_options.get("num_days", 1) + per_day = builds_options.get("per_day", 1) + builds_map = BuildFactory.buncha_builds(machines, end_date, num_days, per_day) + + if len(machines) == 1: + return builds_map[machines[0]] + return builds_map + + +@depends(builds, publisher) +def pulled_builds(_options: SetupOptions, fixtures: Fixtures) -> None: + if isinstance(fixtures.builds, dict): + builds_ = list(itertools.chain(*fixtures.builds.values())) + else: + builds_ = fixtures.builds + + for build_ in builds_: + fixtures.publisher.pull(build_) + + @depends(tmpdir) def storage(_options: SetupOptions, fixtures: Fixtures) -> Storage: root = fixtures.tmpdir / "root" diff --git a/tests/test_views.py b/tests/test_views.py index 9528520..2f7d1e3 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -14,7 +14,6 @@ from . import DjangoTestCase as BaseTestCase from . import setup -from .factories import BuildFactory from .setup_types import Fixtures, SetupOptions now = partial(dt.datetime.now, tz=dt.UTC) @@ -26,14 +25,7 @@ def lighthouse(_options: SetupOptions, fixtures: Fixtures) -> HttpResponse: return response -@setup.depends("clock", "publisher") -def builds(_options: SetupOptions, fixtures: Fixtures) -> dict[str, list[Build]]: - machines = ["babette", "lighthouse", "web"] - - return BuildFactory.buncha_builds(machines, fixtures.clock, 3, 2) - - -@setup.depends("publisher", builds) +@setup.depends("publisher", "builds") def artifacts(_options: SetupOptions, fixtures: Fixtures) -> dict[str, Build]: artifact_builder = fixtures.publisher.jenkins.artifact_builder published = first_build(fixtures.builds, "lighthouse") @@ -49,9 +41,16 @@ def artifacts(_options: SetupOptions, fixtures: Fixtures) -> dict[str, Build]: return {"published": published, "latest": latest} -@setup.requires("tmpdir", "clock", "publisher", builds) +@setup.requires("publisher", "builds") class TestCase(BaseTestCase): - options = {"records_backend": "memory"} + options = { + "records_backend": "memory", + "builds": { + "machines": ["babette", "lighthouse", "web"], + "num_days": 3, + "per_day": 2, + }, + } class DashboardTestCase(TestCase): @@ -147,7 +146,7 @@ def test_tagged_builds_should_have_a_binrepos_dot_conf(self) -> None: self.assertTrue(b"/binpkgs/lighthouse@prod/" in response.content) -@setup.requires("publisher", "client", builds, artifacts, lighthouse) +@setup.requires("publisher", "client", "builds", artifacts, lighthouse) class MachineViewTests(TestCase): """Tests for the machine view"""