Skip to content

Commit 4afa982

Browse files
📝 Add docstrings to test_mentorship_backend
Docstrings generation was requested by @kart-u. * #3179 (comment) The following files were modified: * `backend/apps/mentorship/api/internal/nodes/mentee.py` * `backend/tests/apps/mentorship/api/internal/nodes/test_api_internal_mentor.py` * `backend/tests/apps/mentorship/api/internal/nodes/test_api_internal_module.py` * `backend/tests/apps/mentorship/api/internal/nodes/test_api_internal_program.py` * `backend/tests/apps/mentorship/api/internal/queries/test_api_queries_mentorship.py` * `backend/tests/apps/mentorship/api/internal/queries/test_api_queries_program.py` * `backend/tests/apps/mentorship/management/commands/test_mentorship_sync_issue_levels.py` * `backend/tests/apps/mentorship/management/commands/test_mentorship_sync_module_issues.py` * `backend/tests/apps/mentorship/management/commands/test_mentorship_update_comments.py` * `backend/tests/apps/mentorship/model/test_module.py`
1 parent 45521fb commit 4afa982

File tree

10 files changed

+2146
-2
lines changed

10 files changed

+2146
-2
lines changed

backend/apps/mentorship/api/internal/nodes/mentee.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ def resolve_avatar_url(self) -> str:
2626

2727
@strawberry.field(name="experienceLevel")
2828
def resolve_experience_level(self) -> str:
29-
"""Get the experience level of the mentee."""
30-
return self.experience_level if self.experience_level else "beginner"
29+
"""
30+
Return the mentee's experience level, defaulting to "beginner" when not set.
31+
32+
Returns:
33+
experience_level (str): The mentee's experience level, or "beginner" if the field is empty or falsy.
34+
"""
35+
return self.experience_level if self.experience_level else "beginner"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""Pytest for mentorship mentor nodes."""
2+
3+
from unittest.mock import MagicMock
4+
5+
import pytest
6+
7+
from apps.mentorship.api.internal.nodes.mentor import MentorNode
8+
9+
10+
@pytest.fixture
11+
def mock_github_user():
12+
"""
13+
Create a MagicMock that simulates a GitHub user for tests.
14+
15+
The mock has the following attributes set:
16+
- `avatar_url`: "https://example.com/mentor_avatar.jpg"
17+
- `name`: "Mentor Name"
18+
- `login`: "mentorlogin"
19+
20+
Returns:
21+
MagicMock: A mock object representing a GitHub user with the above attributes.
22+
"""
23+
mock = MagicMock()
24+
mock.avatar_url = "https://example.com/mentor_avatar.jpg"
25+
mock.name = "Mentor Name"
26+
mock.login = "mentorlogin"
27+
return mock
28+
29+
30+
@pytest.fixture
31+
def mock_mentor_node(mock_github_user):
32+
"""
33+
Create a MentorNode with its `github_user` set to the provided mock.
34+
35+
Parameters:
36+
mock_github_user: Mocked GitHub user object (e.g., MagicMock) providing attributes like `avatar_url`, `name`, and `login`.
37+
38+
Returns:
39+
MentorNode: A MentorNode with id `"1"` and `github_user` assigned to the provided mock.
40+
"""
41+
mentor_node = MentorNode(id="1")
42+
mentor_node.github_user = mock_github_user
43+
return mentor_node
44+
45+
46+
@pytest.fixture
47+
def mock_mentor_node_no_github_user():
48+
"""
49+
Create a MentorNode test fixture with no associated GitHub user.
50+
51+
Returns:
52+
MentorNode: a MentorNode with id "2" and github_user set to None.
53+
"""
54+
mentor_node = MentorNode(id="2")
55+
mentor_node.github_user = None
56+
return mentor_node
57+
58+
59+
def test_mentor_node_id(mock_mentor_node):
60+
"""Test that MentorNode id is correctly assigned."""
61+
assert str(mock_mentor_node.id) == "1"
62+
63+
64+
def test_mentor_node_avatar_url(mock_mentor_node):
65+
"""Test the avatar_url field resolver."""
66+
assert mock_mentor_node.avatar_url() == "https://example.com/mentor_avatar.jpg"
67+
68+
69+
def test_mentor_node_avatar_url_no_github_user(mock_mentor_node_no_github_user):
70+
"""Test avatar_url when no github_user is associated."""
71+
assert mock_mentor_node_no_github_user.avatar_url() == ""
72+
73+
74+
def test_mentor_node_name(mock_mentor_node):
75+
"""Test the name field resolver."""
76+
assert mock_mentor_node.name() == "Mentor Name"
77+
78+
79+
def test_mentor_node_name_no_github_user(mock_mentor_node_no_github_user):
80+
"""Test name when no github_user is associated."""
81+
assert mock_mentor_node_no_github_user.name() == ""
82+
83+
84+
def test_mentor_node_login(mock_mentor_node):
85+
"""Test the login field resolver."""
86+
assert mock_mentor_node.login() == "mentorlogin"
87+
88+
89+
def test_mentor_node_login_no_github_user(mock_mentor_node_no_github_user):
90+
"""Test login when no github_user is associated."""
91+
assert mock_mentor_node_no_github_user.login() == ""

0 commit comments

Comments
 (0)