mirror of
https://github.com/inventree/InvenTree.git
synced 2026-03-16 00:50:56 +00:00
Tweak migration unit tests
This commit is contained in:
@@ -86,7 +86,7 @@ class TestReferencePatternMigration(MigratorTestCase):
|
||||
"""
|
||||
|
||||
migrate_from = ('build', '0019_auto_20201019_1302')
|
||||
migrate_to = ('build', unit_test.getNewestMigrationFile('build'))
|
||||
migrate_to = ('build', '0022_buildorderattachment')
|
||||
|
||||
def prepare(self):
|
||||
"""Create some initial data prior to migration."""
|
||||
|
||||
@@ -201,7 +201,7 @@ class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('contenttypes', '__latest__'),
|
||||
("part", "0144_partcategoryparametertemplate_template"),
|
||||
("company", "0034_manufacturerpart"),
|
||||
("company", "0076_alter_company_image"),
|
||||
("common", "0040_parametertemplate_parameter"),
|
||||
]
|
||||
|
||||
|
||||
@@ -316,7 +316,7 @@ class TestSupplierPartQuantity(MigratorTestCase):
|
||||
"""Test that the supplier part quantity is correctly migrated."""
|
||||
|
||||
migrate_from = ('company', '0058_auto_20230515_0004')
|
||||
migrate_to = ('company', unit_test.getNewestMigrationFile('company'))
|
||||
migrate_to = ('company', '0062_contact_metadata')
|
||||
|
||||
def prepare(self):
|
||||
"""Prepare a number of SupplierPart objects."""
|
||||
@@ -381,21 +381,13 @@ class TestManufacturerPartParameterMigration(MigratorTestCase):
|
||||
def prepare(self):
|
||||
"""Create some existing data before migration."""
|
||||
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')
|
||||
ManufacturerPart = self.old_state.apps.get_model('company', 'manufacturerpart')
|
||||
ManufacturerPartParameter = self.old_state.apps.get_model(
|
||||
'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
|
||||
part = Part.objects.create(
|
||||
name='PART',
|
||||
@@ -415,15 +407,11 @@ class TestManufacturerPartParameterMigration(MigratorTestCase):
|
||||
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
|
||||
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):
|
||||
"""Test that ManufacturerPartParameter data has been migrated correctly."""
|
||||
@@ -433,7 +421,7 @@ class TestManufacturerPartParameterMigration(MigratorTestCase):
|
||||
ManufacturerPart = self.new_state.apps.get_model('company', 'manufacturerpart')
|
||||
|
||||
# There should be 6 ParameterTemplate objects
|
||||
self.assertEqual(ParameterTemplate.objects.count(), 6)
|
||||
self.assertEqual(ParameterTemplate.objects.count(), 3)
|
||||
|
||||
manu_part = ManufacturerPart.objects.first()
|
||||
|
||||
@@ -441,19 +429,12 @@ class TestManufacturerPartParameterMigration(MigratorTestCase):
|
||||
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(
|
||||
content_type=content_type, object_id=manu_part.pk
|
||||
)
|
||||
|
||||
self.assertEqual(params.count(), 6)
|
||||
self.assertEqual(params.count(), 3)
|
||||
|
||||
for name in [
|
||||
'Parameter 0',
|
||||
'Parameter 1',
|
||||
'Parameter 2',
|
||||
'Width',
|
||||
'Height',
|
||||
'Depth',
|
||||
]:
|
||||
for name in ['Width', 'Height', 'Depth']:
|
||||
self.assertTrue(params.filter(template__name=name).exists())
|
||||
|
||||
@@ -52,7 +52,7 @@ class TestBomItemMigrations(MigratorTestCase):
|
||||
"""Tests for BomItem migrations."""
|
||||
|
||||
migrate_from = ('part', '0002_auto_20190520_2204')
|
||||
migrate_to = ('part', unit_test.getNewestMigrationFile('part'))
|
||||
migrate_to = ('part', '0010_auto_20190620_2135')
|
||||
|
||||
def prepare(self):
|
||||
"""Create initial dataset."""
|
||||
@@ -158,7 +158,7 @@ class PartUnitsMigrationTest(MigratorTestCase):
|
||||
"""Test for data migration of Part.units field."""
|
||||
|
||||
migrate_from = ('part', '0109_auto_20230517_1048')
|
||||
migrate_to = ('part', unit_test.getNewestMigrationFile('part'))
|
||||
migrate_to = ('part', '0115_part_responsible_owner')
|
||||
|
||||
def prepare(self):
|
||||
"""Prepare some parts with units."""
|
||||
|
||||
@@ -2,14 +2,12 @@
|
||||
|
||||
from django_test_migrations.contrib.unittest_case import MigratorTestCase
|
||||
|
||||
from InvenTree import unit_test
|
||||
|
||||
|
||||
class TestSerialNumberMigration(MigratorTestCase):
|
||||
"""Test data migration which updates serial numbers."""
|
||||
|
||||
migrate_from = ('stock', '0067_alter_stockitem_part')
|
||||
migrate_to = ('stock', unit_test.getNewestMigrationFile('stock'))
|
||||
migrate_to = ('stock', '0070_auto_20211128_0151')
|
||||
|
||||
def prepare(self):
|
||||
"""Create initial data for this migration."""
|
||||
@@ -72,7 +70,7 @@ class TestScheduledForDeletionMigration(MigratorTestCase):
|
||||
"""Test data migration for removing 'scheduled_for_deletion' field."""
|
||||
|
||||
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):
|
||||
"""Create some initial stock items."""
|
||||
|
||||
Reference in New Issue
Block a user