diff --git a/.gitignore b/.gitignore index 58c20b944..75e7762e7 100644 --- a/.gitignore +++ b/.gitignore @@ -64,4 +64,4 @@ conda-store.sqlite *.lockb # generated test assets -conda-store-server/tests/alembic.ini \ No newline at end of file +conda-store-server/tests/alembic.ini diff --git a/conda-store-server/conda_store_server/_internal/alembic/versions/89637f546129_remove_conda_package_build_channel.py b/conda-store-server/conda_store_server/_internal/alembic/versions/89637f546129_remove_conda_package_build_channel.py index 8e3548c3e..63f2abc89 100644 --- a/conda-store-server/conda_store_server/_internal/alembic/versions/89637f546129_remove_conda_package_build_channel.py +++ b/conda-store-server/conda_store_server/_internal/alembic/versions/89637f546129_remove_conda_package_build_channel.py @@ -42,11 +42,11 @@ def fix_misrepresented_packages(conn): def get_conda_package_id(conn, channel_id, name, version): hashed_name = f"{channel_id}-{name}-{version}" - + # if package exists in the conda_packages dict, return it if hashed_name in conda_packages: return conda_packages[hashed_name] - + # if not, then query the db for the package package = conn.execute( select(conda_package_table).where( @@ -75,7 +75,7 @@ def get_conda_package_id(conn, channel_id, name, version): # the channel_id might already be empty if row[2] is None: continue - + package_id = get_conda_package_id(conn, row[2], row[3], row[4]) # if found package id does not match the found package id, we'll need to updated it if package_id != row[1]: @@ -94,7 +94,7 @@ def upgrade(): # Due to the issue fixed in https://github.com/conda-incubator/conda-store/pull/961 # many conda_package_build entries have the wrong package entry (but the right channel). # Because the packages are duplicated, we can not recreate the _conda_package_build_uc - # constraint without the channel_id. + # constraint without the channel_id. # So, go thru each conda_package_build and re-associate it with the correct conda_package # based on the channel id. fix_misrepresented_packages(bind) @@ -108,7 +108,7 @@ def upgrade(): # re-add the constraint without the channel column batch_op.create_unique_constraint( "_conda_package_build_uc", - [ + [ "package_id", "subdir", "build", @@ -142,7 +142,7 @@ def downgrade(): # re-add the constraint with the channel column batch_op.create_unique_constraint( constraint_name="_conda_package_build_uc", - columns=[ + columns=[ "channel_id", "package_id", "subdir", diff --git a/conda-store-server/tests/_internal/alembic/version/test_89637f546129_remove_conda_package_build_channel.py b/conda-store-server/tests/_internal/alembic/version/test_89637f546129_remove_conda_package_build_channel.py index b5261f391..9af2d7fc8 100644 --- a/conda-store-server/tests/_internal/alembic/version/test_89637f546129_remove_conda_package_build_channel.py +++ b/conda-store-server/tests/_internal/alembic/version/test_89637f546129_remove_conda_package_build_channel.py @@ -2,7 +2,7 @@ # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. -from sqlalchemy import insert, select, table, Column, INTEGER, String, ForeignKey, text +from sqlalchemy import text from conda_store_server import api from conda_store_server._internal import orm @@ -84,17 +84,17 @@ def setup_bad_data_db(conda_store): }, ] default_values = { - "depends": "", - "md5": "", - "timestamp": 0, - "constrains": "", - "size": 0, + "depends": "", + "md5": "", + "timestamp": 0, + "constrains": "", + "size": 0, } for cpb in conda_package_builds: conda_package = orm.CondaPackageBuild(**cpb, **default_values) db.add(conda_package) db.commit() - + # force in some channel data db.execute(text("UPDATE conda_package_build SET channel_id=2 WHERE id=1")) db.execute(text("UPDATE conda_package_build SET channel_id=1 WHERE id=2")) @@ -103,10 +103,13 @@ def setup_bad_data_db(conda_store): db.execute(text("UPDATE conda_package_build SET channel_id=1 WHERE id=5")) db.commit() -def test_remove_conda_package_build_channel_basic(conda_store, alembic_config, alembic_engine, alembic_runner): + +def test_remove_conda_package_build_channel_basic( + conda_store, alembic_config, alembic_engine, alembic_runner +): """Simply run the upgrade and downgrade for this migration""" # migrate all the way to the target revision - alembic_runner.migrate_up_to('89637f546129') + alembic_runner.migrate_up_to("89637f546129") # try downgrading alembic_runner.migrate_down_one() @@ -114,11 +117,14 @@ def test_remove_conda_package_build_channel_basic(conda_store, alembic_config, a # try upgrading once more alembic_runner.migrate_up_one() -def test_remove_conda_package_build_bad_data(conda_store, alembic_config, alembic_engine, alembic_runner): + +def test_remove_conda_package_build_bad_data( + conda_store, alembic_config, alembic_engine, alembic_runner +): """Simply run the upgrade and downgrade for this migration""" - # migrate all the way to the target revision - alembic_runner.migrate_up_to('89637f546129') - + # migrate all the way to the target revision + alembic_runner.migrate_up_to("89637f546129") + # try downgrading alembic_runner.migrate_down_one() @@ -130,27 +136,37 @@ def test_remove_conda_package_build_bad_data(conda_store, alembic_config, alembi # ensure all packages builds have the right package associated with conda_store.session_factory() as db: - build = db.query(orm.CondaPackageBuild).filter( - orm.CondaPackageBuild.id == 1 - ).first() + build = ( + db.query(orm.CondaPackageBuild) + .filter(orm.CondaPackageBuild.id == 1) + .first() + ) assert build.package_id == 2 - build = db.query(orm.CondaPackageBuild).filter( - orm.CondaPackageBuild.id == 2 - ).first() + build = ( + db.query(orm.CondaPackageBuild) + .filter(orm.CondaPackageBuild.id == 2) + .first() + ) assert build.package_id == 1 - build = db.query(orm.CondaPackageBuild).filter( - orm.CondaPackageBuild.id == 3 - ).first() + build = ( + db.query(orm.CondaPackageBuild) + .filter(orm.CondaPackageBuild.id == 3) + .first() + ) assert build.package_id == 1 - build = db.query(orm.CondaPackageBuild).filter( - orm.CondaPackageBuild.id == 4 - ).first() + build = ( + db.query(orm.CondaPackageBuild) + .filter(orm.CondaPackageBuild.id == 4) + .first() + ) assert build.package_id == 2 - build = db.query(orm.CondaPackageBuild).filter( - orm.CondaPackageBuild.id == 5 - ).first() + build = ( + db.query(orm.CondaPackageBuild) + .filter(orm.CondaPackageBuild.id == 5) + .first() + ) assert build.package_id == 1 diff --git a/conda-store-server/tests/conftest.py b/conda-store-server/tests/conftest.py index 3679c4ab2..5406c92a8 100644 --- a/conda-store-server/tests/conftest.py +++ b/conda-store-server/tests/conftest.py @@ -13,7 +13,6 @@ import yaml from fastapi.testclient import TestClient from sqlalchemy.orm import Session -from pytest_alembic.config import Config from conda_store_server import api, app, storage @@ -293,10 +292,12 @@ def plugin_manager(): @pytest.fixture def alembic_config(conda_store): - from conda_store_server._internal.dbutil import ALEMBIC_DIR, write_alembic_ini - ini_file = pathlib.Path(__file__).parent / "alembic.ini" - write_alembic_ini(ini_file, conda_store.database_url) - return {"file": ini_file} + from conda_store_server._internal.dbutil import write_alembic_ini + + ini_file = pathlib.Path(__file__).parent / "alembic.ini" + write_alembic_ini(ini_file, conda_store.database_url) + return {"file": ini_file} + @pytest.fixture def alembic_engine(db):