Skip to content

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +7 to +17
Copy link
Collaborator

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 remove

Apologies 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 to CHANGELOG.md.


## [3.12.9] - 2025-03-05 15:56:31

Expand Down Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down
5 changes: 5 additions & 0 deletions changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: This code should be added to changelog_entry.yaml, not changelog.yaml

The entry will automatically be added to changelog_entry.yaml as part of the GitHub Actions scripts and should not be included here.

2 changes: 1 addition & 1 deletion policyengine_api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
POST = "POST"
UPDATE = "UPDATE"
LIST = "LIST"
VERSION = "3.12.9"
VERSION = "3.12.10"
Copy link
Collaborator

Choose a reason for hiding this comment

The 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",
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 git pull origin master, then switching back to your feature branch and running git rebase master to fix this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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",
Expand Down
70 changes: 70 additions & 0 deletions tests/unit/services/test_create_profile.py
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue, blocking: This needs to be a SQL BIGINT value corresponding to JavaScript's internal Date.now() method

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 user_since.


def fetch_created_record():
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment: If fetching directly from the db, this line would be removed

Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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