Skip to content

Commit

Permalink
test: create_or_update_article fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ErnestaP committed Jan 26, 2024
1 parent 17b8205 commit 71fbc0a
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions tests/units/common/test_common_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,31 @@ def test_create_article():
"BACKEND_TOKEN": "CHANGE_ME",
},
)
def test_update_article():
@pytest.fixture
def mock_response_create_fail():
response = mock.Mock()
response.raise_for_status.side_effect = requests.HTTPError("Create failed")
response.json.return_value = {"message": "Create failed", "article_id": "81153"}
return response


@pytest.fixture
def mock_response_update_success():
"""Mock response for successful update request."""
response = mock.Mock()
response.raise_for_status.return_value = None
response.json.return_value = {"title": "New title", "id": "81153"}
return response


@mock.patch("requests.post")
@mock.patch("requests.put")
def test_update_article(
mock_put, mock_post, mock_response_create_fail, mock_response_update_success
):
mock_post.return_value = mock_response_create_fail
mock_put.return_value = mock_response_update_success

data = {
"_oai": {
"updated": "2023-11-14T00:15:03Z",
Expand Down Expand Up @@ -192,16 +216,14 @@ def test_update_article():
],
"imprints": [{"date": "2023-10-27", "publisher": "Hindawi"}],
}
article = create_or_update_article(data)
assert (
article["title"]
== "Theoretical and Experimental Challenges in the Measurement of Neutrino Mass"
)
assert article["id"] == 81153

data["titles"][0]["title"] = "New title"
article = create_or_update_article(data)

assert article["title"] == "New title"
assert article["id"] == "81153"

mock_post.assert_called_once()
mock_put.assert_called_once()


@pytest.mark.vcr
Expand Down

0 comments on commit 71fbc0a

Please sign in to comment.