Skip to content

Commit

Permalink
DRY resource get tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aristizabal95 committed Oct 25, 2024
1 parent 39cd511 commit 8767d0b
Showing 1 changed file with 14 additions and 39 deletions.
53 changes: 14 additions & 39 deletions cli/medperf/tests/comms/entity_resources/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,61 +120,36 @@ def test_get_additional_files_will_download_if_folder_exists_and_hash_valid_but_
assert spy.call_count == 2


class TestGetCube:
def test_get_cube_does_not_download_if_folder_exists_and_hash_valid(
self, mocker, fs
@pytest.mark.parametrize("method", [
resources.get_cube,
resources.get_cube_params,
resources.get_cube_stages,
])
class TestGet:
def test_get_does_not_download_if_folder_exists_and_hash_valid(
self, mocker, fs, method
):
# Arrange
cube_path = "cube/1"
spy = mocker.spy(resources, "download_resource")
_, exp_hash = resources.get_cube(url, cube_path)
_, exp_hash = method(url, cube_path)

# Act
resources.get_cube(url, cube_path, exp_hash)
method(url, cube_path, exp_hash)

# Assert
spy.assert_called_once() # second time shouldn't download

def test_get_cube_does_will_download_if_folder_exists_and_hash_outdated(
self, mocker, fs
):
# Arrange
cube_path = "cube/1"
spy = mocker.spy(resources, "download_resource")
resources.get_cube(url, cube_path)

# Act
resources.get_cube(url, cube_path, "incorrect hash")

# Assert
assert spy.call_count == 2


class TestGetCubeParams:
def test_get_cube_params_does_not_download_if_folder_exists_and_hash_valid(
self, mocker, fs
):
# Arrange
cube_path = "cube/1"
spy = mocker.spy(resources, "download_resource")
_, exp_hash = resources.get_cube_params(url, cube_path)

# Act
resources.get_cube_params(url, cube_path, exp_hash)

# Assert
spy.assert_called_once() # second time shouldn't download

def test_get_cube_params_does_will_download_if_folder_exists_and_hash_outdated(
self, mocker, fs
def test_get_does_will_download_if_folder_exists_and_hash_outdated(
self, mocker, fs, method
):
# Arrange
cube_path = "cube/1"
spy = mocker.spy(resources, "download_resource")
resources.get_cube_params(url, cube_path)
method(url, cube_path)

# Act
resources.get_cube_params(url, cube_path, "incorrect hash")
method(url, cube_path, "incorrect hash")

# Assert
assert spy.call_count == 2

0 comments on commit 8767d0b

Please sign in to comment.