Selaa lähdekoodia

Add unittest for testing migrations (from wagtail)

This also updates the pytest dependencies
master
Michael van Tellingen 9 vuotta sitten
vanhempi
commit
bc893aa92a
No account linked to committer's email address

+ 1
- 0
.travis.yml Näytä tiedosto

@@ -48,6 +48,7 @@ before_install:
48 48
 install:
49 49
     - pip install --pre $DJANGO 
50 50
     - pip install -r requirements.txt 
51
+    - pip list
51 52
 
52 53
 before_script:
53 54
     # Create testing databases for running migrations against

+ 4
- 4
setup.py Näytä tiedosto

@@ -60,11 +60,11 @@ test_requires = [
60 60
     'WebTest==2.0.21',
61 61
     'coverage==3.7.1',
62 62
     'django-webtest==1.7.9',
63
-    'pytest-cache==1.0',
64
-    'pytest-cov==2.2.0',
63
+    'py>=1.4.31',
64
+    'pytest-cov==2.3.0',
65 65
     'pytest-django==2.9.1',
66
-    'pytest-xdist==1.13.1',
67
-    'pytest==2.8.5',
66
+    'pytest-xdist==1.14',
67
+    'pytest==2.9.2',
68 68
     'spec==0.11.1',
69 69
     'tox==1.8.1',
70 70
 ]

+ 0
- 39
tests/_site/myauth/migrations/0001_initial.py Näytä tiedosto

@@ -1,39 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-# Generated by Django 1.9.7 on 2016-07-13 09:29
3
-from __future__ import unicode_literals
4
-
5
-import django.core.validators
6
-from django.db import migrations, models
7
-import django.utils.timezone
8
-import re
9
-
10
-
11
-class Migration(migrations.Migration):
12
-
13
-    initial = True
14
-
15
-    dependencies = [
16
-        ('auth', '0007_alter_validators_add_error_messages'),
17
-    ]
18
-
19
-    operations = [
20
-        migrations.CreateModel(
21
-            name='User',
22
-            fields=[
23
-                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
24
-                ('password', models.CharField(max_length=128, verbose_name='password')),
25
-                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
26
-                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
27
-                ('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
28
-                ('first_name', models.CharField(blank=True, max_length=255, verbose_name='First name')),
29
-                ('last_name', models.CharField(blank=True, max_length=255, verbose_name='Last name')),
30
-                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='Staff status')),
31
-                ('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')),
32
-                ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
33
-                ('username', models.CharField(help_text='Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters', max_length=30, unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[\\w.@+-]+$', 32), 'Enter a valid username.', 'invalid')], verbose_name='username')),
34
-                ('extra_field', models.CharField(blank=True, max_length=5, verbose_name='Nobody needs me')),
35
-                ('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')),
36
-                ('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')),
37
-            ],
38
-        ),
39
-    ]

+ 0
- 0
tests/_site/myauth/migrations/__init__.py Näytä tiedosto


+ 58
- 0
tests/integration/migrations_tests.py Näytä tiedosto

@@ -0,0 +1,58 @@
1
+"""This module was taken from Wagtail, see:
2
+
3
+https://github.com/torchbox/wagtail/blob/d82e38e11e9f6c27b6ad6dfc6467e2754b5ab228/wagtail/wagtailcore/tests/test_migrations.py
4
+
5
+
6
+"""
7
+from __future__ import absolute_import
8
+
9
+from django.apps import apps
10
+from django.db.migrations.autodetector import MigrationAutodetector
11
+from django.db.migrations.loader import MigrationLoader
12
+from django.db.migrations.questioner import MigrationQuestioner
13
+from django.db.migrations.state import ProjectState
14
+from django.test import TransactionTestCase
15
+from django.utils.six import iteritems
16
+
17
+
18
+class TestForMigrations(TransactionTestCase):
19
+    def test__migrations(self):
20
+        app_labels = set(app.label for app in apps.get_app_configs()
21
+                         if app.name.startswith('oscar.'))
22
+        for app_label in app_labels:
23
+            apps.get_app_config(app_label.split('.')[-1])
24
+        loader = MigrationLoader(None, ignore_no_migrations=True)
25
+
26
+        conflicts = dict(
27
+            (app_label, conflict)
28
+            for app_label, conflict in iteritems(loader.detect_conflicts())
29
+            if app_label in app_labels
30
+        )
31
+
32
+        if conflicts:
33
+            name_str = "; ".join("%s in %s" % (", ".join(names), app)
34
+                                 for app, names in conflicts.items())
35
+            self.fail("Conflicting migrations detected (%s)." % name_str)
36
+
37
+        autodetector = MigrationAutodetector(
38
+            loader.project_state(),
39
+            ProjectState.from_apps(apps),
40
+            MigrationQuestioner(specified_apps=app_labels, dry_run=True),
41
+        )
42
+
43
+        changes = autodetector.changes(
44
+            graph=loader.graph,
45
+            trim_to_apps=app_labels or None,
46
+            convert_apps=app_labels or None,
47
+        )
48
+
49
+        if changes:
50
+            migrations = '\n'.join((
51
+                '  {migration}\n{changes}'.format(
52
+                    migration=migration,
53
+                    changes='\n'.join('    {0}'.format(operation.describe())
54
+                                      for operation in migration.operations))
55
+                for (_, migrations) in changes.items()
56
+                for migration in migrations))
57
+
58
+            self.fail('Model changes with no migrations detected:\n%s' % migrations)

Loading…
Peruuta
Tallenna