Skip to content

Commit 79118b6

Browse files
authored
Merge pull request #198 from anexia-it/SIANXKE-410_userUUID
Test cases for issue #99 (UUID as user model primary key field)
2 parents b68009c + b3eb207 commit 79118b6

File tree

13 files changed

+112
-3
lines changed

13 files changed

+112
-3
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
# prepare Django project: link all necessary data from the test project into the root directory
7171
# Hint: Simply changing the directory does not work (leads to missing files in coverage report)
7272
ln -s ./tests/test test
73+
ln -s ./tests/user_id_uuid_testapp user_id_uuid_testapp
7374
ln -s ./tests/manage.py manage.py
7475
ln -s ./tests/settings.py settings.py
7576
ln -s ./tests/urls.py urls.py

tests/settings.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
'rest_framework',
4343

4444
# include multi token auth
45-
'django_rest_passwordreset'
45+
'django_rest_passwordreset',
46+
47+
# test app
48+
'user_id_uuid_testapp',
4649
]
4750

4851
MIDDLEWARE = [
@@ -123,3 +126,4 @@
123126

124127
STATIC_URL = '/static/'
125128

129+
AUTH_USER_MODEL = "user_id_uuid_testapp.User"

tests/test/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from django.contrib.auth.models import User
1+
from django.contrib.auth import get_user_model
2+
3+
User = get_user_model()
24

35
try:
46
from unittest.mock import patch

tests/test/test_auth_test_case.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
from datetime import timedelta
33

4-
from django.contrib.auth.models import User
4+
from django.contrib.auth import get_user_model
55
from django.test import override_settings
66
from django.utils import timezone
77
from rest_framework import status
@@ -11,6 +11,8 @@
1111
from django_rest_passwordreset.views import clear_expired_tokens, generate_token_for_email
1212
from tests.test.helpers import HelperMixin, patch
1313

14+
User = get_user_model()
15+
1416

1517
class AuthTestCase(APITestCase, HelperMixin):
1618
"""

tests/user_id_uuid_testapp/__init__.py

Whitespace-only changes.

tests/user_id_uuid_testapp/apps.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class TestappConfig(AppConfig):
5+
name = "user_id_uuid_testapp"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Generated by Django 3.2.18 on 2024-10-25 12:00
2+
3+
import django.contrib.auth.models
4+
import django.contrib.auth.validators
5+
from django.db import migrations, models
6+
import django.utils.timezone
7+
import uuid
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
initial = True
13+
14+
dependencies = [
15+
('auth', '0012_alter_user_first_name_max_length'),
16+
]
17+
18+
operations = [
19+
migrations.CreateModel(
20+
name='User',
21+
fields=[
22+
('password', models.CharField(max_length=128, verbose_name='password')),
23+
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
24+
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
25+
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
26+
('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')),
27+
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
28+
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
29+
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
30+
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
31+
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
32+
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
33+
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
34+
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
35+
],
36+
options={
37+
'verbose_name': 'user',
38+
'verbose_name_plural': 'users',
39+
'abstract': False,
40+
},
41+
managers=[
42+
('objects', django.contrib.auth.models.UserManager()),
43+
],
44+
),
45+
]

tests/user_id_uuid_testapp/migrations/__init__.py

Whitespace-only changes.

tests/user_id_uuid_testapp/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import uuid
2+
3+
from django.contrib.auth.models import AbstractUser
4+
from django.db import models
5+
6+
7+
class User(AbstractUser):
8+
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

tests/user_id_uuid_testapp/tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)