Skip to content

Commit a35ddb6

Browse files
committed
Use a demo project for running the test suite
When all test environments were run locally, the migration files would persist. This would result in `NodeNotFoundError` being raised when ran against a version of Django that does not contain that migration file. This change introduces a migration file that is connected to Django's 0008 `auth` migration. Since the change to the custom `User` model is trivial, this should not be an issue when tested against future versions of Django.
1 parent 2be6485 commit a35ddb6

File tree

21 files changed

+321
-72
lines changed

21 files changed

+321
-72
lines changed

demo/app/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default_app_config = "app.apps.AppConfig"

demo/app/admin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import unicode_literals
4+
5+
from django.contrib import admin
6+
from django.contrib.auth import get_user_model
7+
from django.contrib.auth.admin import UserAdmin
8+
9+
10+
User = get_user_model()
11+
12+
13+
@admin.register(User)
14+
class UserAdmin(UserAdmin):
15+
pass

demo/app/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AppConfig(AppConfig):
5+
name = "app"
6+
label = "app"

demo/app/migrations/0001_initial.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from django.conf import settings
2+
import django.contrib.auth.models
3+
import django.contrib.auth.validators
4+
from django.db import migrations, models
5+
import django.db.models.deletion
6+
import django.utils.timezone
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
initial = True
12+
13+
dependencies = [
14+
('auth', '0008_alter_user_username_max_length'),
15+
]
16+
17+
operations = [
18+
migrations.CreateModel(
19+
name='UserWithProfile',
20+
fields=[
21+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
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=30, 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+
('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')),
33+
('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')),
34+
],
35+
managers=[
36+
('objects', django.contrib.auth.models.UserManager()),
37+
],
38+
),
39+
migrations.CreateModel(
40+
name='UserProfile',
41+
fields=[
42+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
43+
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)),
44+
],
45+
),
46+
]

demo/app/migrations/__init__.py

Whitespace-only changes.

tests/models.py renamed to demo/app/models.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,22 @@
22

33
from __future__ import unicode_literals
44

5+
from django.conf import settings
56
from django.contrib.auth.models import AbstractUser
67
from django.db import models
78

89

910
class UserWithProfile(AbstractUser):
1011

11-
class Meta:
12-
app_label = 'tests'
13-
1412
def save(self, *args, **kwargs):
1513
if not self.pk:
1614
self.profile = UserProfile(user=self)
1715
super(UserWithProfile, self).save(*args, **kwargs)
1816

1917

2018
class UserProfile(models.Model):
21-
user = models.OneToOneField(UserWithProfile, related_name='profile',
22-
on_delete=models.CASCADE)
23-
24-
class Meta:
25-
app_label = 'tests'
19+
user = models.OneToOneField(
20+
settings.AUTH_USER_MODEL,
21+
related_name="profile",
22+
on_delete=models.CASCADE,
23+
)

demo/app/urls.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import unicode_literals
4+
5+
from rest_framework_jwt import views
6+
from rest_framework_jwt.compat import url
7+
8+
from .views import test_view
9+
10+
11+
urlpatterns = [
12+
url(r"^auth/$", views.obtain_jwt_token, name="auth"),
13+
url(r"^auth/verify/$", views.verify_jwt_token, name="auth-verify"),
14+
url(r"^auth/refresh/$", views.refresh_jwt_token, name="auth-refresh"),
15+
url(r"^test-view/$", test_view, name="test-view"),
16+
]
File renamed without changes.

demo/demo/__init__.py

Whitespace-only changes.

demo/demo/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for demo project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo.settings')
15+
16+
application = get_asgi_application()

0 commit comments

Comments
 (0)