mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-04 06:18:48 +00:00
* Add fix for stock migration - Ensure the serial number is not too large when performing migration - Add unit test for data migration (cherry picked from commit 661fbf0e3dbdf6444d3d25b02d68ad229925d87c) * Add similar fixes for PO and SO migrations (cherry picked from commit bde23c130c879e7663091fba808bbd57c52ed8bf) * And similar fix for BuildOrder reference field (cherry picked from commit ca0f4e00310aed0551f8fad5c57f90fae2177f04) * Update unit tests for API plugin mixin class - API at previous target URL has changed - Simplier to use the github API as a test case (cherry picked from commit dfe3172b7d7e7c6910aff0e6248b5609570607a9) * Revert test database name (cherry picked from commit 53333c29c38ae393b1e31e764e08a1239839a594) * Override default URL behaviour for unit test (cherry picked from commit 2c12a695294c2785e82b7f469f79a7d1a5412e71)
70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
"""Unit tests for data migrations in the 'stock' app"""
|
|
|
|
from django_test_migrations.contrib.unittest_case import MigratorTestCase
|
|
|
|
from InvenTree import helpers
|
|
|
|
|
|
class TestSerialNumberMigration(MigratorTestCase):
|
|
"""Test data migration which updates serial numbers"""
|
|
|
|
migrate_from = ('stock', '0067_alter_stockitem_part')
|
|
migrate_to = ('stock', helpers.getNewestMigrationFile('stock'))
|
|
|
|
def prepare(self):
|
|
"""Create initial data for this migration"""
|
|
|
|
Part = self.old_state.apps.get_model('part', 'part')
|
|
StockItem = self.old_state.apps.get_model('stock', 'stockitem')
|
|
|
|
# Create a base part
|
|
my_part = Part.objects.create(
|
|
name='PART-123',
|
|
description='Some part',
|
|
active=True,
|
|
trackable=True,
|
|
level=0,
|
|
tree_id=0,
|
|
lft=0, rght=0
|
|
)
|
|
|
|
# Create some serialized stock items
|
|
for sn in range(10, 20):
|
|
StockItem.objects.create(
|
|
part=my_part,
|
|
quantity=1,
|
|
serial=sn,
|
|
level=0,
|
|
tree_id=0,
|
|
lft=0, rght=0
|
|
)
|
|
|
|
# Create a stock item with a very large serial number
|
|
item = StockItem.objects.create(
|
|
part=my_part,
|
|
quantity=1,
|
|
serial='9999999999999999999999999999999999999999999999999999999999999',
|
|
level=0,
|
|
tree_id=0,
|
|
lft=0, rght=0
|
|
)
|
|
|
|
self.big_ref_pk = item.pk
|
|
|
|
def test_migrations(self):
|
|
"""Test that the migrations have been applied correctly"""
|
|
|
|
StockItem = self.new_state.apps.get_model('stock', 'stockitem')
|
|
|
|
# Check that the serial number integer conversion has been applied correctly
|
|
for sn in range(10, 20):
|
|
item = StockItem.objects.get(serial_int=sn)
|
|
|
|
self.assertEqual(item.serial, str(sn))
|
|
|
|
big_ref_item = StockItem.objects.get(pk=self.big_ref_pk)
|
|
|
|
# Check that the StockItem maximum serial number
|
|
self.assertEqual(big_ref_item.serial, '9999999999999999999999999999999999999999999999999999999999999')
|
|
self.assertEqual(big_ref_item.serial_int, 0x7fffffff)
|