Skip to content

Commit

Permalink
records: remove save method from BuildRecord
Browse files Browse the repository at this point in the history
We don't need a .save() on RecordDB *and* BuildRecord. RecordDB seems
like the more appropriate one to keep.
  • Loading branch information
enku committed Feb 15, 2024
1 parent f17445f commit 452dcac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 27 deletions.
4 changes: 0 additions & 4 deletions src/gentoo_build_publisher/records/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ def purge_key(self) -> dt.datetime:

return submitted.replace(tzinfo=None)

def save(self, record_db: RecordDB, **fields: Any) -> BuildRecord:
"""Save changes to record_db. Return new record"""
return record_db.save(self, **fields)


class RecordDB(Protocol):
"""Repository for BuildRecords"""
Expand Down
12 changes: 5 additions & 7 deletions tests/test_views_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ def test_builds_over_time_and_build_recently(self) -> None:
for machine in ["babette", "lighthouse"]:
for day in range(2):
for _ in range(3):
build = BuildFactory(machine=machine)
record = publisher.record(build)
record = record.save(
publisher.records, submitted=now - dt.timedelta(days=day)
record = BuildRecordFactory(
machine=machine, submitted=now - dt.timedelta(days=day)
)
publisher.save(record)
publisher.pull(record)
if day == 0:
break
Expand Down Expand Up @@ -180,12 +179,11 @@ def test_packages_built_today_when_build_built_is_none(self) -> None:
self.artifact_builder.timer = int(built.timestamp())
self.artifact_builder.build(build, cpv)
publisher.pull(build)
record = publisher.record(build)

# In 2021 GBP didn't have a built field and in the database. They were
# back-filled to NULL
record = record.save(
publisher.records,
publisher.save(
publisher.record(build),
built=None,
submitted=submitted,
completed=completed,
Expand Down
31 changes: 15 additions & 16 deletions tests/test_views_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
)

from . import QuickCache, TestCase
from .factories import ArtifactFactory, BuildFactory, package_factory
from .factories import (
ArtifactFactory,
BuildFactory,
BuildRecordFactory,
package_factory,
)


class GetMetadataTestCase(TestCase):
Expand Down Expand Up @@ -157,15 +162,9 @@ def test_latest_build(self) -> None:
def test_built_recently(self) -> None:
day = dt.timedelta(days=1)
now = timezone.localtime()
b1 = publisher.record(BuildFactory(machine="babette")).save(
publisher.records, built=now - 2 * day
)
b2 = publisher.record(BuildFactory(machine="babette")).save(
publisher.records, built=now - day
)
b3 = publisher.record(BuildFactory(machine="babette")).save(
publisher.records, built=now
)
b1 = publisher.save(BuildRecordFactory(machine="babette"))
b2 = publisher.save(BuildRecordFactory(machine="babette"), built=now - day)
b3 = publisher.save(BuildRecordFactory(machine="babette"), built=now)
publisher.pull(b3)

sc = self.stats_collector()
Expand All @@ -176,20 +175,20 @@ def test_built_recently(self) -> None:

def test_builds_by_day(self) -> None:
for hour in range(2):
publisher.record(BuildFactory(machine="babette")).save(
publisher.records,
publisher.save(
BuildRecordFactory(machine="babette"),
submitted=localtime(dt.datetime(2024, 1, 13, 12))
+ dt.timedelta(hours=hour),
)
for hour in range(3):
publisher.record(BuildFactory(machine="babette")).save(
publisher.records,
publisher.save(
BuildRecordFactory(machine="babette"),
submitted=localtime(dt.datetime(2024, 1, 14, 12))
+ dt.timedelta(hours=hour),
)
for hour in range(4):
publisher.record(BuildFactory(machine="babette")).save(
publisher.records,
publisher.save(
BuildRecordFactory(machine="babette"),
submitted=localtime(dt.datetime(2024, 1, 15, 12))
+ dt.timedelta(hours=hour),
)
Expand Down

0 comments on commit 452dcac

Please sign in to comment.