Skip to content

Commit

Permalink
Make assertions about mocked DOI publish calls
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmullen authored and danlamanna committed Aug 28, 2023
1 parent 92cbc8a commit 9c04073
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions isic/core/tests/test_doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

@pytest.fixture
def mock_datacite_create_doi(mocker):
mocker.patch(
"isic.core.services.collection.doi._datacite_create_doi", lambda doi: {"doi": "123456"}
)
mocker.patch("isic.core.services.collection.doi._datacite_update_doi")
yield
yield mocker.patch("isic.core.services.collection.doi._datacite_create_doi")


@pytest.fixture
def mock_datacite_update_doi(mocker):
yield mocker.patch("isic.core.services.collection.doi._datacite_update_doi")


@pytest.fixture
Expand All @@ -29,14 +30,19 @@ def staff_user_request(staff_user, mocker):

@pytest.mark.django_db
def test_collection_create_doi(
public_collection_with_public_images, staff_user, mock_datacite_create_doi
public_collection_with_public_images,
staff_user,
mock_datacite_create_doi,
mock_datacite_update_doi,
):
collection_create_doi(user=staff_user, collection=public_collection_with_public_images)

public_collection_with_public_images.refresh_from_db()
assert public_collection_with_public_images.locked
assert public_collection_with_public_images.doi
assert public_collection_with_public_images.doi.creator == staff_user
mock_datacite_create_doi.assert_called_once()
mock_datacite_update_doi.assert_called_once()


@pytest.mark.django_db
Expand All @@ -60,7 +66,10 @@ def test_doi_form_requires_no_existing_doi(public_collection, staff_user_request

@pytest.mark.django_db
def test_doi_form_creation(
public_collection_with_public_images, staff_user_request, mock_datacite_create_doi
public_collection_with_public_images,
staff_user_request,
mock_datacite_create_doi,
mock_datacite_update_doi,
):
form = CreateDoiForm(
data={},
Expand All @@ -73,6 +82,8 @@ def test_doi_form_creation(
public_collection_with_public_images.refresh_from_db()
assert public_collection_with_public_images.doi is not None
assert public_collection_with_public_images.locked
mock_datacite_create_doi.assert_called_once()
mock_datacite_update_doi.assert_called_once()


@pytest.fixture
Expand Down

0 comments on commit 9c04073

Please sign in to comment.