mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add initial migration unit test for the 'part' app
This commit is contained in:
parent
d811f3c48a
commit
e407b99d0d
52
InvenTree/part/test_migrations.py
Normal file
52
InvenTree/part/test_migrations.py
Normal file
@ -0,0 +1,52 @@
|
||||
"""
|
||||
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()
|
Loading…
Reference in New Issue
Block a user