From 4c34fd84701a2878195f860d0f8e4907d12b4149 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Fri, 8 Dec 2023 19:05:51 +0000 Subject: [PATCH] test fixtures --- codeforlife/user/fixtures/classes.json | 20 ++++++++++++ codeforlife/user/fixtures/schools.json | 12 +++++++ codeforlife/user/fixtures/students.json | 20 ++++++++++++ codeforlife/user/fixtures/teachers.json | 6 ++-- codeforlife/user/fixtures/users.json | 31 +++++++++++++++++++ codeforlife/user/models/user.py | 1 + .../user/tests/models/test_abstract.py | 6 +++- 7 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 codeforlife/user/fixtures/classes.json create mode 100644 codeforlife/user/fixtures/schools.json create mode 100644 codeforlife/user/fixtures/students.json diff --git a/codeforlife/user/fixtures/classes.json b/codeforlife/user/fixtures/classes.json new file mode 100644 index 00000000..f7873e52 --- /dev/null +++ b/codeforlife/user/fixtures/classes.json @@ -0,0 +1,20 @@ +[ + { + "model": "user.Class", + "pk": "AB123", + "fields": { + "last_saved_at": "2023-01-01 00:00:00.0+00:00", + "teacher": 1, + "school": 1 + } + }, + { + "model": "user.Class", + "pk": "AB456", + "fields": { + "last_saved_at": "2023-01-01 00:00:00.0+00:00", + "teacher": 2, + "school": 1 + } + } +] \ No newline at end of file diff --git a/codeforlife/user/fixtures/schools.json b/codeforlife/user/fixtures/schools.json new file mode 100644 index 00000000..8e19682d --- /dev/null +++ b/codeforlife/user/fixtures/schools.json @@ -0,0 +1,12 @@ +[ + { + "model": "user.School", + "pk": 1, + "fields": { + "last_saved_at": "2023-01-01 00:00:00.0+00:00", + "name": "Example School", + "country": "UK", + "uk_county": "Surrey" + } + } +] \ No newline at end of file diff --git a/codeforlife/user/fixtures/students.json b/codeforlife/user/fixtures/students.json new file mode 100644 index 00000000..bc8d65a0 --- /dev/null +++ b/codeforlife/user/fixtures/students.json @@ -0,0 +1,20 @@ +[ + { + "model": "user.Student", + "pk": 1, + "fields": { + "last_saved_at": "2023-01-01 00:00:00.0+00:00", + "school": 1, + "klass": "AB123" + } + }, + { + "model": "user.Student", + "pk": 2, + "fields": { + "last_saved_at": "2023-01-01 00:00:00.0+00:00", + "school": 1, + "klass": "AB456" + } + } +] \ No newline at end of file diff --git a/codeforlife/user/fixtures/teachers.json b/codeforlife/user/fixtures/teachers.json index add1b720..3d7cd7a2 100644 --- a/codeforlife/user/fixtures/teachers.json +++ b/codeforlife/user/fixtures/teachers.json @@ -4,7 +4,8 @@ "pk": 1, "fields": { "last_saved_at": "2023-01-01 00:00:00.0+00:00", - "is_admin": true + "is_admin": true, + "school": 1 } }, { @@ -12,7 +13,8 @@ "pk": 2, "fields": { "last_saved_at": "2023-01-01 00:00:00.0+00:00", - "is_admin": true + "is_admin": false, + "school": 1 } } ] \ No newline at end of file diff --git a/codeforlife/user/fixtures/users.json b/codeforlife/user/fixtures/users.json index 04ae23d1..2d3e67c0 100644 --- a/codeforlife/user/fixtures/users.json +++ b/codeforlife/user/fixtures/users.json @@ -22,5 +22,36 @@ "password": "password", "teacher": 2 } + }, + { + "model": "user.User", + "pk": 3, + "fields": { + "last_saved_at": "2023-01-01 00:00:00.0+00:00", + "first_name": "SpongeBob", + "password": "password", + "student": 1 + } + }, + { + "model": "user.User", + "pk": 4, + "fields": { + "last_saved_at": "2023-01-01 00:00:00.0+00:00", + "first_name": "Patrick", + "password": "password", + "student": 2 + } + }, + { + "model": "user.User", + "pk": 5, + "fields": { + "last_saved_at": "2023-01-01 00:00:00.0+00:00", + "first_name": "Indiana", + "last_name": "Jones", + "email": "indiana.jones@codeforlife.com", + "password": "password" + } } ] \ No newline at end of file diff --git a/codeforlife/user/models/user.py b/codeforlife/user/models/user.py index 1dc97c20..d4c1cba4 100644 --- a/codeforlife/user/models/user.py +++ b/codeforlife/user/models/user.py @@ -122,6 +122,7 @@ def create_superuser(self, password: str, first_name: str, **fields): ) # TODO: is last name required for teachers? + # TODO: are students allowed to have a last name? last_name = models.CharField( _("last name"), max_length=150, diff --git a/codeforlife/user/tests/models/test_abstract.py b/codeforlife/user/tests/models/test_abstract.py index e2254c64..6194156d 100644 --- a/codeforlife/user/tests/models/test_abstract.py +++ b/codeforlife/user/tests/models/test_abstract.py @@ -8,7 +8,7 @@ from django.test import TestCase from django.utils import timezone -from ...models import User +from ...models import Class, User class TestAbstract(TestCase): @@ -18,9 +18,13 @@ class TestAbstract(TestCase): Abstract model path: codeforlife.models """ + # TODO: group fixtures by scenarios, not model classes. fixtures = [ "users", "teachers", + "schools", + "classes", + "students", ] def setUp(self):