mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-21 06:16:29 +00:00
Merge pull request #1271 from SchrodingersGat/migration-unit-test
Migration unit test
This commit is contained in:
@ -12,6 +12,8 @@ def update_tree(apps, schema_editor):
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
atomic = False
|
||||
|
||||
dependencies = [
|
||||
('part', '0019_auto_20190908_0404'),
|
||||
]
|
||||
|
@ -18,6 +18,8 @@ def create_thumbnails(apps, schema_editor):
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
atomic = False
|
||||
|
||||
dependencies = [
|
||||
('part', '0033_auto_20200404_0445'),
|
||||
]
|
||||
|
@ -16,6 +16,8 @@ def nupdate_tree(apps, schema_editor):
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
atomic = False
|
||||
|
||||
dependencies = [
|
||||
('part', '0038_auto_20200513_0016'),
|
||||
]
|
||||
|
@ -138,6 +138,8 @@ def reverse_currencies(apps, schema_editor):
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
atomic = False
|
||||
|
||||
dependencies = [
|
||||
('part', '0055_auto_20201110_1001'),
|
||||
]
|
||||
|
51
InvenTree/part/test_migrations.py
Normal file
51
InvenTree/part/test_migrations.py
Normal file
@ -0,0 +1,51 @@
|
||||
"""
|
||||
Unit tests for the part model database migrations
|
||||
"""
|
||||
|
||||
from django_test_migrations.contrib.unittest_case import MigratorTestCase
|
||||
|
||||
from InvenTree import helpers
|
||||
|
||||
|
||||
class TestForwardMigrations(MigratorTestCase):
|
||||
"""
|
||||
Test entire schema migration sequence for the part app
|
||||
"""
|
||||
|
||||
migrate_from = ('part', helpers.getOldestMigrationFile('part'))
|
||||
migrate_to = ('part', helpers.getNewestMigrationFile('part'))
|
||||
|
||||
def prepare(self):
|
||||
"""
|
||||
Create initial data
|
||||
"""
|
||||
|
||||
Part = self.old_state.apps.get_model('part', 'part')
|
||||
|
||||
Part.objects.create(name='A', description='My part A')
|
||||
Part.objects.create(name='B', description='My part B')
|
||||
Part.objects.create(name='C', description='My part C')
|
||||
Part.objects.create(name='D', description='My part D')
|
||||
Part.objects.create(name='E', description='My part E')
|
||||
|
||||
# Extract one part object to investigate
|
||||
p = Part.objects.all().last()
|
||||
|
||||
# Initially some fields are not present
|
||||
with self.assertRaises(AttributeError):
|
||||
print(p.has_variants)
|
||||
|
||||
with self.assertRaises(AttributeError):
|
||||
print(p.is_template)
|
||||
|
||||
def test_models_exist(self):
|
||||
|
||||
Part = self.new_state.apps.get_model('part', 'part')
|
||||
|
||||
self.assertEqual(Part.objects.count(), 5)
|
||||
|
||||
for part in Part.objects.all():
|
||||
part.is_template = True
|
||||
part.save()
|
||||
part.is_template = False
|
||||
part.save()
|
Reference in New Issue
Block a user