FAQ | This is a LIVE service | Changelog

Skip to content
Commits on Source (4)
......@@ -4,6 +4,7 @@
### Features
* add account details model ([bf1cfdf](https://gitlab.developers.cam.ac.uk/uis/devops/iam/activate-account/api/commit/bf1cfdf52aa8fe263da21196f12f06cf2e7379fe))
* add session creation and return mechanism to API
## [0.2.1](https://gitlab.developers.cam.ac.uk/uis/devops/iam/activate-account/api/compare/0.2.0...0.2.1) (2024-10-28)
......
import factory
from django.utils import timezone
from .models import Account
from .models import Account, AccountDetails
class AccountFactory(factory.django.DjangoModelFactory):
......@@ -12,3 +12,14 @@ class AccountFactory(factory.django.DjangoModelFactory):
date_of_birth = factory.Faker("date_object", end_datetime=timezone.now())
last_name = factory.Faker("last_name")
code = factory.Faker("pystr", min_chars=6, max_chars=10)
class AccountDetailsFactory(factory.django.DjangoModelFactory):
class Meta:
model = AccountDetails
name = factory.Faker("name")
college = factory.Faker("company")
affiliation = factory.Faker("company")
account = factory.SubFactory(AccountFactory)
from django.core.management.base import BaseCommand
from activate_account.factories import AccountFactory
from activate_account.factories import AccountDetailsFactory
class Command(BaseCommand):
......@@ -10,6 +10,6 @@ class Command(BaseCommand):
self.stdout.write(self.style.SUCCESS("Starting to initialize mock data..."))
for _ in range(10):
AccountFactory()
AccountDetailsFactory()
self.stdout.write(self.style.SUCCESS("Successfully initialized mock data."))
# Generated by Django 4.2.14 on 2024-10-28 13:16
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("activate_account", "0001_initial"),
]
operations = [
migrations.CreateModel(
name="AccountDetails",
fields=[
(
"account",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
primary_key=True,
related_name="account_details",
serialize=False,
to="activate_account.account",
),
),
("name", models.CharField(blank=True)),
("affiliation", models.CharField(blank=True)),
("college", models.CharField(blank=True)),
],
),
]
......@@ -11,3 +11,16 @@ class Account(models.Model):
constraints = [
models.UniqueConstraint("last_name", "date_of_birth", "code", name="unique_account"),
]
class AccountDetails(models.Model):
account = models.OneToOneField(
Account, related_name="account_details", on_delete=models.CASCADE, primary_key=True
)
# These fields are taken as-is from Jackdaw, no additional special handling or constraints are
# required. They are displayed to the user for confirmation, and no further processing is
# needed. If the data from Jackdaw is the blank string this is acceptable.
name = models.CharField(blank=True)
affiliation = models.CharField(blank=True)
college = models.CharField(blank=True)
......@@ -4,6 +4,10 @@ from activate_account.models import Account
class AccountSerializer(serializers.ModelSerializer):
name = serializers.CharField(source="account_details.name", default="")
affiliation = serializers.CharField(source="account_details.affiliation", default="")
college = serializers.CharField(source="account_details.college", default="")
class Meta:
model = Account
fields = ("crsid", "last_name", "date_of_birth")
fields = ("crsid", "last_name", "date_of_birth", "name", "affiliation", "college")
......@@ -7,7 +7,7 @@ def url():
return reverse("v1alpha:account", kwargs={"version": "v1alpha1"})
def test_account_details(authenticated_api_client, account, url):
def test_account_details(authenticated_api_client, account, account_details, url):
response = authenticated_api_client.get(url)
assert response.status_code == 200
......@@ -15,4 +15,7 @@ def test_account_details(authenticated_api_client, account, url):
"crsid": account.crsid,
"last_name": account.last_name,
"date_of_birth": account.date_of_birth.strftime("%Y-%m-%d"),
"name": account_details.name,
"affiliation": account_details.affiliation,
"college": account_details.college,
}
......@@ -7,7 +7,7 @@ from django.urls import reverse
from pytest_docker_tools import container
from rest_framework.test import APIClient
from activate_account.factories import AccountFactory
from activate_account.factories import AccountDetailsFactory, AccountFactory
from authentication.constants import SESSION_GRANT_TYPE
# We only modify the database settings for the test suite if TEST_USE_EXTERNAL_DATABASE is not set
......@@ -52,6 +52,11 @@ def account(db):
return AccountFactory()
@pytest.fixture
def account_details(account):
return AccountDetailsFactory(account=account)
@pytest.fixture
def api_client():
return APIClient()
......