Skip to content

Commit

Permalink
Move seeding tests functionality into test module
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Oct 25, 2024
1 parent 15e0b4a commit eb0c5b6
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 157 deletions.
117 changes: 0 additions & 117 deletions conda-store-server/conda_store_server/_internal/testing.py

This file was deleted.

115 changes: 113 additions & 2 deletions conda-store-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import pytest
import yaml
import json
import typing
import uuid

from sqlalchemy.orm import Session
from fastapi.testclient import TestClient

from conda_store_server import api, app, storage
Expand All @@ -18,8 +22,10 @@
action,
dbutil,
schema,
testing,
utils,
conda_utils,
orm,
schema
)

from conda_store_server._internal.server import app as server_app # isort:skip
Expand Down Expand Up @@ -118,7 +124,7 @@ def authenticate(testclient):

@pytest.fixture
def seed_conda_store(db, conda_store):
testing.seed_conda_store(
_seed_conda_store(
db,
conda_store,
{
Expand Down Expand Up @@ -275,3 +281,108 @@ def conda_prefix(conda_store, tmp_path, request):
conda_prefix=conda_prefix,
)
yield conda_prefix


def _seed_conda_store(
db: Session,
conda_store,
config: typing.Dict[str, typing.Dict[str, schema.CondaSpecification]] = {},
):
for namespace_name in config:
namespace = api.ensure_namespace(db, name=namespace_name)
for environment_name, specification in config[namespace_name].items():
environment = api.ensure_environment(
db,
name=specification.name,
namespace_id=namespace.id,
)
specification = api.ensure_specification(db, specification)
build = api.create_build(db, environment.id, specification.id)
db.commit()

environment.current_build_id = build.id
db.commit()

_create_build_artifacts(db, conda_store, build)
_create_build_packages(db, conda_store, build)

api.create_solve(db, specification.id)
db.commit()


def _create_build_packages(db: Session, conda_store, build: orm.Build):
channel_name = conda_utils.normalize_channel_name(
conda_store.conda_channel_alias, "conda-forge"
)
channel = api.ensure_conda_channel(db, channel_name)

conda_package = orm.CondaPackage(
name=f"madeup-{uuid.uuid4()}",
version="1.2.3",
channel_id=channel.id,
)
db.add(conda_package)
db.commit()

conda_package_build = orm.CondaPackageBuild(
package_id=conda_package.id,
build="fakebuild",
build_number=1,
constrains=[],
depends=[],
md5=str(uuid.uuid4()),
sha256=str(uuid.uuid4()),
size=123456,
subdir="noarch",
timestamp=12345667,
)
db.add(conda_package_build)
db.commit()

build.package_builds.append(conda_package_build)
db.commit()


def _create_build_artifacts(db: Session, conda_store, build: orm.Build):
conda_store.storage.set(
db,
build.id,
build.log_key,
b"fake logs",
content_type="text/plain",
artifact_type=schema.BuildArtifactType.LOGS,
)

directory_build_artifact = orm.BuildArtifact(
build_id=build.id,
artifact_type=schema.BuildArtifactType.DIRECTORY,
key=str(build.build_path(conda_store)),
)
db.add(directory_build_artifact)

lockfile_build_artifact = orm.BuildArtifact(
build_id=build.id, artifact_type=schema.BuildArtifactType.LOCKFILE, key=""
)
db.add(lockfile_build_artifact)

conda_store.storage.set(
db,
build.id,
build.conda_env_export_key,
json.dumps(
dict(name="testing", channels=["conda-forge"], dependencies=["numpy"])
).encode("utf-8"),
content_type="text/yaml",
artifact_type=schema.BuildArtifactType.YAML,
)

conda_store.storage.set(
db,
build.id,
build.conda_pack_key,
b"testing-conda-package",
content_type="application/gzip",
artifact_type=schema.BuildArtifactType.CONDA_PACK,
)

# have not included docker at the moment
38 changes: 0 additions & 38 deletions conda-store-server/tests/test_testing.py

This file was deleted.

0 comments on commit eb0c5b6

Please sign in to comment.