Skip to content

Commit

Permalink
[pre-commit.ci] Apply automatic pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 16, 2024
1 parent ebe9c21 commit 2280bf2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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]:
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -108,28 +108,34 @@ 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()

# 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()

Expand All @@ -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
11 changes: 6 additions & 5 deletions conda-store-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2280bf2

Please sign in to comment.