Skip to content

Commit

Permalink
Test refactored, by Piotr
Browse files Browse the repository at this point in the history
  • Loading branch information
caseneuve committed Aug 11, 2023
1 parent dc3ca1d commit 5b5cfaf
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions tests/test_students.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import pytest
from unittest.mock import call

Expand Down Expand Up @@ -36,25 +35,22 @@ def test_returns_empty_list_when_no_usernames_found_in_api_response(self, mocker
assert mock_students_api_get.called
assert result == []

def test_uses_correct_grammar_in_log_messages(self, mocker, caplog):
caplog.set_level(logging.INFO)

@pytest.mark.parametrize(
"api_response,expected_wording",
[
({"students": [{"username": "one"}, {"username": "two"}]}, "You have 2 students!"),
({"students": [{"username": "one"}]}, "You have 1 student!"),
]
)
def test_uses_correct_grammar_in_log_messages(
self, mocker, api_response, expected_wording, caplog
):
mock_students_api_get = mocker.patch("pythonanywhere.api.students_api.StudentsAPI.get")
mock_students_api_get.return_value = {
"students": [{"username": "one"}, {"username": "two"}]
}

Students().get()

mock_students_api_get.return_value = {
"students": [{"username": "one"}]
}
mock_students_api_get.return_value = api_response

Students().get()

first_log, second_log = caplog.records
assert "students!" in first_log.message, "Should be plural"
assert "student!" in second_log.message, "Should be singular"
assert expected_wording in caplog.text


@pytest.mark.students
Expand Down

0 comments on commit 5b5cfaf

Please sign in to comment.