mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 21:38:48 +00:00
Add some unit testing
This commit is contained in:
parent
6bc5fe2497
commit
2039100d3e
@ -38,4 +38,5 @@ class CompanyConfig(AppConfig):
|
|||||||
company.image = None
|
company.image = None
|
||||||
company.save()
|
company.save()
|
||||||
except (OperationalError, ProgrammingError):
|
except (OperationalError, ProgrammingError):
|
||||||
print("Could not generate Company thumbnails")
|
# Getting here probably meant the database was in test mode
|
||||||
|
pass
|
||||||
|
@ -24,7 +24,6 @@ def reverse_association(apps, schema_editor):
|
|||||||
# Exit if there are no SupplierPart objects
|
# Exit if there are no SupplierPart objects
|
||||||
# This crucial otherwise the unit test suite fails!
|
# This crucial otherwise the unit test suite fails!
|
||||||
if SupplierPart.objects.count() == 0:
|
if SupplierPart.objects.count() == 0:
|
||||||
print("No SupplierPart objects - skipping")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
print("Reversing migration for manufacturer association")
|
print("Reversing migration for manufacturer association")
|
||||||
@ -105,7 +104,6 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
# Exit if there are no SupplierPart objects
|
# Exit if there are no SupplierPart objects
|
||||||
# This crucial otherwise the unit test suite fails!
|
# This crucial otherwise the unit test suite fails!
|
||||||
if SupplierPart.objects.count() == 0:
|
if SupplierPart.objects.count() == 0:
|
||||||
print("No SupplierPart objects - skipping")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Link a 'manufacturer_name' to a 'Company'
|
# Link a 'manufacturer_name' to a 'Company'
|
||||||
|
@ -37,4 +37,4 @@ class PartConfig(AppConfig):
|
|||||||
part.image = None
|
part.image = None
|
||||||
part.save()
|
part.save()
|
||||||
except (OperationalError, ProgrammingError):
|
except (OperationalError, ProgrammingError):
|
||||||
print("Could not generate Part thumbnails")
|
pass
|
||||||
|
@ -28,9 +28,7 @@ class RuleSet(models.Model):
|
|||||||
('part', _('Parts')),
|
('part', _('Parts')),
|
||||||
('stock', _('Stock')),
|
('stock', _('Stock')),
|
||||||
('build', _('Build Orders')),
|
('build', _('Build Orders')),
|
||||||
('supplier', _('Suppliers')),
|
|
||||||
('purchase_order', _('Purchase Orders')),
|
('purchase_order', _('Purchase Orders')),
|
||||||
('customer', _('Customers')),
|
|
||||||
('sales_order', _('Sales Orders')),
|
('sales_order', _('Sales Orders')),
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -73,6 +71,21 @@ class RuleSet(models.Model):
|
|||||||
'build.builditem',
|
'build.builditem',
|
||||||
'stock.stockitem',
|
'stock.stockitem',
|
||||||
'stock.stocklocation',
|
'stock.stocklocation',
|
||||||
|
],
|
||||||
|
'purchase_order': [
|
||||||
|
'company.company',
|
||||||
|
'company.supplierpart',
|
||||||
|
'company.supplierpricebreak',
|
||||||
|
'order.purchaseorder',
|
||||||
|
'order.purchaseorderattachment',
|
||||||
|
'order.purchaseorderlineitem',
|
||||||
|
],
|
||||||
|
'sales_order': [
|
||||||
|
'company.company',
|
||||||
|
'order.salesorder',
|
||||||
|
'order.salesorderattachment',
|
||||||
|
'order.salesorderlineitem',
|
||||||
|
'order.salesorderallocation',
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,10 +132,11 @@ class RuleSet(models.Model):
|
|||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def get_models(self):
|
def get_models(self):
|
||||||
|
"""
|
||||||
|
Return the database tables / models that this ruleset covers.
|
||||||
|
"""
|
||||||
|
|
||||||
models = {
|
return self.RULESET_MODELS.get(self.name, [])
|
||||||
''
|
|
||||||
}
|
|
||||||
|
|
||||||
def update_group_roles(group):
|
def update_group_roles(group):
|
||||||
"""
|
"""
|
||||||
@ -157,4 +171,4 @@ def update_group_roles(group):
|
|||||||
@receiver(post_save, sender=Group)
|
@receiver(post_save, sender=Group)
|
||||||
def create_missing_rule_sets(sender, instance, **kwargs):
|
def create_missing_rule_sets(sender, instance, **kwargs):
|
||||||
|
|
||||||
update_group_roles(instance)
|
update_group_roles(instance)
|
||||||
|
@ -1,4 +1,46 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from users.models import RuleSet
|
||||||
|
|
||||||
|
|
||||||
|
class RuleSetModelTest(TestCase):
|
||||||
|
"""
|
||||||
|
Some simplistic tests to ensure the RuleSet model is setup correctly.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_ruleset_models(self):
|
||||||
|
|
||||||
|
keys = RuleSet.RULESET_MODELS.keys()
|
||||||
|
|
||||||
|
# Check if there are any rulesets which do not have models defined
|
||||||
|
|
||||||
|
missing = [name for name in RuleSet.RULESET_NAMES if name not in keys]
|
||||||
|
|
||||||
|
if len(missing) > 0:
|
||||||
|
print("The following rulesets do not have models assigned:")
|
||||||
|
for m in missing:
|
||||||
|
print("-", m)
|
||||||
|
|
||||||
|
# Check if models have been defined for a ruleset which is incorrect
|
||||||
|
extra = [name for name in keys if name not in RuleSet.RULESET_NAMES]
|
||||||
|
|
||||||
|
if len(extra) > 0:
|
||||||
|
print("The following rulesets have been improperly added to RULESET_MODELS:")
|
||||||
|
for e in extra:
|
||||||
|
print("-", e)
|
||||||
|
|
||||||
|
# Check that each ruleset has models assigned
|
||||||
|
empty = [key for key in keys if len(RuleSet.RULESET_MODELS[key]) == 0]
|
||||||
|
|
||||||
|
if len(empty) > 0:
|
||||||
|
print("The following rulesets have empty entries in RULESET_MODELS:")
|
||||||
|
for e in empty:
|
||||||
|
print("-", e)
|
||||||
|
|
||||||
|
self.assertEqual(len(missing), 0)
|
||||||
|
self.assertEqual(len(extra), 0)
|
||||||
|
self.assertEqual(len(empty), 0)
|
||||||
|
|
||||||
# from django.test import TestCase
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user