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 Oct 28, 2024
1 parent 5d78a79 commit 2954f45
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
21 changes: 10 additions & 11 deletions conda-store-server/tests/_internal/worker/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

import pytest
import logging

from unittest.mock import patch
import pytest

from conda_store_server._internal.worker.app import CondaStoreWorker

Expand All @@ -20,28 +19,28 @@ def test_worker_with_valid_config(conda_store_config, tmp_path):
test_config_file = str(tmp_path / "config1")
with open(test_config_file, "w") as file:
file.write(config_file_contents)

worker = CondaStoreWorker(config=conda_store_config)
worker.config_file = test_config_file
worker.initialize()


def test_worker_with_invalid_config(conda_store_config):
worker = CondaStoreWorker(config=conda_store_config)
with pytest.raises(SystemExit) as exc_info:
with pytest.raises(SystemExit) as exc_info:
worker.config_file = "/i/dont/exist"
worker.initialize()

assert exc_info.value.code == 1


@pytest.mark.parametrize(
"logging_level,output",
[
(logging.INFO, "INFO"),
(logging.CRITICAL, "CRITICAL"),
(logging.FATAL, "CRITICAL"),
]
"logging_level,output",
[
(logging.INFO, "INFO"),
(logging.CRITICAL, "CRITICAL"),
(logging.FATAL, "CRITICAL"),
],
)
def test_logger_to_celery_logging_level(logging_level, output):
worker = CondaStoreWorker()
Expand Down
61 changes: 38 additions & 23 deletions conda-store-server/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import pytest

from conda_store_server import storage
from conda_store_server import api, storage
from conda_store_server._internal import schema
from conda_store_server import api


@pytest.fixture()
def local_file_store(tmp_path):
Expand All @@ -16,7 +16,7 @@ def local_file_store(tmp_path):
tf_two = str(tmp_path / "testfile2")
with open(tf_two, "w") as file:
file.write("testfile2")

logs_path = tmp_path / "logs"
os.mkdir(logs_path)

Expand All @@ -29,65 +29,80 @@ def test_fset_new_package(self, db):
store.fset(db, 123, "new_build_key", "", schema.BuildArtifactType.YAML)
assert len(api.list_build_artifacts(db).all()) == 1


def test_fset_existing_package(self, seed_conda_store):
store = storage.Storage()
db = seed_conda_store

inital_artifacts = api.list_build_artifacts(db).all()
artifact = inital_artifacts[0]

store.fset(db, artifact.build_id, artifact.key, "", artifact.artifact_type)
assert len(api.list_build_artifacts(db).all()) == len(inital_artifacts)

def test_delete_existing_artifact(self, seed_conda_store):
store = storage.Storage()
db = seed_conda_store

inital_artifacts = api.list_build_artifacts(db).all()
artifact = inital_artifacts[0]

store.delete(db, artifact.build_id, artifact.key)
assert len(api.list_build_artifacts(db).all()) == len(inital_artifacts)-1
assert len(api.list_build_artifacts(db).all()) == len(inital_artifacts) - 1


class TestLocalStorage:
def test_fset_new_package(self, db, local_file_store):
store = storage.LocalStorage()
store.storage_path = local_file_store

filename = str(local_file_store / "testfile1")
store.fset(db, 123, "new_build_key", filename, "contenttype", schema.BuildArtifactType.YAML)
store.fset(
db,
123,
"new_build_key",
filename,
"contenttype",
schema.BuildArtifactType.YAML,
)
assert len(api.list_build_artifacts(db).all()) == 1

target_file = str(local_file_store / "new_build_key")
assert os.path.exists(target_file)
target_content = open(target_file, 'r').read()
target_content = open(target_file, "r").read()
assert target_content == "testfile1"

def test_fset_dont_overwrite_file(self, db, local_file_store):
store = storage.LocalStorage()
store.storage_path = local_file_store

filename = str(local_file_store / "testfile1")
store.fset(db, 123, "testfile2", filename, "contenttype", schema.BuildArtifactType.YAML)
store.fset(
db, 123, "testfile2", filename, "contenttype", schema.BuildArtifactType.YAML
)
assert len(api.list_build_artifacts(db).all()) == 1

target_file = str(local_file_store / "testfile2")
assert os.path.exists(target_file)
target_content = open(target_file, 'r').read()
target_content = open(target_file, "r").read()
assert target_content == "testfile1"

def test_set_new_package(self, db, local_file_store):
store = storage.LocalStorage()
store.storage_path = local_file_store

store.set(db, 123, "new_build_key", b"somestuff", "contenttype", schema.BuildArtifactType.YAML)

store.set(
db,
123,
"new_build_key",
b"somestuff",
"contenttype",
schema.BuildArtifactType.YAML,
)
assert len(api.list_build_artifacts(db).all()) == 1

target_file = str(local_file_store / "new_build_key")
assert os.path.exists(target_file)
target_content = open(target_file, 'r').read()
target_content = open(target_file, "r").read()
assert target_content == "somestuff"

def test_get(self, local_file_store):
Expand All @@ -110,6 +125,6 @@ def test_delete(self, seed_conda_store, local_file_store):
file.write("testfile2")

store.delete(db, artifact.build_id, artifact.key)
assert len(api.list_build_artifacts(db).all()) == len(inital_artifacts)-1
assert len(api.list_build_artifacts(db).all()) == len(inital_artifacts) - 1

assert not os.path.exists(target_file)

0 comments on commit 2954f45

Please sign in to comment.