|
1 | | -import logging |
2 | 1 | import pytest |
3 | 2 | from unittest.mock import call |
4 | 3 |
|
@@ -36,25 +35,22 @@ def test_returns_empty_list_when_no_usernames_found_in_api_response(self, mocker |
36 | 35 | assert mock_students_api_get.called |
37 | 36 | assert result == [] |
38 | 37 |
|
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 | + ): |
42 | 48 | 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 |
52 | 50 |
|
53 | 51 | Students().get() |
54 | 52 |
|
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 |
58 | 54 |
|
59 | 55 |
|
60 | 56 | @pytest.mark.students |
|
0 commit comments