Skip to content

Commit

Permalink
Fixed grammar in logging for students subcommand, by Piotr
Browse files Browse the repository at this point in the history
  • Loading branch information
caseneuve committed Aug 11, 2023
1 parent da6c5ed commit 4a4d15c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 5 additions & 2 deletions pythonanywhere/students.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def get(self):
result = self.api.get()
student_usernames = [student["username"] for student in result["students"]]
count = len(student_usernames)
msg = f"You have {count} students!" if count else "Currently you don't have any students."
if count:
msg = f"You have {count} student{'s' if count > 1 else ''}!"
else:
msg = "Currently you don't have any students."
logger.info(snakesay(msg))
return student_usernames
except Exception as e:
Expand All @@ -49,7 +52,7 @@ def delete(self, username):

try:
self.api.delete(username)
logger.info(snakesay(f"{username!r} removed from the students list!"))
logger.info(snakesay(f"{username!r} removed from the list of students!"))
return True
except Exception as e:
logger.warning(snakesay(str(e)))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="pythonanywhere",
version="0.12.0",
version="0.12.1",
description="PythonAnywhere helper tools for users",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
17 changes: 17 additions & 0 deletions tests/test_students.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ 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):
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"}]
}

Students().get()

first_log, second_log = caplog.records
assert "students!" in first_log.message
assert "student!" in second_log.message

@pytest.mark.students
class TestStudentsDelete:
Expand Down

0 comments on commit 4a4d15c

Please sign in to comment.