From 6c2eb959a6a63356bfd38aac65db5f68c2ab52b5 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 4 Oct 2020 00:34:22 +1000 Subject: [PATCH] More unit testing --- InvenTree/users/models.py | 72 +++++++++++++++++++-------------------- InvenTree/users/tests.py | 28 +++++++++++++++ 2 files changed, 64 insertions(+), 36 deletions(-) diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index 9395f3e1f2..403dc94291 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -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', ] } diff --git a/InvenTree/users/tests.py b/InvenTree/users/tests.py index 3687762fba..6c088441c9 100644 --- a/InvenTree/users/tests.py +++ b/InvenTree/users/tests.py @@ -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) \ No newline at end of file