Skip to content

Commit

Permalink
fix test_lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
FynnBe committed Feb 21, 2024
1 parent 8e41d70 commit 970efb2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 4 additions & 3 deletions scripts/utils/remote_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,17 @@ class StagedVersion(_RemoteResourceVersion):
version_prefix: ClassVar[str] = "staged/"

def publish(self) -> PublishedVersion:
logger.debug("Publishing {}", self.folder)
# get next version and update versions.json
versions_path = f"{self.id}/versions.json"
versions_data = self.client.load_file(versions_path)
if versions_data is None:
versions: dict[str, Any] = {"1": {}}
versions: dict[str, Any] = {}
next_version = 1
else:
versions = json.loads(versions_data)
next_version = max(map(int, versions)) + 1

next_version = max(map(int, versions)) + 1
logger.debug("Publishing {} as version {}", self.folder, next_version)

assert next_version not in versions, (next_version, versions)

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def client():
bucket=os.environ["S3_TEST_BUCKET"],
prefix=os.environ["S3_TEST_FOLDER"] + "/pytest",
)
yield cl
cl.rm_dir("") # wipe s3 test folder
yield cl


@pytest.fixture(scope="session")
Expand Down
15 changes: 11 additions & 4 deletions tests/test_scripts/test_utils/test_remote_resource.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
def test_lifecycle(package_url: str, package_id: str, s3_test_folder_url: str):
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from scripts.utils.s3_client import Client


def test_lifecycle(
client: "Client", package_url: str, package_id: str, s3_test_folder_url: str
):
from scripts.utils.remote_resource import (
PublishedVersion,
RemoteResource,
StagedVersion,
)
from scripts.utils.s3_client import Client

resource = RemoteResource(client=Client(), id=package_id)
resource = RemoteResource(client=client, id=package_id)
staged = resource.stage_new_version(package_url)
assert isinstance(staged, StagedVersion)
staged_rdf_url = staged.get_rdf_url()
Expand All @@ -18,5 +25,5 @@ def test_lifecycle(package_url: str, package_id: str, s3_test_folder_url: str):
assert isinstance(published, PublishedVersion)
published_rdf_url = published.get_rdf_url()
assert (
published_rdf_url == f"{s3_test_folder_url}frank-water-buffalo/3/files/rdf.yaml"
published_rdf_url == f"{s3_test_folder_url}frank-water-buffalo/1/files/rdf.yaml"
)

0 comments on commit 970efb2

Please sign in to comment.