-
-
Notifications
You must be signed in to change notification settings - Fork 526
Improved testing for backend/app/mentorship #3179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
acb93fa
update:model,management
kart-u a548249
update:model
kart-u f5f4227
update:cleaned
kart-u 8e89cea
update:cleaned
kart-u eb11e98
initial test added needed corrections
kart-u 3a799e3
some more test
kart-u 21ce132
test added
kart-u 2d7f8df
code rabbit
kart-u 548c7e1
code rabbit
kart-u ba90eb2
correction
kart-u c12784d
code-rabbit
kart-u 97432c0
code-rabbit
kart-u 730c63d
code-rabbit
kart-u 538b746
code-rabbit
kart-u 9210d5d
sonar-issue
kart-u 71b255a
cspell_check
kart-u 490c637
lint/format
kart-u a47d3de
lint/format
kart-u 3f471d6
lint/format
kart-u 8f974cc
lint/format
kart-u c6a8e89
lint/format
kart-u e97ec17
lint/format
kart-u ed8abae
final lint/format
kart-u 96d8eca
cleaned code
kart-u fe6a3fa
lint/format code-rabbit
kart-u 54f9bde
lint/format code-rabbit
kart-u d4a0199
lint/format code-rabbit
kart-u 6c700cb
lint/format
kart-u d57a9d3
lint/format
kart-u c2b351f
lint/format
kart-u bebf831
code-rabbit
kart-u ae2981a
code-rabbit
kart-u aadfab5
lint/format
kart-u e1e1335
lint/format
kart-u 9b13ef4
resolved conflicts
kart-u 55b9264
'
kart-u 13ed6a9
lint/format
kart-u 27788ed
Merge branch 'main' into pr/kart-u/3179
arkid15r 579d4d1
Update code
arkid15r f20e8ce
Update code
arkid15r 12267be
Merge branch 'main' into pr/kart-u/3179
arkid15r f392653
Fix tests
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
backend/tests/apps/mentorship/api/internal/nodes/api_internal_enum_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| from apps.mentorship.api.internal.nodes.enum import ExperienceLevelEnum, ProgramStatusEnum | ||
| from apps.mentorship.models import Program | ||
| from apps.mentorship.models.common.experience_level import ExperienceLevel | ||
|
|
||
|
|
||
| def test_experience_level_enum_values(): | ||
| """Test that ExperienceLevelEnum maps correctly to model choices.""" | ||
| assert ExperienceLevelEnum.BEGINNER.value == ExperienceLevel.ExperienceLevelChoices.BEGINNER | ||
| assert ( | ||
| ExperienceLevelEnum.INTERMEDIATE.value | ||
| == ExperienceLevel.ExperienceLevelChoices.INTERMEDIATE | ||
| ) | ||
| assert ExperienceLevelEnum.ADVANCED.value == ExperienceLevel.ExperienceLevelChoices.ADVANCED | ||
| assert ExperienceLevelEnum.EXPERT.value == ExperienceLevel.ExperienceLevelChoices.EXPERT | ||
|
|
||
|
|
||
| def test_program_status_enum_values(): | ||
| """Test that ProgramStatusEnum maps correctly to model choices.""" | ||
| assert ProgramStatusEnum.DRAFT.value == Program.ProgramStatus.DRAFT | ||
| assert ProgramStatusEnum.PUBLISHED.value == Program.ProgramStatus.PUBLISHED | ||
| assert ProgramStatusEnum.COMPLETED.value == Program.ProgramStatus.COMPLETED |
56 changes: 56 additions & 0 deletions
56
backend/tests/apps/mentorship/api/internal/nodes/api_internal_mentee_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import pytest | ||
|
|
||
| from apps.mentorship.api.internal.nodes.enum import ExperienceLevelEnum | ||
| from apps.mentorship.api.internal.nodes.mentee import MenteeNode | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_mentee_node(): | ||
| """Fixture for a mock MenteeNode instance.""" | ||
| return MenteeNode( | ||
| id="1", | ||
| login="test_mentee", | ||
| name="Test Mentee", | ||
| avatar_url="https://example.com/avatar.jpg", | ||
| bio="A test mentee", | ||
| experience_level=ExperienceLevelEnum.BEGINNER, | ||
| domains=["python"], | ||
| tags=["backend"], | ||
| ) | ||
|
|
||
|
|
||
| def test_mentee_node_fields(mock_mentee_node): | ||
| """Test that MenteeNode fields are correctly assigned.""" | ||
| assert mock_mentee_node.id == "1" | ||
| assert mock_mentee_node.login == "test_mentee" | ||
| assert mock_mentee_node.name == "Test Mentee" | ||
| assert mock_mentee_node.avatar_url == "https://example.com/avatar.jpg" | ||
| assert mock_mentee_node.bio == "A test mentee" | ||
| assert mock_mentee_node.experience_level == ExperienceLevelEnum.BEGINNER | ||
| assert mock_mentee_node.domains == ["python"] | ||
| assert mock_mentee_node.tags == ["backend"] | ||
|
|
||
|
|
||
| def test_mentee_node_resolve_avatar_url(mock_mentee_node): | ||
| """Test the resolve_avatar_url method.""" | ||
| assert mock_mentee_node.resolve_avatar_url() == "https://example.com/avatar.jpg" | ||
|
|
||
|
|
||
| def test_mentee_node_resolve_experience_level(mock_mentee_node): | ||
| """Test the resolve_experience_level method.""" | ||
| assert mock_mentee_node.resolve_experience_level() == ExperienceLevelEnum.BEGINNER | ||
|
|
||
|
|
||
| def test_mentee_node_resolve_experience_level_none(): | ||
| """Test the resolve_experience_level method when experience_level is None.""" | ||
| mentee_node_no_exp = MenteeNode( | ||
| id="2", | ||
| login="no_exp_mentee", | ||
| name="No Experience Mentee", | ||
| avatar_url="https://example.com/noexp.jpg", | ||
| bio=None, | ||
| experience_level=None, # type: ignore[assignment] | ||
| domains=None, | ||
| tags=None, | ||
| ) | ||
| assert mentee_node_no_exp.resolve_experience_level() == "beginner" | ||
66 changes: 66 additions & 0 deletions
66
backend/tests/apps/mentorship/api/internal/nodes/api_internal_mentor_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from apps.mentorship.api.internal.nodes.mentor import MentorNode | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_github_user(): | ||
| """Fixture for a mock GithubUser.""" | ||
| mock = MagicMock() | ||
| mock.avatar_url = "https://example.com/mentor_avatar.jpg" | ||
| mock.name = "Mentor Name" | ||
| mock.login = "mentor_login" | ||
| return mock | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_mentor_node(mock_github_user): | ||
| """Fixture for a mock MentorNode instance.""" | ||
| mentor_node = MentorNode(id="1") | ||
| mentor_node.github_user = mock_github_user | ||
| return mentor_node | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_mentor_node_no_github_user(): | ||
| """Fixture for a mock MentorNode instance without a GitHub user.""" | ||
| mentor_node = MentorNode(id="2") | ||
| mentor_node.github_user = None | ||
| return mentor_node | ||
|
|
||
|
|
||
| def test_mentor_node_id(mock_mentor_node): | ||
| """Test that MentorNode id is correctly assigned.""" | ||
| assert str(mock_mentor_node.id) == "1" | ||
|
|
||
|
|
||
| def test_mentor_node_avatar_url(mock_mentor_node): | ||
| """Test the avatar_url field resolver.""" | ||
| assert mock_mentor_node.avatar_url() == "https://example.com/mentor_avatar.jpg" | ||
|
|
||
|
|
||
| def test_mentor_node_avatar_url_no_github_user(mock_mentor_node_no_github_user): | ||
| """Test avatar_url when no github_user is associated.""" | ||
| assert mock_mentor_node_no_github_user.avatar_url() == "" | ||
|
|
||
|
|
||
| def test_mentor_node_name(mock_mentor_node): | ||
| """Test the name field resolver.""" | ||
| assert mock_mentor_node.name() == "Mentor Name" | ||
|
|
||
|
|
||
| def test_mentor_node_name_no_github_user(mock_mentor_node_no_github_user): | ||
| """Test name when no github_user is associated.""" | ||
| assert mock_mentor_node_no_github_user.name() == "" | ||
|
|
||
|
|
||
| def test_mentor_node_login(mock_mentor_node): | ||
| """Test the login field resolver.""" | ||
| assert mock_mentor_node.login() == "mentor_login" | ||
|
|
||
|
|
||
| def test_mentor_node_login_no_github_user(mock_mentor_node_no_github_user): | ||
| """Test login when no github_user is associated.""" | ||
| assert mock_mentor_node_no_github_user.login() == "" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.