Skip to content

Commit

Permalink
Update/include email in processed application data (#476)
Browse files Browse the repository at this point in the history
* Add updated user.py module

* Add user to function call in processed application function call

* Modify ProcessedXApplicationData classes to include email attr

* fix pytests

---------

Co-authored-by: Albert Wang <[email protected]>
  • Loading branch information
noahk004 and waalbert authored Dec 11, 2024
1 parent 1d1ff19 commit d74224a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
4 changes: 4 additions & 0 deletions apps/api/src/models/ApplicationData.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BeforeValidator,
ConfigDict,
Discriminator,
EmailStr,
Field,
HttpUrl,
Tag,
Expand Down Expand Up @@ -122,6 +123,7 @@ class RawVolunteerApplicationData(VolunteerApplicationData):


class ProcessedHackerApplicationData(BaseApplicationData):
email: EmailStr
resume_url: Union[HttpUrl, None] = None
submission_time: datetime
reviews: list[Review] = []
Expand All @@ -134,6 +136,7 @@ def url2str(self, val: Union[HttpUrl, None]) -> Union[str, None]:


class ProcessedMentorApplicationData(BaseMentorApplicationData):
email: EmailStr
resume_url: Union[HttpUrl, None] = None
submission_time: datetime
reviews: list[Review] = []
Expand All @@ -146,6 +149,7 @@ def url2str(self, val: Union[HttpUrl, None]) -> Union[str, None]:


class ProcessedVolunteerData(BaseVolunteerApplicationData):
email: EmailStr
submission_time: datetime
reviews: list[Review] = []
friday_availability: dict[str, bool]
Expand Down
5 changes: 4 additions & 1 deletion apps/api/src/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ async def _to_processed_application_data_hackers_mentors(

return {
**raw_app_data_dump,
"email": user.email,
"resume_url": resume_url,
"submission_time": now,
}


def _to_processed_application_data_volunteers(
raw_app_data_dump: dict[str, Any],
user: User,
now: datetime,
) -> dict[str, Any]:

Expand All @@ -154,6 +156,7 @@ def _to_processed_application_data_volunteers(

return {
**raw_app_data_dump,
"email": user.email,
"submission_time": now,
}

Expand Down Expand Up @@ -220,7 +223,7 @@ async def _apply_flow(
elif raw_application_data.application_type == "Volunteer":
processed_application_data = (
ProcessedApplicationDataUnionAdapter.validate_python(
_to_processed_application_data_volunteers(raw_app_data_dump, now)
_to_processed_application_data_volunteers(raw_app_data_dump, user, now)
)
)
else:
Expand Down
3 changes: 2 additions & 1 deletion apps/api/tests/test_user_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"frq_change": "I am pkfire",
"frq_video_game": "I am pkfire",
"application_type": "Hacker",
"email": "[email protected]",
}


Expand Down Expand Up @@ -302,7 +303,7 @@ def test_application_data_is_bson_encodable() -> None:
data = EXPECTED_APPLICATION_DATA.model_copy()
data.linkedin = HttpUrl("https://linkedin.com")
encoded = bson.encode(EXPECTED_APPLICATION_DATA.model_dump())
assert len(encoded) == 378
assert len(encoded) == 404


@patch("services.mongodb_handler.retrieve_one", autospec=True)
Expand Down
3 changes: 2 additions & 1 deletion apps/api/tests/test_user_mentor_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"mentor_team_help_saq4": "",
"other_questions": "",
"application_type": "Mentor",
"email": "[email protected]",
}


Expand Down Expand Up @@ -253,7 +254,7 @@ def test_mentor_application_data_is_bson_encodable() -> None:
data = EXPECTED_APPLICATION_DATA.model_copy()
data.linkedin = HttpUrl("https://linkedin.com")
encoded = bson.encode(EXPECTED_APPLICATION_DATA.model_dump())
assert len(encoded) == 486
assert len(encoded) == 512


@patch("services.mongodb_handler.retrieve_one", autospec=True)
Expand Down
3 changes: 2 additions & 1 deletion apps/api/tests/test_user_volunteer_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"frq_utensil": "",
"other_questions": "",
"application_type": "Volunteer",
"email": USER_EMAIL,
}

SAMPLE_APPLICATION = {
Expand Down Expand Up @@ -250,7 +251,7 @@ def test_volunteer_apply_with_confirmation_email_issue_causes_500(
def test_volunteer_application_data_is_bson_encodable() -> None:
"""Test that application data model can be encoded into BSON to store in MongoDB."""
encoded = bson.encode(EXPECTED_APPLICATION_DATA.model_dump())
assert len(encoded) == 369
assert len(encoded) == 395


def test_volunteer_past_deadline_causes_403() -> None:
Expand Down

0 comments on commit d74224a

Please sign in to comment.