From e407b99d0d1f89bab3d90fa519631b0088735f4e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 4 Feb 2021 09:13:11 +1100 Subject: [PATCH] Add initial migration unit test for the 'part' app --- InvenTree/part/test_migrations.py | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 InvenTree/part/test_migrations.py diff --git a/InvenTree/part/test_migrations.py b/InvenTree/part/test_migrations.py new file mode 100644 index 0000000000..0dbcdb1af8 --- /dev/null +++ b/InvenTree/part/test_migrations.py @@ -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()