More unit testing

This commit is contained in:
Oliver Walters 2020-10-04 00:34:22 +10:00
parent 2039100d3e
commit 6c2eb959a6
2 changed files with 64 additions and 36 deletions

View File

@ -38,54 +38,54 @@ class RuleSet(models.Model):
RULESET_MODELS = { RULESET_MODELS = {
'general': [ 'general': [
'part.partstar', 'part_partstar',
], ],
'admin': [ 'admin': [
'auth.group', 'auth_group',
'auth.user', 'auth_user',
'auth.permission', 'auth_permission',
'authtoken.token', 'authtoken_token',
], ],
'part': [ 'part': [
'part.part', 'part_part',
'part.bomitem', 'part_bomitem',
'part.partcategory', 'part_partcategory',
'part.partattachment', 'part_partattachment',
'part.partsellpricebreak', 'part_partsellpricebreak',
'part.parttesttemplate', 'part_parttesttemplate',
'part.partparametertemplate', 'part_partparametertemplate',
'part.partparameter', 'part_partparameter',
], ],
'stock': [ 'stock': [
'stock.stockitem', 'stock_stockitem',
'stock.stocklocation', 'stock_stocklocation',
'stock.stockitemattachment', 'stock_stockitemattachment',
'stock.stockitemtracking', 'stock_stockitemtracking',
'stock.stockitemtestresult', 'stock_stockitemtestresult',
], ],
'build': [ 'build': [
'part.part', 'part_part',
'part.partcategory', 'part_partcategory',
'part.bomitem', 'part_bomitem',
'build.build', 'build_build',
'build.builditem', 'build_builditem',
'stock.stockitem', 'stock_stockitem',
'stock.stocklocation', 'stock_stocklocation',
], ],
'purchase_order': [ 'purchase_order': [
'company.company', 'company_company',
'company.supplierpart', 'part_supplierpart',
'company.supplierpricebreak', 'part_supplierpricebreak',
'order.purchaseorder', 'order_purchaseorder',
'order.purchaseorderattachment', 'order_purchaseorderattachment',
'order.purchaseorderlineitem', 'order_purchaseorderlineitem',
], ],
'sales_order': [ 'sales_order': [
'company.company', 'company_company',
'order.salesorder', 'order_salesorder',
'order.salesorderattachment', 'order_salesorderattachment',
'order.salesorderlineitem', 'order_salesorderlineitem',
'order.salesorderallocation', 'order_salesorderallocation',
] ]
} }

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from django.test import TestCase from django.test import TestCase
from django.apps import apps
from users.models import RuleSet from users.models import RuleSet
@ -44,3 +45,30 @@ class RuleSetModelTest(TestCase):
self.assertEqual(len(extra), 0) self.assertEqual(len(extra), 0)
self.assertEqual(len(empty), 0) self.assertEqual(len(empty), 0)
def test_model_names(self):
"""
Test that each model defined in the rulesets is valid,
based on the database schema!
"""
available_models = apps.get_models()
available_tables = []
for model in available_models:
table_name = model.objects.model._meta.db_table
available_tables.append(table_name)
errors = 0
# Now check that each defined model is a valid table name
for key in RuleSet.RULESET_MODELS.keys():
models = RuleSet.RULESET_MODELS[key]
for m in models:
if m not in available_tables:
print("{n} is not a valid database table".format(n=m))
errors += 1
self.assertEqual(errors, 0)