FAQ | This is a LIVE service | Changelog

Skip to content
Commits on Source (8)
# Changelog
## [0.4.1](https://gitlab.developers.cam.ac.uk/uis/devops/iam/activate-account/api/compare/0.4.0...0.4.1) (2024-11-11)
### Bug Fixes
* enhance AccountFactory attributes and update README.md ([a521545](https://gitlab.developers.cam.ac.uk/uis/devops/iam/activate-account/api/commit/a5215458819020d860a84be7cbfaa9b2707f091b))
## [0.4.0](https://gitlab.developers.cam.ac.uk/uis/devops/iam/activate-account/api/compare/0.3.1...0.4.0) (2024-11-01)
### Features
......
# Activate Account
**THIS README NEEDS COMPLETING**
This repository contains [...] which does [...] in order to [...].
This repository hosts the API for the Activate Account service, which manages the signup and account activation
processes as part of the transition away from the legacy Raven Login system. The API enables integration with a new web
application designed to streamline user registration and initial account setup.
## Documentation
......
import random
import factory
from django.utils import timezone
from .models import Account, AccountDetails
......@@ -8,19 +9,54 @@ class AccountFactory(factory.django.DjangoModelFactory):
class Meta:
model = Account
crsid = factory.Faker("bothify", text="??####")
date_of_birth = factory.Faker("date_object", end_datetime=timezone.now())
date_of_birth = factory.Faker("date_between", start_date="-100y", end_date="-10y")
last_name = factory.Faker("last_name")
code = factory.Faker("pystr", min_chars=6, max_chars=10)
@factory.lazy_attribute
def crsid(self):
# Choose 'abcdejmnrst' as the first letter for CRSid because these are the most
# commonly used initials in names, which helps minimize the risk of infinite loops
# in the name matching process within the AccountDetailsFactory.
return (
f"{random.choice('abcdejmnrst')}{self.last_name[:1].lower()}"
f"{random.randint(199, 99999)}"
)
@factory.lazy_attribute
def code(self):
code_type = random.choice(["staff", "postgraduate", "pgce", "undergraduate"])
faker = factory.Faker._get_faker()
if code_type == "staff":
return faker.bothify("???###?##").lower()
elif code_type == "postgraduate":
return faker.numerify(text="3########")
elif code_type == "pgce":
return faker.numerify(text="#######")
elif code_type == "undergraduate":
return faker.numerify(text="##########")
class AccountDetailsFactory(factory.django.DjangoModelFactory):
class Meta:
model = AccountDetails
name = factory.Faker("name")
account = factory.SubFactory(AccountFactory)
college = factory.Faker("company")
affiliation = factory.Faker("company")
terms_accepted = False
account = factory.SubFactory(AccountFactory)
@factory.lazy_attribute
def name(self):
# Generate first name based on a letter from crsid
faker = factory.Faker._get_faker()
first_letter = self.account.crsid[0].upper()
first_name = faker.first_name()
attempts = 0
max_attempts = 20
while not first_name.startswith(first_letter) and attempts < max_attempts:
first_name = faker.first_name()
attempts += 1
last_name = self.account.last_name
return f"{first_name} {last_name}"
[tool.poetry]
name = "activate_account"
version = "0.4.0"
version = "0.4.1"
description = ""
authors = [ ]
readme = "README.md"
......