2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-04-04 10:31:03 +00:00

Tweak migration unit tests

This commit is contained in:
Oliver Walters
2025-12-02 03:06:20 +00:00
parent 539add7105
commit aaf6a97d71
5 changed files with 15 additions and 36 deletions

View File

@@ -86,7 +86,7 @@ class TestReferencePatternMigration(MigratorTestCase):
""" """
migrate_from = ('build', '0019_auto_20201019_1302') migrate_from = ('build', '0019_auto_20201019_1302')
migrate_to = ('build', unit_test.getNewestMigrationFile('build')) migrate_to = ('build', '0022_buildorderattachment')
def prepare(self): def prepare(self):
"""Create some initial data prior to migration.""" """Create some initial data prior to migration."""

View File

@@ -201,7 +201,7 @@ class Migration(migrations.Migration):
dependencies = [ dependencies = [
('contenttypes', '__latest__'), ('contenttypes', '__latest__'),
("part", "0144_partcategoryparametertemplate_template"), ("part", "0144_partcategoryparametertemplate_template"),
("company", "0034_manufacturerpart"), ("company", "0076_alter_company_image"),
("common", "0040_parametertemplate_parameter"), ("common", "0040_parametertemplate_parameter"),
] ]

View File

@@ -316,7 +316,7 @@ class TestSupplierPartQuantity(MigratorTestCase):
"""Test that the supplier part quantity is correctly migrated.""" """Test that the supplier part quantity is correctly migrated."""
migrate_from = ('company', '0058_auto_20230515_0004') migrate_from = ('company', '0058_auto_20230515_0004')
migrate_to = ('company', unit_test.getNewestMigrationFile('company')) migrate_to = ('company', '0062_contact_metadata')
def prepare(self): def prepare(self):
"""Prepare a number of SupplierPart objects.""" """Prepare a number of SupplierPart objects."""
@@ -381,21 +381,13 @@ class TestManufacturerPartParameterMigration(MigratorTestCase):
def prepare(self): def prepare(self):
"""Create some existing data before migration.""" """Create some existing data before migration."""
Part = self.old_state.apps.get_model('part', 'part') Part = self.old_state.apps.get_model('part', 'part')
PartParameterTemplate = self.old_state.apps.get_model(
'part', 'partparametertemplate'
)
Company = self.old_state.apps.get_model('company', 'company') Company = self.old_state.apps.get_model('company', 'company')
ManufacturerPart = self.old_state.apps.get_model('company', 'manufacturerpart') ManufacturerPart = self.old_state.apps.get_model('company', 'manufacturerpart')
ManufacturerPartParameter = self.old_state.apps.get_model( ManufacturerPartParameter = self.old_state.apps.get_model(
'company', 'manufacturerpartparameter' 'company', 'manufacturerpartparameter'
) )
# Create some existing templates
for ii in range(3):
PartParameterTemplate.objects.create(
name=f'Parameter {ii}', description=f'Description for parameter {ii}'
)
# Create a ManufacturerPart # Create a ManufacturerPart
part = Part.objects.create( part = Part.objects.create(
name='PART', name='PART',
@@ -415,15 +407,11 @@ class TestManufacturerPartParameterMigration(MigratorTestCase):
part=part, manufacturer=manufacturer, MPN='MPN-001' part=part, manufacturer=manufacturer, MPN='MPN-001'
) )
# Create some parameters which correlate with existing templates
for ii in range(3):
ManufacturerPartParameter.objects.create(
manufacturer_part=manu_part, name=f'Parameter {ii}', value=str(ii * 10)
)
# Create a parameter which does NOT correlate with any existing template # Create a parameter which does NOT correlate with any existing template
for name in ['Width', 'Height', 'Depth']: for name in ['Width', 'Height', 'Depth']:
ManufacturerPartParameter.objects.create(name=name, value='100', units='mm') ManufacturerPartParameter.objects.create(
manufacturer_part=manu_part, name=name, value='100', units='mm'
)
def test_manufacturer_part_parameter_migration(self): def test_manufacturer_part_parameter_migration(self):
"""Test that ManufacturerPartParameter data has been migrated correctly.""" """Test that ManufacturerPartParameter data has been migrated correctly."""
@@ -433,7 +421,7 @@ class TestManufacturerPartParameterMigration(MigratorTestCase):
ManufacturerPart = self.new_state.apps.get_model('company', 'manufacturerpart') ManufacturerPart = self.new_state.apps.get_model('company', 'manufacturerpart')
# There should be 6 ParameterTemplate objects # There should be 6 ParameterTemplate objects
self.assertEqual(ParameterTemplate.objects.count(), 6) self.assertEqual(ParameterTemplate.objects.count(), 3)
manu_part = ManufacturerPart.objects.first() manu_part = ManufacturerPart.objects.first()
@@ -441,19 +429,12 @@ class TestManufacturerPartParameterMigration(MigratorTestCase):
app_label='company', model='manufacturerpart' app_label='company', model='manufacturerpart'
) )
# There should be 6 Parameter objects linked to the ManufacturerPart # There should be 3 Parameter objects linked to the ManufacturerPart
params = Parameter.objects.filter( params = Parameter.objects.filter(
content_type=content_type, object_id=manu_part.pk content_type=content_type, object_id=manu_part.pk
) )
self.assertEqual(params.count(), 6) self.assertEqual(params.count(), 3)
for name in [ for name in ['Width', 'Height', 'Depth']:
'Parameter 0',
'Parameter 1',
'Parameter 2',
'Width',
'Height',
'Depth',
]:
self.assertTrue(params.filter(template__name=name).exists()) self.assertTrue(params.filter(template__name=name).exists())

