Skip to content

Created test_create_profile.py #2505

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- bump: patch
changes:
changed:
- Created test_create_profile.py to test the create_profile function.
date: 2025-05-27 07:09:00
64 changes: 64 additions & 0 deletions tests/unit/services/test_create_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest
import unittest.mock as mock
import time
from policyengine_api.services.user_service import UserService

userService = UserService()


class TestCreateProfile:

def test_create_profile_valid(self):
auth0_id = "test-auth-id"
primary_country = "United States"
username = "test_username"
user_since = int(time.time() * 1000)

result = userService.create_profile(
primary_country=primary_country,
auth0_id=auth0_id,
username=username,
user_since=user_since,
)

assert result[0] is True
user_record = userService.get_profile(auth0_id)
assert user_record is not None
assert user_record["auth0_id"] == auth0_id
assert user_record["primary_country"] == primary_country
assert user_record["username"] == username
assert user_record["user_since"] == user_since

def test_create_profile_invalid(self):
primary_country = "United States"
username = "test_username"
user_since = int(time.time() * 1000)
with pytest.raises(
Exception,
match=r"UserService.create_profile\(\) missing 1 required positional argument: 'auth0_id'",
):
userService.create_profile(
primary_country=primary_country,
username=username,
user_since=user_since,
)

def test_create_profile_duplicate(self):
auth0_id = "test-auth-id"
primary_country = "United States"
username = "test_username"
user_since = int(time.time() * 1000)
result1 = userService.create_profile(
primary_country=primary_country,
auth0_id=auth0_id,
username=username,
user_since=user_since,
)

result2 = userService.create_profile(
primary_country=primary_country,
auth0_id=auth0_id,
username=username,
user_since=user_since,
)
assert result2[0] == False
Loading