Tests: add test project

* manage.py file at the root of the project
* targetting the project located at tests/test_project/settings.py

That allows testing the linter through just calling it on the project itself.
Using the new method coming soon: `python manage.py lintmigrations`
This commit is contained in:
David Wobrock committed 2019-05-12 15:32:57 +02:00
1 parent fdd6b9b06a
commit 26ed4ecf62
85 files changed
+843

No files matched your search

Executable
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.test_project.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
View File
Whitespace-only changes.
Whitespace-only changes.
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,5 @@
from django.apps import AppConfig
class AppAddNotNullColumnConfig(AppConfig):
name = "app_add_not_null_column"
@@ -0,0 +1,28 @@
# Generated by Django 2.1.4 on 2019-03-19 20:59
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("null_field", models.IntegerField(null=True)),
],
)
]
@@ -0,0 +1,17 @@
# Generated by Django 2.1.4 on 2019-03-19 21:05
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("app_add_not_null_column", "0001_create_table")]
operations = [
migrations.AddField(
model_name="a",
name="new_not_null_field",
field=models.IntegerField(default=1),
preserve_default=False,
)
]
Whitespace-only changes.
@@ -0,0 +1,6 @@
from django.db import models
class A(models.Model):
null_field = models.IntegerField(null=True)
new_not_null_field = models.IntegerField(null=False)
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class AppAddNotNullColumnFollowedByDefaultConfig(AppConfig):
name = "tests.test_project.app_add_not_null_column_followed_by_default"
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 14:54
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("field", models.IntegerField()),
],
)
]
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 14:55
from __future__ import unicode_literals
from django.db import migrations, models
from django_add_default_value import AddDefaultValue
class Migration(migrations.Migration):
dependencies = [("app_add_not_null_column_followed_by_default", "0001_initial")]
operations = [
migrations.AddField(
model_name="a", name="not_null_field", field=models.IntegerField(default=1)
),
AddDefaultValue(model_name="a", name="not_null_field", value=1),
]
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class A(models.Model):
field = models.IntegerField()
not_null_field = models.IntegerField(null=False, default=1)
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
# Create your views here.
Whitespace-only changes.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class AppAlterColumnConfig(AppConfig):
name = "tests.test_project.app_alter_column"
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 14:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("field", models.IntegerField(null=True)),
],
)
]
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 14:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("app_alter_column", "0001_initial")]
operations = [
migrations.AlterField(
model_name="a",
name="field",
field=models.CharField(max_length=10, null=True),
)
]
Whitespace-only changes.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class A(models.Model):
field = models.CharField(null=True, max_length=10)
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
# Create your views here.
Whitespace-only changes.
+3
View File
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
+5
View File
@@ -0,0 +1,5 @@
from django.apps import AppConfig
class AppCorrectConfig(AppConfig):
name = "app_correct"
@@ -0,0 +1,28 @@
# Generated by Django 2.1.4 on 2019-03-19 21:08
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("null_field", models.IntegerField(null=True)),
],
)
]
@@ -0,0 +1,14 @@
# Generated by Django 2.1.4 on 2019-03-19 21:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [("app_correct", "0001_initial")]
operations = [
migrations.AddField(
model_name="a", name="new_null_field", field=models.IntegerField(null=True)
)
]
Whitespace-only changes.
+6
View File
@@ -0,0 +1,6 @@
from django.db import models
class A(models.Model):
null_field = models.IntegerField(null=True)
new_null_field = models.IntegerField(null=True)
+3
View File
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
+3
View File
@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
Whitespace-only changes.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class AppCreateTableWithNotNullColumnConfig(AppConfig):
name = "tests.test_project.app_create_table_with_not_null_column"
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 14:59
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("field", models.CharField(max_length=150)),
],
)
]
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class A(models.Model):
field = models.CharField(max_length=150, null=False)
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
# Create your views here.
Whitespace-only changes.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class AppDropColumnConfig(AppConfig):
name = "tests.test_project.app_drop_column"
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 14:59
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("field_a", models.IntegerField()),
("field_b", models.CharField(max_length=10)),
],
)
]
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 14:59
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("app_drop_column", "0001_initial")]
operations = [migrations.RemoveField(model_name="a", name="field_b")]
Whitespace-only changes.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class A(models.Model):
field_a = models.IntegerField()
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
# Create your views here.
Whitespace-only changes.
@@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,5 @@
from django.apps import AppConfig
class AppIgnoreMigrationConfig(AppConfig):
name = "app_ignore_migration"
@@ -0,0 +1,28 @@
# Generated by Django 2.1.4 on 2019-03-21 20:40
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="B",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("null_field", models.IntegerField()),
],
)
]
@@ -0,0 +1,20 @@
# Generated by Django 2.1.4 on 2019-03-21 20:41
from django.db import migrations, models
import django_migration_linter as linter
class Migration(migrations.Migration):
dependencies = [("app_ignore_migration", "0001_initial")]
operations = [
linter.IgnoreMigration(),
migrations.AddField(
model_name="b",
name="null_field_real",
field=models.IntegerField(default=1),
preserve_default=False,
),
]
Whitespace-only changes.
@@ -0,0 +1,6 @@
from django.db import models
class B(models.Model):
null_field = models.IntegerField()
null_field_real = models.IntegerField(null=False)
@@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.
Whitespace-only changes.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class AppRenameColumnConfig(AppConfig):
name = "tests.test_project.app_rename_column"
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 15:02
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("field", models.IntegerField()),
],
)
]
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 15:02
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("app_rename_column", "0001_initial")]
operations = [
migrations.RenameField(model_name="a", old_name="field", new_name="renamed")
]
Whitespace-only changes.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class A(models.Model):
renamed = models.IntegerField()
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
# Create your views here.
Whitespace-only changes.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class AppRenameTableConfig(AppConfig):
name = "tests.test_project.app_rename_table"
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 15:00
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = []
operations = [
migrations.CreateModel(
name="A",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("field", models.IntegerField()),
],
)
]
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.18 on 2019-04-14 15:00
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [("app_rename_table", "0001_initial")]
operations = [migrations.RenameModel(old_name="A", new_name="B")]
Whitespace-only changes.
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
class B(models.Model):
field = models.IntegerField()
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render
# Create your views here.
+142
View File
@@ -0,0 +1,142 @@
"""
Django settings for test_project project.
Generated by 'django-admin startproject' using Django 2.1.7.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
from collections import OrderedDict
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "dummy"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_migration_linter",
"tests.test_project.app_add_not_null_column",
"tests.test_project.app_add_not_null_column_followed_by_default",
"tests.test_project.app_alter_column",
"tests.test_project.app_correct",
"tests.test_project.app_create_table_with_not_null_column",
"tests.test_project.app_drop_column",
"tests.test_project.app_ignore_migration",
"tests.test_project.app_rename_column",
"tests.test_project.app_rename_table",
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "tests.test_project.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
]
},
}
]
WSGI_APPLICATION = "tests.test_project.wsgi.application"
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
"TEST": {"DEPENDENCIES": []},
},
"sqlite": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "sqlite3",
"TEST": {"DEPENDENCIES": []},
},
"postgresql": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "django_migration_linter_test_project",
"USER": "postgres",
"TEST": {"DEPENDENCIES": []},
},
"mysql": {
"ENGINE": "django.db.backends.mysql",
"NAME": "django_migration_linter_test_project",
"USER": "travis",
"PASSWORD": "",
"HOST": "127.0.0.1",
"TEST": {"DEPENDENCIES": []},
},
}
# Password validation
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = "/static/"
+19
View File
@@ -0,0 +1,19 @@
"""test_project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.conf.urls import url
urlpatterns = [url("admin/", admin.site.urls)]
+16
View File
@@ -0,0 +1,16 @@
"""
WSGI config for test_project project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
application = get_wsgi_application()