Skip to content

Commit

Permalink
almost there on the task tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewdurbin committed Apr 10, 2023
1 parent 4ec50f3 commit 1f9c8f7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def metrics_timing(*args, **kwargs):
def metrics():
return pretend.stub(
event=pretend.call_recorder(lambda *args, **kwargs: None),
gauge=pretend.call_recorder(lambda *args, **kwargs: None),
increment=pretend.call_recorder(lambda *args, **kwargs: None),
histogram=pretend.call_recorder(lambda *args, **kwargs: None),
timing=pretend.call_recorder(lambda *args, **kwargs: None),
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/packaging/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
from warehouse.accounts.models import WebAuthn
from warehouse.packaging.models import Description
from warehouse.packaging.tasks import (
check_file_archive_tasks_outstanding,
compute_2fa_mandate,
compute_2fa_metrics,
sync_bigquery_release_files,
sync_file_to_archive,
update_bigquery_release_files,
update_description_html,
)
Expand All @@ -43,6 +45,43 @@
)


def test_sync_file_to_archive(db_request):
file = FileFactory(archived=False)
primary_stub = pretend.stub(
get_metadata=pretend.call_recorder(lambda path: {"fizz": "buzz"}),
get=pretend.call_recorder(
lambda path: pretend.stub(read=lambda: b"my content")
),
)
archive_stub = pretend.stub(
store=pretend.call_recorder(lambda filename, path, meta=None: None)
)
db_request.find_service = pretend.call_recorder(
lambda iface, name=None: {"primary": primary_stub, "archive": archive_stub}[
name
]
)

sync_file_to_archive(db_request, file.id)

assert file.archived

assert primary_stub.get_metadata.calls == [pretend.call(file.path)]
assert primary_stub.get.calls == [pretend.call(file.path)]
assert archive_stub.store.calls == [pretend.call()]


def test_check_file_archive_tasks_outstanding(db_request, metrics):
archived_files = [FileFactory(archived=True) for _ in range(12)]
unarchived_files = [FileFactory(archived=False) for _ in range(3)]

check_file_archive_tasks_outstanding(db_request)

assert metrics.gauge.calls == [
pretend.call("warehouse.packaging.files.not_archived", 3)
]


def test_update_description_html(monkeypatch, db_request):
current_version = "24.0"
previous_version = "23.0"
Expand Down

0 comments on commit 1f9c8f7

Please sign in to comment.