Skip to content

Commit 5b5cfaf

Browse files
committed
Test refactored, by Piotr
1 parent dc3ca1d commit 5b5cfaf

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

tests/test_students.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import logging
21
import pytest
32
from unittest.mock import call
43

@@ -36,25 +35,22 @@ def test_returns_empty_list_when_no_usernames_found_in_api_response(self, mocker
3635
assert mock_students_api_get.called
3736
assert result == []
3837

39-
def test_uses_correct_grammar_in_log_messages(self, mocker, caplog):
40-
caplog.set_level(logging.INFO)
41-
38+
@pytest.mark.parametrize(
39+
"api_response,expected_wording",
40+
[
41+
({"students": [{"username": "one"}, {"username": "two"}]}, "You have 2 students!"),
42+
({"students": [{"username": "one"}]}, "You have 1 student!"),
43+
]
44+
)
45+
def test_uses_correct_grammar_in_log_messages(
46+
self, mocker, api_response, expected_wording, caplog
47+
):
4248
mock_students_api_get = mocker.patch("pythonanywhere.api.students_api.StudentsAPI.get")
43-
mock_students_api_get.return_value = {
44-
"students": [{"username": "one"}, {"username": "two"}]
45-
}
46-
47-
Students().get()
48-
49-
mock_students_api_get.return_value = {
50-
"students": [{"username": "one"}]
51-
}
49+
mock_students_api_get.return_value = api_response
5250

5351
Students().get()
5452

55-
first_log, second_log = caplog.records
56-
assert "students!" in first_log.message, "Should be plural"
57-
assert "student!" in second_log.message, "Should be singular"
53+
assert expected_wording in caplog.text
5854

5955

6056
@pytest.mark.students

0 commit comments

Comments
 (0)