Skip to content

Commit 4a4d15c

Browse files
committed
Fixed grammar in logging for students subcommand, by Piotr
1 parent da6c5ed commit 4a4d15c

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

pythonanywhere/students.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def get(self):
3535
result = self.api.get()
3636
student_usernames = [student["username"] for student in result["students"]]
3737
count = len(student_usernames)
38-
msg = f"You have {count} students!" if count else "Currently you don't have any students."
38+
if count:
39+
msg = f"You have {count} student{'s' if count > 1 else ''}!"
40+
else:
41+
msg = "Currently you don't have any students."
3942
logger.info(snakesay(msg))
4043
return student_usernames
4144
except Exception as e:
@@ -49,7 +52,7 @@ def delete(self, username):
4952

5053
try:
5154
self.api.delete(username)
52-
logger.info(snakesay(f"{username!r} removed from the students list!"))
55+
logger.info(snakesay(f"{username!r} removed from the list of students!"))
5356
return True
5457
except Exception as e:
5558
logger.warning(snakesay(str(e)))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
setup(
1111
name="pythonanywhere",
12-
version="0.12.0",
12+
version="0.12.1",
1313
description="PythonAnywhere helper tools for users",
1414
long_description=long_description,
1515
long_description_content_type="text/markdown",

tests/test_students.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ def test_returns_empty_list_when_no_usernames_found_in_api_response(self, mocker
3535
assert mock_students_api_get.called
3636
assert result == []
3737

38+
def test_uses_correct_grammar_in_log_messages(self, mocker, caplog):
39+
mock_students_api_get = mocker.patch("pythonanywhere.api.students_api.StudentsAPI.get")
40+
mock_students_api_get.return_value = {
41+
"students": [{"username": "one"}, {"username": "two"}]
42+
}
43+
44+
Students().get()
45+
46+
mock_students_api_get.return_value = {
47+
"students": [{"username": "one"}]
48+
}
49+
50+
Students().get()
51+
52+
first_log, second_log = caplog.records
53+
assert "students!" in first_log.message
54+
assert "student!" in second_log.message
3855

3956
@pytest.mark.students
4057
class TestStudentsDelete:

0 commit comments

Comments
 (0)