Skip to content

Commit

Permalink
Merge pull request #8 from City-of-Turku/feature/add-gender-to-profile
Browse files Browse the repository at this point in the history
Feature/add gender to profile
  • Loading branch information
juuso-j authored Feb 9, 2024
2 parents b096413 + c886009 commit 5a20422
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions account/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Meta:
"optional_postal_code",
"is_filled_for_fun",
"result_can_be_used",
"gender",
]


Expand Down
23 changes: 23 additions & 0 deletions account/migrations/0011_profile_gender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.1.10 on 2024-02-08 12:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("account", "0010_rename_age_profile_year_of_birth"),
]

operations = [
migrations.AddField(
model_name="profile",
name="gender",
field=models.CharField(
blank=True,
choices=[("M", "Male"), ("F", "Female"), ("X", "X")],
max_length=2,
null=True,
),
),
]
8 changes: 8 additions & 0 deletions account/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Meta:


class Profile(models.Model):
GENDER_OPTIONS = [
("M", "Male"),
("F", "Female"),
("X", "X"),
]
user = models.OneToOneField(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="profile"
)
Expand All @@ -42,6 +47,9 @@ class Profile(models.Model):
optional_postal_code = models.CharField(max_length=10, null=True)
is_filled_for_fun = models.BooleanField(default=False)
result_can_be_used = models.BooleanField(default=True)
gender = models.CharField(
max_length=2, choices=GENDER_OPTIONS, null=True, blank=True
)

def __str__(self):
return self.user.username
Expand Down
9 changes: 9 additions & 0 deletions account/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ def test_profile_created(api_client):
assert user.profile.postal_code is None


@pytest.mark.django_db
def test_profile_patch_geneder(api_client_authenticated, users, profiles):
user = users.get(username="test1")
url = reverse("account:profiles-detail", args=[user.id])
patch(api_client_authenticated, url, {"gender": "X"})
user.refresh_from_db()
assert user.profile.gender == "X"


@pytest.mark.django_db
def test_profile_patch_postal_code(api_client_authenticated, users, profiles):
user = users.get(username="test1")
Expand Down

0 comments on commit 5a20422

Please sign in to comment.