Skip to content

Commit

Permalink
Merge branch 'main' into bulk_transfer_students
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Feb 29, 2024
2 parents 57df6a6 + a125976 commit 874b428
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 13 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

<!--next-version-placeholder-->

## v0.14.4 (2024-02-29)

### Fix

* Transfer class ([#95](https://github.com/ocadotechnology/codeforlife-package-python/issues/95)) ([`a3a11b5`](https://github.com/ocadotechnology/codeforlife-package-python/commit/a3a11b5b40ded1707bc0017e5ce136983e3fed7e))

## v0.14.3 (2024-02-29)

### Fix

* Update class fixtures for class join requests ([#99](https://github.com/ocadotechnology/codeforlife-package-python/issues/99)) ([`76d2635`](https://github.com/ocadotechnology/codeforlife-package-python/commit/76d26359f51189b72bd1965bdc0e42e894d17b38))

## v0.14.2 (2024-02-28)

### Fix

* Assertion helpers ([#98](https://github.com/ocadotechnology/codeforlife-package-python/issues/98)) ([`a347bd3`](https://github.com/ocadotechnology/codeforlife-package-python/commit/a347bd3d74fea6c891855603e5f75f1bdd5b8554))

## v0.14.1 (2024-02-26)

### Fix

* Generate username helper ([#94](https://github.com/ocadotechnology/codeforlife-package-python/issues/94)) ([`7eeb1ff`](https://github.com/ocadotechnology/codeforlife-package-python/commit/7eeb1ff2c5d85985969b360d8d68352da77c9f68))

## v0.14.0 (2024-02-23)

### Feature
Expand Down
12 changes: 12 additions & 0 deletions codeforlife/tests/model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def assert_create(
validated_data: DataDict,
*args,
new_data: t.Optional[DataDict] = None,
non_model_fields: t.Optional[t.Iterable[str]] = None,
**kwargs,
):
"""Assert that the data used to create the model is a subset of the
Expand All @@ -149,10 +150,13 @@ def assert_create(
Args:
validated_data: The data used to create the model.
new_data: Any new data that the model may have after creating.
non_model_fields: Validated data fields that are not in the model.
"""
serializer = self._init_model_serializer(*args, **kwargs)
model = serializer.create(validated_data.copy())
data = {**validated_data, **(new_data or {})}
for field in non_model_fields or []:
data.pop(field)
self._assert_data_is_subset_of_model(data, model)

def assert_update(
Expand All @@ -161,6 +165,7 @@ def assert_update(
validated_data: DataDict,
*args,
new_data: t.Optional[DataDict] = None,
non_model_fields: t.Optional[t.Iterable[str]] = None,
**kwargs,
):
"""Assert that the data used to update the model is a subset of the
Expand All @@ -170,10 +175,13 @@ def assert_update(
instance: The model instance to update.
validated_data: The data used to update the model.
new_data: Any new data that the model may have after updating.
non_model_fields: Validated data fields that are not in the model.
"""
serializer = self._init_model_serializer(*args, **kwargs)
model = serializer.update(instance, validated_data.copy())
data = {**validated_data, **(new_data or {})}
for field in non_model_fields or []:
data.pop(field)
self._assert_data_is_subset_of_model(data, model)

def assert_update_many(
Expand All @@ -182,6 +190,7 @@ def assert_update_many(
validated_data: t.List[DataDict],
*args,
new_data: t.Optional[t.List[DataDict]] = None,
non_model_fields: t.Optional[t.Iterable[str]] = None,
**kwargs,
):
"""Assert that the data used to update the models is a subset of the
Expand All @@ -194,6 +203,7 @@ def assert_update_many(
instance: The model instances to update.
validated_data: The data used to update the models.
new_data: Any new data that the models may have after updating.
non_model_fields: Validated data fields that are not in the model.
"""
kwargs.pop("many", None) # many must be True
serializer = self._init_model_serializer(*args, **kwargs, many=True)
Expand All @@ -203,6 +213,8 @@ def assert_update_many(
new_data = new_data or [{} for _ in range(len(instance))]
for data, _new_data, model in zip(validated_data, new_data, models):
data = {**data, **_new_data}
for field in non_model_fields or []:
data.pop(field)
self._assert_data_is_subset_of_model(data, model)

def assert_to_representation(
Expand Down
36 changes: 32 additions & 4 deletions codeforlife/user/fixtures/independent.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"pk": 28,
"fields": {
"first_name": "Indy",
"last_name": "Man",
"username": "indy@man.com",
"email": "indy@man.com",
"last_name": "Requester",
"username": "indy.requester@email.com",
"email": "indy.requester@email.com",
"password": "pbkdf2_sha256$720000$Jp50WPBA6WZImUIpj3UcVm$OJWB8+UoW5lLaUkHLYo0cKgMkyRI6qnqVOWxYEsi9T0="
}
},
Expand All @@ -23,7 +23,35 @@
"pk": 18,
"fields": {
"user": 28,
"new_user": 28
"new_user": 28,
"pending_class_request": 6
}
},
{
"model": "auth.user",
"pk": 30,
"fields": {
"first_name": "Indy",
"last_name": "NoRequest",
"username": "[email protected]",
"email": "[email protected]",
"password": "pbkdf2_sha256$720000$Jp50WPBA6WZImUIpj3UcVm$OJWB8+UoW5lLaUkHLYo0cKgMkyRI6qnqVOWxYEsi9T0="
}
},
{
"model": "common.userprofile",
"pk": 30,
"fields": {
"user": 30,
"is_verified": true
}
},
{
"model": "common.student",
"pk": 20,
"fields": {
"user": 30,
"new_user": 30
}
}
]
6 changes: 3 additions & 3 deletions codeforlife/user/fixtures/school_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"fields": {
"name": "Class 1 @ School 1",
"access_code": "ZZ111",
"teacher": 6
"teacher": 6,
"accept_requests_until": "9999-02-09 20:26:08.298402+00:00"
}
},
{
Expand Down Expand Up @@ -106,8 +107,7 @@
"fields": {
"name": "Class 2 @ School 1",
"access_code": "ZZ222",
"teacher": 7,
"accept_requests_until": "9999-02-09 20:26:08.298402+00:00"
"teacher": 7
}
},
{
Expand Down
17 changes: 12 additions & 5 deletions codeforlife/user/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,13 @@ def create_user( # type: ignore[override]
**extra_fields,
):
"""Create a student-user."""
username = None
while username is None or self.filter(username=username).exists():
username = get_random_string(length=30)

# pylint: disable-next=protected-access
password = StudentUser._get_random_password()

user = super().create_user(
**extra_fields,
first_name=first_name,
username=username,
username=StudentUser.get_random_username(),
password=password,
)

Expand Down Expand Up @@ -336,6 +332,17 @@ def _get_random_login_id():

return login_id

@staticmethod
def get_random_username():
username = None

while (
username is None or User.objects.filter(username=username).exists()
):
username = get_random_string(length=30)

return username

# pylint: disable-next=arguments-differ
def set_password(self):
super().set_password(self._get_random_password())
Expand Down
2 changes: 1 addition & 1 deletion codeforlife/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Do NOT set manually!
# This is auto-updated by python-semantic-release in the pipeline.
__version__ = "0.14.0"
__version__ = "0.14.4"

0 comments on commit 874b428

Please sign in to comment.