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 6, 2024
1 parent 3d6df9f commit c72fb68
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ conda-store.sqlite
*.lockb

# generated test assets
conda-store-server/tests/alembic.ini
conda-store-server/tests/alembic.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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]:
Expand All @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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",
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 @@ -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"))
Expand All @@ -103,22 +103,28 @@ 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()

# 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 @@ -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
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 c72fb68

Please sign in to comment.