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 d8272d8e1..cfecde382 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 @@ -22,8 +22,8 @@ # 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. -# So, this function will go thru each conda_package_build and re-associate it with the +# constraint without the channel_id. +# So, this function will go thru each conda_package_build and re-associate it with the # correct conda_package based on the channel id. def fix_misrepresented_packages(conn): # conda_packages is a hash of channel-id_name_version to conda_package id @@ -46,11 +46,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( @@ -79,7 +79,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]: @@ -107,7 +107,7 @@ def upgrade(): # re-add the constraint without the channel column batch_op.create_unique_constraint( "_conda_package_build_uc", - [ + [ "package_id", "subdir", "build", @@ -139,7 +139,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 ce26b1fc3..12cbe69e1 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 @@ -88,11 +88,11 @@ 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) @@ -108,16 +108,19 @@ def setup_bad_data_db(conda_store): db.execute(text("UPDATE conda_package_build SET channel_id=1 WHERE id=3")) # conda_package_build 4 should have package_id 2 after migration db.execute(text("UPDATE conda_package_build SET channel_id=2 WHERE id=4")) - + # don't set conda_package_build 5 channel_id as a test case # conda_package_build 5 package_id should be unchanged (2) after migration - + 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() @@ -125,11 +128,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() @@ -141,27 +147,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 == 2 diff --git a/conda-store-server/tests/conftest.py b/conda-store-server/tests/conftest.py index 7b8223c93..929df5965 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):