Skip to content

Commit

Permalink
Add tests for archiving builds
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Jan 16, 2025
1 parent 642728d commit d48580c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
38 changes: 38 additions & 0 deletions conda-store-server/tests/_internal/server/views/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,44 @@ def test_delete_build_auth_completed_build(testclient, seed_conda_store, authent
assert build_data.get("deleted_on") is not None


def test_archive_build_unauth(testclient, seed_conda_store):
build_id = 4

response = testclient.post(f"api/v1/build/{build_id}/archive")
assert response.status_code == 403

r = schema.APIResponse.model_validate(response.json())
assert r.status == schema.APIStatus.ERROR


def test_archive_build_auth_completed_build(testclient, seed_conda_store, authenticate, celery_worker):
new_build_id = 4

# ensure the build exists - seed_conda_store should create a build
# with id 4 that is in the "completed" state
response = testclient.get(f"api/v1/build/{new_build_id}")
response.raise_for_status()
response_json = response.json()
r = schema.APIGetBuild.model_validate(response_json)
assert r.status == schema.APIStatus.OK
build_data = response_json.get("data")
assert build_data.get("deleted_on") is None

# delete the build
response = testclient.post(f"api/v1/build/{new_build_id}/archive")
assert response.status_code == 200

# check to make sure the build has been deleted
response = testclient.get(f"api/v1/build/{new_build_id}")
response.raise_for_status()
response_json = response.json()
r = schema.APIGetBuild.model_validate(response_json)
assert r.status == schema.APIStatus.OK
build_data = response_json.get("data")
assert build_data.get("archived_on") is not None
assert build_data.get("status") == "ARCHIVED"


@pytest.mark.parametrize(
"route",
[
Expand Down
16 changes: 16 additions & 0 deletions conda-store-server/tests/test_conda_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,19 @@ def test_conda_store_delete_build(seed_conda_store, conda_store):
build = api.get_build(db, build_id=4)
assert build.deleted_on is not None
assert build.status == schema.BuildStatus.DELETED


def test_conda_store_archive_build(seed_conda_store, conda_store):
"""Ensure conda store will archive a build and update all appropriate metadata"""
db = seed_conda_store

# build 4 is completed, we'll use that test test deletion
build = api.get_build(db, build_id=4)
assert build.archived_on is None
assert build.status == schema.BuildStatus.COMPLETED

conda_store.archive_build(db, 4)

build = api.get_build(db, build_id=4)
assert build.archived_on is not None
assert build.status == schema.BuildStatus.ARCHIVED

0 comments on commit d48580c

Please sign in to comment.