View File

@@ -52,7 +52,7 @@ class TestBomItemMigrations(MigratorTestCase):
"""Tests for BomItem migrations.""" """Tests for BomItem migrations."""
migrate_from = ('part', '0002_auto_20190520_2204') migrate_from = ('part', '0002_auto_20190520_2204')
migrate_to = ('part', unit_test.getNewestMigrationFile('part')) migrate_to = ('part', '0010_auto_20190620_2135')
def prepare(self): def prepare(self):
"""Create initial dataset.""" """Create initial dataset."""
@@ -158,7 +158,7 @@ class PartUnitsMigrationTest(MigratorTestCase):
"""Test for data migration of Part.units field.""" """Test for data migration of Part.units field."""
migrate_from = ('part', '0109_auto_20230517_1048') migrate_from = ('part', '0109_auto_20230517_1048')
migrate_to = ('part', unit_test.getNewestMigrationFile('part')) migrate_to = ('part', '0115_part_responsible_owner')
def prepare(self): def prepare(self):
"""Prepare some parts with units.""" """Prepare some parts with units."""

View File

@@ -2,14 +2,12 @@
from django_test_migrations.contrib.unittest_case import MigratorTestCase from django_test_migrations.contrib.unittest_case import MigratorTestCase
from InvenTree import unit_test
class TestSerialNumberMigration(MigratorTestCase): class TestSerialNumberMigration(MigratorTestCase):
"""Test data migration which updates serial numbers.""" """Test data migration which updates serial numbers."""
migrate_from = ('stock', '0067_alter_stockitem_part') migrate_from = ('stock', '0067_alter_stockitem_part')
migrate_to = ('stock', unit_test.getNewestMigrationFile('stock')) migrate_to = ('stock', '0070_auto_20211128_0151')
def prepare(self): def prepare(self):
"""Create initial data for this migration.""" """Create initial data for this migration."""
@@ -72,7 +70,7 @@ class TestScheduledForDeletionMigration(MigratorTestCase):
"""Test data migration for removing 'scheduled_for_deletion' field.""" """Test data migration for removing 'scheduled_for_deletion' field."""
migrate_from = ('stock', '0066_stockitem_scheduled_for_deletion') migrate_from = ('stock', '0066_stockitem_scheduled_for_deletion')
migrate_to = ('stock', unit_test.getNewestMigrationFile('stock')) migrate_to = ('stock', '0069_auto_20211109_2347')
def prepare(self): def prepare(self):
"""Create some initial stock items.""" """Create some initial stock items."""