-
-
Notifications
You must be signed in to change notification settings - Fork 423
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
Draft
kart-u
wants to merge
33
commits into
OWASP:main
Choose a base branch
from
kart-u:test_mentorship_backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
9e7c886
update:model,management
kart-u 13aae2b
update:model
kart-u 13373c7
update:cleaned
kart-u 5d46f78
update:cleaned
kart-u 7af67a1
initial test added needed corrections
kart-u 6b3bedf
some more test
kart-u 7bb0862
test added
kart-u 1946fe9
code rabbit
kart-u bb976f8
code rabbit
kart-u 0162d52
correction
kart-u e6674f9
code-rabbit
kart-u ad141a2
code-rabbit
kart-u cade9d3
code-rabbit
kart-u 36883d5
code-rabbit
kart-u 7ed4e28
sonar-issue
kart-u 0636c18
cspell_check
kart-u 06c73bd
lint/format
kart-u 47f1934
lint/format
kart-u ae971a8
lint/format
kart-u d925133
lint/format
kart-u 950ecf0
lint/format
kart-u 66852aa
lint/format
kart-u 65ca306
final lint/format
kart-u b8a3c02
cleaned code
kart-u 9f7cf69
lint/format code-rabbit
kart-u 359147c
lint/format code-rabbit
kart-u 52d4306
lint/format code-rabbit
kart-u 7410827
lint/format
kart-u 5e1a7c9
lint/format
kart-u 650b9a2
lint/format
kart-u f28b256
code-rabbit
kart-u 178e90b
code-rabbit
kart-u ed77a1f
lint/format
kart-u 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
Empty file.
Empty file.
Empty file.
Empty file.
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.