Short-circuit the custom migration if there are no SupplierPart objects

- This allows the unit testing to run!
This commit is contained in:
Oliver Walters 2020-04-13 19:46:57 +10:00
parent 2839f94773
commit f243b567fd
2 changed files with 12 additions and 2 deletions

View File

@ -15,8 +15,6 @@ class StatusCode:
Render the value as a label. Render the value as a label.
""" """
print("Rendering:", key, cls.options)
# If the key cannot be found, pass it back # If the key cannot be found, pass it back
if key not in cls.options.keys(): if key not in cls.options.keys():
return key return key

View File

@ -21,6 +21,12 @@ def reverse_association(apps, schema_editor):
into the 'manufacturer_name' field. into the 'manufacturer_name' field.
""" """
# Exit if there are no SupplierPart objects
# This crucial otherwise the unit test suite fails!
if SupplierPart.objects.count() == 0:
print("No SupplierPart objects - skipping")
return
print("Reversing migration for manufacturer association") print("Reversing migration for manufacturer association")
try: try:
@ -49,6 +55,12 @@ def associate_manufacturers(apps, schema_editor):
It uses fuzzy pattern matching to help the user out as much as possible. It uses fuzzy pattern matching to help the user out as much as possible.
""" """
# Exit if there are no SupplierPart objects
# This crucial otherwise the unit test suite fails!
if SupplierPart.objects.count() == 0:
print("No SupplierPart objects - skipping")
return
# Link a 'manufacturer_name' to a 'Company' # Link a 'manufacturer_name' to a 'Company'
links = {} links = {}