-
Notifications
You must be signed in to change notification settings - Fork 35
Create test_create_profile.py #2250
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file. | |
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
## [3.12.11] - 2025-03-22 13:20:22 | ||
|
||
### Added | ||
|
||
- Create test_create_profile | ||
|
||
## [3.12.10] - 2025-03-10 12:55:10 | ||
|
||
### Changed | ||
|
||
- Update PolicyEngine US to 1.208.0 | ||
|
||
## [3.12.9] - 2025-03-05 15:56:31 | ||
|
||
|
@@ -5367,6 +5378,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 | |
|
||
|
||
|
||
[3.12.10]: https://github.com/PolicyEngine/policyengine-api/compare/3.12.9...3.12.10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue, blocking: This code should be removed This is the same as above |
||
[3.12.9]: https://github.com/PolicyEngine/policyengine-api/compare/3.12.8...3.12.9 | ||
[3.12.8]: https://github.com/PolicyEngine/policyengine-api/compare/3.12.7...3.12.8 | ||
[3.12.7]: https://github.com/PolicyEngine/policyengine-api/compare/3.12.6...3.12.7 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4471,3 +4471,8 @@ | |
changed: | ||
- Update PolicyEngine US to 1.207.0 | ||
date: 2025-03-05 15:56:31 | ||
- bump: patch | ||
changes: | ||
changed: | ||
- Update PolicyEngine US to 1.208.0 | ||
date: 2025-03-10 12:55:10 | ||
Comment on lines
+4474
to
+4478
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue, blocking: This code should be added to The entry will automatically be added to |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
POST = "POST" | ||
UPDATE = "UPDATE" | ||
LIST = "LIST" | ||
VERSION = "3.12.9" | ||
VERSION = "3.12.10" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue, blocking: This code should not be updated This will be updated automatically as part of the merge process and should not be modified |
||
COUNTRIES = ("uk", "us", "ca", "ng", "il") | ||
COUNTRY_PACKAGE_NAMES = ( | ||
"policyengine_uk", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,8 @@ | |
"policyengine-ng==0.5.1", | ||
"policyengine-il==0.1.0", | ||
"policyengine_uk==2.22.0", | ||
"policyengine_us==1.207.0", | ||
"policyengine_core>=3.12.9", | ||
"policyengine_us==1.208.0", | ||
"policyengine_core>=3.12.10", | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Did you modify this? If not and all of my comments seem unexpected (I'm starting to suspect they are), I'd recommend switching to your local master branch, running There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It likely has to do with my local branch. Sorry about that. |
||
"pydantic", | ||
"pymysql", | ||
"redis", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pytest | ||
import unittest.mock as mock | ||
from policyengine_api.services.user_service import UserService | ||
|
||
user_service = UserService() | ||
|
||
|
||
class TestCreateProfile: | ||
def test_create_profile_valid(self, test_db): | ||
auth0_id = "test_auth0_id" | ||
primary_country = "us" | ||
username = "test_username" | ||
user_since = 2025 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue, blocking: This needs to be a SQL JavaScript represents time as the number of seconds to have elapsed since Jan. 1, 1970 (the Unix epoch). E.g., at the time of me posting this, the time is now 1743548347780. I'd use a number more like that to represent |
||
|
||
def fetch_created_record(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, non-blocking: I'd probably not write this as a separate function and just fetch the record back out using this code |
||
return test_db.query( | ||
"SELECT * FROM user_profiles WHERE auth0_id = ?", (auth0_id,) | ||
).fetchone() | ||
|
||
result = user_service.create_profile( | ||
primary_country=primary_country, | ||
auth0_id=auth0_id, | ||
username=username, | ||
user_since=user_since, | ||
) | ||
|
||
assert result[0] is True | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment: If fetching directly from the db, this line would be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: What does this line do now? |
||
|
||
user_record = fetch_created_record() | ||
assert user_record is not None | ||
assert ( | ||
user_record["auth0_id"] == auth0_id | ||
) # Ensure column name is correct | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: What is the purpose of this comment? |
||
assert user_record["primary_country"] == primary_country | ||
assert user_record["username"] == username | ||
assert user_record["user_since"] == user_since | ||
|
||
def test_create_profile_invalid_argument(self, test_db): | ||
primary_country = "us" | ||
username = "test_username" | ||
user_since = 2025 | ||
with pytest.raises( | ||
Exception, | ||
match=r"UserService.create_profile\(\) missing 1 required positional argument: 'auth0_id'", | ||
): | ||
user_service.create_profile( | ||
primary_country=primary_country, | ||
username=username, | ||
user_since=user_since, | ||
) | ||
|
||
def test_create_profile_duplicate(self, test_db): | ||
auth0_id = "test_auth0_id" | ||
primary_country = "us" | ||
username = "test_username" | ||
user_since = 2025 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue, blocking: Here, too, this should be a BIGINT value |
||
result1 = user_service.create_profile( | ||
primary_country=primary_country, | ||
auth0_id=auth0_id, | ||
username=username, | ||
user_since=user_since, | ||
) | ||
|
||
result2 = user_service.create_profile( | ||
primary_country=primary_country, | ||
auth0_id=auth0_id, | ||
username=username, | ||
user_since=user_since, | ||
) | ||
assert result2[0] == False | ||
anth-volk marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
issue, blocking: Code should not be added to
CHANGELOG.md
; please removeApologies if the instructions in our PR chat were unclear, but only
changelog_entry.yaml
should be modified when submitting a PR. The information from this file will automatically be added toCHANGELOG.md
.