-
Notifications
You must be signed in to change notification settings - Fork 0
Test: Nominee endpoint #127
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
base: main
Are you sure you want to change the base?
Conversation
* refactored how the election officers are looked up * changed the Nominee put back to a patch * made election tests work with the new testing setup
| query = query.where(BlogPosts.title == title) | ||
|
|
||
| # should return the one entry with an unique title | ||
| post = await db_session.scalar(query) |
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.
nit pick: might wanna check if post is none
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.
It looks like the whole Blog module is a mess. It showed up here since I ran a formatter over everything. Blogs will be addressed in a future update.
| query = query.where(BlogPosts.post_tags in tags).where(BlogPosts.last_edited).order_by(BlogPosts.last_edited.desc()) | ||
| # .all() should return a list of all the posts |
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.
slight syntax issue for sqlalchemy. BlogPosts.post_tags in tags is invalid syntax
Correction: query = query.where(BlogPosts.post_tags.contains(tags)).order_by(BlogPosts.last_edited.desc())
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.
It looks like the whole Blog module is a mess. It showed up here since I ran a formatter over everything. Blogs will be addressed in a future update.
| detail="candidate is already registered for that position", | ||
| ) | ||
|
|
||
| registration.update_from_params(body) |
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.
might want to await this
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.
Nothing asynchronous about this function.
def update_from_params(self, params: CandidateUpdate):
update_data = params.model_dump(exclude_unset=True)
for k, v in update_data.items():
setattr(self, k, v)
The commit on line 176 should update the candidate at this point.
Based off this: https://docs.sqlalchemy.org/en/21/tutorial/orm_data_manipulation.html#updating-orm-objects-using-the-unit-of-work-pattern
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.
Sorry for the delay, just been trying to balance work and other things! Hopefully its better now.
Everything looks good. Just some minor nitpicks here and there.
| @@ -12,26 +16,105 @@ | |||
| "phone_number", | |||
| "github_username", | |||
| "google_drive_email", | |||
| "photo_url" | |||
| "photo_url", | |||
| } | |||
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.
I know this was already here from before, but maybe if it's not being used, we can get rid of 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'd be losing everything from that field when you do the database migration.
| start_date: date | None = None | ||
| end_date: date | None = None |
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.
-might want to validate the start_date and end_date but its not a big deal.
| sqlalchemy | ||
| .select(OfficerInfo) | ||
| .where(OfficerInfo.computing_id == new_officer_info.computing_id) | ||
| sqlalchemy.select(OfficerInfoDB).where(OfficerInfoDB.computing_id == new_officer_info.computing_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.
I think you might be missing the sqlalchemy import.
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.
It's on line 8
| password=DB_PASSWORD, | ||
| database="postgres", | ||
| host="sfucsss.org", # NOTE: this should point to the old sfucsss.org server (made initially by jace) | ||
| host="sfucsss.org", # NOTE: this should point to the old sfucsss.org server (made initially by jace) |
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.
I know this was here before, but maybe we shouldn't hard code this?
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 shouldn't, but this script was for migrating before we took down the old site.
|
|
||
|
|
||
| @pytest_asyncio.fixture(scope="module", loop_scope="session") | ||
| async def client() -> AsyncGenerator[Any, None]: |
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.
missing import for AsyncGenerator, Any
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.
Lines 3 and 4
| async def test__admin_delete_nominee(admin_client: AsyncClient): | ||
| response = await admin_client.delete(f"/nominee/{TEST_NOMINEE['computing_id']}") | ||
| assert response.status_code == HTTPStatus.OK | ||
| assert response.json()["success"] |
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.
This is asserting thruthiness not correctness.
Consider:
assert response.json() == {"success": True}
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.
It works fine when running the test. I changed the response to False and it correctly catches the assert. What's wrong with this?
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.
I prefer Jon's approach since it's more stable we decide to add extra fields and allow us to do more granular tests on the fields separately.
Though I would like to add is True or is False to be more explicit
assert response.json()["success"] is True
# more fields in the future rather than simple equality
assert response.json()["remaining_nominiees"], "There should be more nominees"
jbriones1
left a comment
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.
Addressed some comments
depends on #126