diff --git a/scripts/utils/remote_resource.py b/scripts/utils/remote_resource.py index 30873d98..c742408b 100644 --- a/scripts/utils/remote_resource.py +++ b/scripts/utils/remote_resource.py @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py index 2db59e62..ebb55f26 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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") diff --git a/tests/test_scripts/test_utils/test_remote_resource.py b/tests/test_scripts/test_utils/test_remote_resource.py index e462e9f3..0c94f47a 100644 --- a/tests/test_scripts/test_utils/test_remote_resource.py +++ b/tests/test_scripts/test_utils/test_remote_resource.py @@ -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() @@ -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" )