-
Notifications
You must be signed in to change notification settings - Fork 19
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
DESENG-436: MET - Rewrite unit tests #2358
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #2358 +/- ##
==========================================
- Coverage 68.56% 67.84% -0.72%
==========================================
Files 472 526 +54
Lines 15593 16828 +1235
Branches 1193 1230 +37
==========================================
+ Hits 10691 11417 +726
- Misses 4693 5185 +492
- Partials 209 226 +17
Flags with carried forward coverage won't be shown. Click here to find out more.
|
bd87b91
to
8cee8a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! There's not much to quibble with but I am curious about a few things. If you could please answer my questions before proceeding, I'd appreciate it
@@ -124,6 +124,8 @@ DATABASE_TEST_NAME= | |||
DATABASE_TEST_HOST= | |||
DATABASE_TEST_PORT= | |||
|
|||
KEYCLOAK_TEST_BASE_URL="http://localhost:8081" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does this mean one needs to run an instance of keycloak locally just to be able to test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to run a separate instance of Keycloak. The test utilizes a Docker Compose file, and the Keycloak instance is automatically set up when executing the pytest command locally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay so if I'm understanding: a limited, temporary instance of keycloak is spun up only for testing?
Role.EDIT_ENGAGEMENT.value), engagement_id=eng_id) | ||
|
||
@staticmethod | ||
def _update_widget_timeline(widget_timeline: WidgetTimelineModel, timeline_data: dict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was the update method for timelines moved to the service from the model?
I've noticed a pattern in this app where models sometimes contain all CRUD methods and sometimes contain only some of them, with the service taking over. Do you happen to know the reason for this? In my mind, we'd strive to have all method handlers in the same location (perhaps the model). If there's a good reason for this that I'm missing, I'd be curious to hear it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have intentionally designed our models to be minimalist, focusing on retrieving requested data. Not all models support full CRUD operations; for instance, tables like submissions are restricted from updates, and deletion is limited, typically reserved for entities like widgets. All business logic is centralized in the service layer.
Moreover the logic in timeline was causing a cyclic dependency because we had the timeline event service being imported back to the model so I had to move that logic to the service.
time = event.get('time'), | ||
position = event.get('position'), | ||
status = event.get('status'), | ||
widget_id=widget_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the linter ask for the removal of these spaces, is there a rule associated with this relevant to classes? I personally prefer when they're spaced out - to me that's more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the linter suggested removing these spaces. It follows a Python style guide that recommends no spaces around the equal sign for keyword arguments.
@@ -39,9 +39,11 @@ | |||
|
|||
|
|||
@pytest.mark.parametrize('survey_info', [TestSurveyInfo.survey1]) | |||
def test_create_survey(client, jwt, session, survey_info): # pylint:disable=unused-argument | |||
def test_create_survey(client, jwt, session, survey_info, | |||
setup_admin_user_and_claims): # pylint:disable=unused-argument |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know if we need to keep the unused argument around instead of adding a rule to ignore it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've included the session argument primarily to satisfy the requirement of the testing framework. Although our code doesn't directly utilize the session within its logic, it's included to facilitate potential database operations that might be required during the test execution. Pylint is complaining about this argument and so we had to add this rule.
}); | ||
|
||
test('Can move to links tab', async () => { | ||
test('Can move to additional details tab', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -145,7 +145,7 @@ describe('Engagement form page tests', () => { | |||
|
|||
await waitFor(() => { | |||
expect(screen.getByDisplayValue('Test Engagement')).toBeInTheDocument(); | |||
expect(container.querySelector('span.MuiSkeleton-root')).toBeNull(); | |||
expect(container.querySelector('span.MuiSkeleton-root')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: what does calling expect
without a matcher function checks for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its just checking if the element exists.
Co-authored-by: Baelx <[email protected]>
Co-authored-by: Baelx <[email protected]>
Quality Gate passedThe SonarCloud Quality Gate passed, but some issues were introduced. 35 New issues |
* DESENG-436: MET - Rewrite unit tests (#1) Co-authored-by: Baelx <[email protected]> * Update met-api/tests/unit/api/test_engagement.py Co-authored-by: Baelx <[email protected]> --------- Co-authored-by: Baelx <[email protected]>
Issue #: https://apps.itsm.gov.bc.ca/jira/browse/DESENG-436
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the met-public license (Apache 2.0).