-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
...-server/tests/_internal/alembic/version/test_8c5abec6e601_add_build_archived_on_column.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (c) conda-store development team. All rights reserved. | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file. | ||
|
||
import pytest | ||
import datetime | ||
|
||
from sqlalchemy import text | ||
from sqlalchemy.exc import OperationalError | ||
|
||
from conda_store_server import api | ||
from conda_store_server._internal import orm | ||
|
||
|
||
def test_add_build_archived_on_column_basic( | ||
conda_store, alembic_config, alembic_runner | ||
): | ||
"""Simply run the upgrade and downgrade for this migration""" | ||
# migrate all the way to the target revision | ||
alembic_runner.migrate_up_to("8c5abec6e601") | ||
|
||
# ensure the archived_on column exists | ||
with conda_store.session_factory() as db: | ||
db.execute(text("SELECT archived_on from build")) | ||
|
||
# try downgrading | ||
alembic_runner.migrate_down_one() | ||
|
||
# ensure the archived_on column does not exists | ||
with conda_store.session_factory() as db: | ||
with pytest.raises(OperationalError): | ||
db.execute(text("SELECT archived_on from build")) | ||
|
||
# try upgrading once more | ||
alembic_runner.migrate_up_one() | ||
|
||
# ensure the archived_on column exists | ||
with conda_store.session_factory() as db: | ||
db.execute(text("SELECT archived_on from build")) | ||
|
||
|
||
def test_downgrade_works_for_populated_column( | ||
conda_store, alembic_config, alembic_runner, seed_conda_store | ||
): | ||
"""Try to run the downgrade part of the migration when the `archived_on` column has data""" | ||
# migrate all the way to the target revision | ||
alembic_runner.migrate_up_to("8c5abec6e601") | ||
|
||
# ensure the archived_on column exists | ||
with conda_store.session_factory() as db: | ||
db.execute(text("SELECT archived_on from build")) | ||
|
||
# update demo data to have data in archived_on column | ||
with conda_store.session_factory() as db: | ||
build = api.get_build(db, 1) | ||
build.archived_on = datetime.datetime.now(datetime.UTC) | ||
db.commit() | ||
|
||
# try downgrading | ||
alembic_runner.migrate_down_one() | ||
|
||
# ensure the archived_on column does not exists | ||
with conda_store.session_factory() as db: | ||
with pytest.raises(OperationalError): | ||
db.execute(text("SELECT archived_on from build")) |