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

View File

@ -2,6 +2,7 @@
from __future__ import unicode_literals
from django.test import TestCase
from django.apps import apps
from users.models import RuleSet
@ -44,3 +45,30 @@ class RuleSetModelTest(TestCase):
self.assertEqual(len(extra), 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)