From 4785f465e8bfef8cd262fefe9ec33b927da6a57e Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 17 May 2023 07:35:26 +1000 Subject: [PATCH] Cleanup / consolidate unit testing code (#4831) - Move testing code out of helpers.py - Create new file unit_test.py --- InvenTree/InvenTree/ci_render_js.py | 2 +- InvenTree/InvenTree/helpers.py | 78 ------------------ InvenTree/InvenTree/test_api.py | 3 +- InvenTree/InvenTree/test_middleware.py | 2 +- InvenTree/InvenTree/test_views.py | 2 +- InvenTree/InvenTree/tests.py | 9 ++- .../InvenTree/{api_tester.py => unit_test.py} | 80 ++++++++++++++++++- InvenTree/build/test_api.py | 2 +- InvenTree/build/test_migrations.py | 10 +-- InvenTree/build/tests.py | 2 +- InvenTree/common/tests.py | 5 +- InvenTree/company/test_api.py | 2 +- InvenTree/company/test_migrations.py | 6 +- InvenTree/company/test_views.py | 2 +- InvenTree/label/test_api.py | 2 +- InvenTree/label/tests.py | 2 +- InvenTree/order/test_api.py | 2 +- InvenTree/order/test_views.py | 2 +- InvenTree/part/test_api.py | 2 +- InvenTree/part/test_bom_export.py | 2 +- InvenTree/part/test_bom_import.py | 2 +- InvenTree/part/test_migrations.py | 8 +- InvenTree/part/test_part.py | 2 +- InvenTree/part/test_pricing.py | 2 +- InvenTree/part/test_views.py | 2 +- InvenTree/plugin/base/action/test_action.py | 2 +- .../plugin/base/barcodes/test_barcode.py | 2 +- .../plugin/base/integration/test_mixins.py | 2 +- .../plugin/base/label/test_label_mixin.py | 2 +- InvenTree/plugin/base/locate/test_locate.py | 2 +- .../barcodes/test_inventree_barcode.py | 2 +- .../plugin/samples/integration/test_sample.py | 2 +- .../integration/test_simpleactionplugin.py | 2 +- .../samples/locate/test_locate_sample.py | 2 +- InvenTree/plugin/test_api.py | 2 +- InvenTree/report/tests.py | 2 +- InvenTree/stock/test_api.py | 2 +- InvenTree/stock/test_migrations.py | 6 +- InvenTree/stock/test_views.py | 2 +- InvenTree/stock/tests.py | 2 +- InvenTree/users/test_api.py | 2 +- InvenTree/users/test_migrations.py | 6 +- InvenTree/users/tests.py | 2 +- 43 files changed, 138 insertions(+), 139 deletions(-) rename InvenTree/InvenTree/{api_tester.py => unit_test.py} (82%) diff --git a/InvenTree/InvenTree/ci_render_js.py b/InvenTree/InvenTree/ci_render_js.py index 5c7c36a30c..59ccffac60 100644 --- a/InvenTree/InvenTree/ci_render_js.py +++ b/InvenTree/InvenTree/ci_render_js.py @@ -6,7 +6,7 @@ Only used for testing the js files! - This file is omited from coverage. import os # pragma: no cover import pathlib # pragma: no cover -from InvenTree.helpers import InvenTreeTestCase # pragma: no cover +from InvenTree.unit_test import InvenTreeTestCase # pragma: no cover class RenderJavascriptFiles(InvenTreeTestCase): # pragma: no cover diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 693c3c9241..0bdf722b36 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -8,18 +8,15 @@ import os import os.path import re from decimal import Decimal, InvalidOperation -from pathlib import Path from wsgiref.util import FileWrapper from django.conf import settings -from django.contrib.auth.models import Permission from django.contrib.staticfiles.storage import StaticFilesStorage from django.core.exceptions import FieldError, ValidationError from django.core.files.storage import default_storage from django.core.validators import URLValidator from django.db.utils import OperationalError, ProgrammingError from django.http import StreamingHttpResponse -from django.test import TestCase from django.utils.translation import gettext_lazy as _ import moneyed.localization @@ -36,7 +33,6 @@ from common.notifications import (InvenTreeNotificationBodies, NotificationBody, trigger_notification) from common.settings import currency_code_default -from .api_tester import ExchangeRateMixin, UserMixin from .settings import MEDIA_URL, STATIC_URL logger = logging.getLogger('inventree') @@ -850,75 +846,6 @@ def validateFilterString(value, model=None): return results -def addUserPermission(user, permission): - """Shortcut function for adding a certain permission to a user.""" - perm = Permission.objects.get(codename=permission) - user.user_permissions.add(perm) - - -def addUserPermissions(user, permissions): - """Shortcut function for adding multiple permissions to a user.""" - for permission in permissions: - addUserPermission(user, permission) - - -def getMigrationFileNames(app): - """Return a list of all migration filenames for provided app.""" - local_dir = Path(__file__).parent - files = local_dir.joinpath('..', app, 'migrations').iterdir() - - # Regex pattern for migration files - regex = re.compile(r"^[\d]+_.*\.py$") - - migration_files = [] - - for f in files: - if regex.match(f.name): - migration_files.append(f.name) - - return migration_files - - -def getOldestMigrationFile(app, exclude_extension=True, ignore_initial=True): - """Return the filename associated with the oldest migration.""" - oldest_num = -1 - oldest_file = None - - for f in getMigrationFileNames(app): - - if ignore_initial and f.startswith('0001_initial'): - continue - - num = int(f.split('_')[0]) - - if oldest_file is None or num < oldest_num: - oldest_num = num - oldest_file = f - - if exclude_extension: - oldest_file = oldest_file.replace('.py', '') - - return oldest_file - - -def getNewestMigrationFile(app, exclude_extension=True): - """Return the filename associated with the newest migration.""" - newest_file = None - newest_num = -1 - - for f in getMigrationFileNames(app): - num = int(f.split('_')[0]) - - if newest_file is None or num > newest_num: - newest_num = num - newest_file = f - - if exclude_extension: - newest_file = newest_file.replace('.py', '') - - return newest_file - - def clean_decimal(number): """Clean-up decimal value.""" # Check if empty @@ -1091,11 +1018,6 @@ def inheritors(cls): return subcls -class InvenTreeTestCase(ExchangeRateMixin, UserMixin, TestCase): - """Testcase with user setup buildin.""" - pass - - def notify_responsible(instance, sender, content: NotificationBody = InvenTreeNotificationBodies.NewOrder, exclude=None): """Notify all responsible parties of a change in an instance. diff --git a/InvenTree/InvenTree/test_api.py b/InvenTree/InvenTree/test_api.py index fb2209257c..81593a9e73 100644 --- a/InvenTree/InvenTree/test_api.py +++ b/InvenTree/InvenTree/test_api.py @@ -6,8 +6,7 @@ from django.urls import reverse from rest_framework import status -from InvenTree.api_tester import InvenTreeAPITestCase -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeAPITestCase, InvenTreeTestCase from users.models import RuleSet, update_group_roles diff --git a/InvenTree/InvenTree/test_middleware.py b/InvenTree/InvenTree/test_middleware.py index fcfc4fe933..459ea6e112 100644 --- a/InvenTree/InvenTree/test_middleware.py +++ b/InvenTree/InvenTree/test_middleware.py @@ -7,7 +7,7 @@ from django.urls import reverse from error_report.models import Error from InvenTree.exceptions import log_error -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase class MiddlewareTests(InvenTreeTestCase): diff --git a/InvenTree/InvenTree/test_views.py b/InvenTree/InvenTree/test_views.py index f3630229b7..f90cae791e 100644 --- a/InvenTree/InvenTree/test_views.py +++ b/InvenTree/InvenTree/test_views.py @@ -5,7 +5,7 @@ import os from django.contrib.auth import get_user_model from django.urls import reverse -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase class ViewTests(InvenTreeTestCase): diff --git a/InvenTree/InvenTree/tests.py b/InvenTree/InvenTree/tests.py index 8c8ca42892..83027fe4ef 100644 --- a/InvenTree/InvenTree/tests.py +++ b/InvenTree/InvenTree/tests.py @@ -24,6 +24,7 @@ import InvenTree.tasks from common.models import InvenTreeSetting from common.settings import currency_codes from InvenTree.sanitizer import sanitize_svg +from InvenTree.unit_test import InvenTreeTestCase from part.models import Part, PartCategory from stock.models import StockItem, StockLocation @@ -711,7 +712,7 @@ class TestStatus(TestCase): self.assertEqual(ready.isImportingData(), False) -class TestSettings(helpers.InvenTreeTestCase): +class TestSettings(InvenTreeTestCase): """Unit tests for settings.""" superuser = True @@ -850,7 +851,7 @@ class TestSettings(helpers.InvenTreeTestCase): self.assertEqual(config.get_setting(TEST_ENV_NAME, None, typecast=dict), {}) -class TestInstanceName(helpers.InvenTreeTestCase): +class TestInstanceName(InvenTreeTestCase): """Unit tests for instance name.""" def test_instance_name(self): @@ -878,7 +879,7 @@ class TestInstanceName(helpers.InvenTreeTestCase): self.assertEqual(site_obj.domain, 'http://127.1.2.3') -class TestOffloadTask(helpers.InvenTreeTestCase): +class TestOffloadTask(InvenTreeTestCase): """Tests for offloading tasks to the background worker""" fixtures = [ @@ -975,7 +976,7 @@ class TestOffloadTask(helpers.InvenTreeTestCase): self.assertTrue(result) -class BarcodeMixinTest(helpers.InvenTreeTestCase): +class BarcodeMixinTest(InvenTreeTestCase): """Tests for the InvenTreeBarcodeMixin mixin class""" def test_barcode_model_type(self): diff --git a/InvenTree/InvenTree/api_tester.py b/InvenTree/InvenTree/unit_test.py similarity index 82% rename from InvenTree/InvenTree/api_tester.py rename to InvenTree/InvenTree/unit_test.py index 56b691d69d..c2926dec90 100644 --- a/InvenTree/InvenTree/api_tester.py +++ b/InvenTree/InvenTree/unit_test.py @@ -1,12 +1,14 @@ -"""Helper functions for performing API unit tests.""" +"""Helper functions for unit testing / CI""" import csv import io import re +from pathlib import Path from django.contrib.auth import get_user_model -from django.contrib.auth.models import Group +from django.contrib.auth.models import Group, Permission from django.http.response import StreamingHttpResponse +from django.test import TestCase from djmoney.contrib.exchange.models import ExchangeBackend, Rate from rest_framework.test import APITestCase @@ -15,6 +17,75 @@ from plugin import registry from plugin.models import PluginConfig +def addUserPermission(user, permission): + """Shortcut function for adding a certain permission to a user.""" + perm = Permission.objects.get(codename=permission) + user.user_permissions.add(perm) + + +def addUserPermissions(user, permissions): + """Shortcut function for adding multiple permissions to a user.""" + for permission in permissions: + addUserPermission(user, permission) + + +def getMigrationFileNames(app): + """Return a list of all migration filenames for provided app.""" + local_dir = Path(__file__).parent + files = local_dir.joinpath('..', app, 'migrations').iterdir() + + # Regex pattern for migration files + regex = re.compile(r"^[\d]+_.*\.py$") + + migration_files = [] + + for f in files: + if regex.match(f.name): + migration_files.append(f.name) + + return migration_files + + +def getOldestMigrationFile(app, exclude_extension=True, ignore_initial=True): + """Return the filename associated with the oldest migration.""" + oldest_num = -1 + oldest_file = None + + for f in getMigrationFileNames(app): + + if ignore_initial and f.startswith('0001_initial'): + continue + + num = int(f.split('_')[0]) + + if oldest_file is None or num < oldest_num: + oldest_num = num + oldest_file = f + + if exclude_extension: + oldest_file = oldest_file.replace('.py', '') + + return oldest_file + + +def getNewestMigrationFile(app, exclude_extension=True): + """Return the filename associated with the newest migration.""" + newest_file = None + newest_num = -1 + + for f in getMigrationFileNames(app): + num = int(f.split('_')[0]) + + if newest_file is None or num > newest_num: + newest_num = num + newest_file = f + + if exclude_extension: + newest_file = newest_file.replace('.py', '') + + return newest_file + + class UserMixin: """Mixin to setup a user and login for tests. @@ -337,3 +408,8 @@ class InvenTreeAPITestCase(ExchangeRateMixin, UserMixin, APITestCase): data.append(entry) return data + + +class InvenTreeTestCase(ExchangeRateMixin, UserMixin, TestCase): + """Testcase with user setup buildin.""" + pass diff --git a/InvenTree/build/test_api.py b/InvenTree/build/test_api.py index fefafcf60d..d5bad81523 100644 --- a/InvenTree/build/test_api.py +++ b/InvenTree/build/test_api.py @@ -11,7 +11,7 @@ from build.models import Build, BuildItem from stock.models import StockItem from InvenTree.status_codes import BuildStatus, StockStatus -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase class TestBuildAPI(InvenTreeAPITestCase): diff --git a/InvenTree/build/test_migrations.py b/InvenTree/build/test_migrations.py index 1d04beb414..1072e2ae61 100644 --- a/InvenTree/build/test_migrations.py +++ b/InvenTree/build/test_migrations.py @@ -2,14 +2,14 @@ from django_test_migrations.contrib.unittest_case import MigratorTestCase -from InvenTree import helpers +from InvenTree import unit_test class TestForwardMigrations(MigratorTestCase): """Test entire schema migration sequence for the build app.""" - migrate_from = ('build', helpers.getOldestMigrationFile('build')) - migrate_to = ('build', helpers.getNewestMigrationFile('build')) + migrate_from = ('build', unit_test.getOldestMigrationFile('build')) + migrate_to = ('build', unit_test.getNewestMigrationFile('build')) def prepare(self): """Create initial data!""" @@ -58,7 +58,7 @@ class TestForwardMigrations(MigratorTestCase): class TestReferenceMigration(MigratorTestCase): """Test custom migration which adds 'reference' field to Build model.""" - migrate_from = ('build', helpers.getOldestMigrationFile('build')) + migrate_from = ('build', unit_test.getOldestMigrationFile('build')) migrate_to = ('build', '0018_build_reference') def prepare(self): @@ -113,7 +113,7 @@ class TestReferencePatternMigration(MigratorTestCase): """ migrate_from = ('build', '0019_auto_20201019_1302') - migrate_to = ('build', helpers.getNewestMigrationFile('build')) + migrate_to = ('build', unit_test.getNewestMigrationFile('build')) def prepare(self): """Create some initial data prior to migration""" diff --git a/InvenTree/build/tests.py b/InvenTree/build/tests.py index f197479d5c..196701729b 100644 --- a/InvenTree/build/tests.py +++ b/InvenTree/build/tests.py @@ -4,7 +4,7 @@ from django.urls import reverse from datetime import datetime, timedelta -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase from .models import Build from stock.models import StockItem diff --git a/InvenTree/common/tests.py b/InvenTree/common/tests.py index 27fef1c9c1..b4b32abfd0 100644 --- a/InvenTree/common/tests.py +++ b/InvenTree/common/tests.py @@ -14,8 +14,9 @@ from django.urls import reverse import PIL -from InvenTree.api_tester import InvenTreeAPITestCase, PluginMixin -from InvenTree.helpers import InvenTreeTestCase, str2bool +from InvenTree.helpers import str2bool +from InvenTree.unit_test import (InvenTreeAPITestCase, InvenTreeTestCase, + PluginMixin) from plugin import registry from plugin.models import NotificationUserSetting diff --git a/InvenTree/company/test_api.py b/InvenTree/company/test_api.py index 6865a1be99..e354b2f0d9 100644 --- a/InvenTree/company/test_api.py +++ b/InvenTree/company/test_api.py @@ -4,7 +4,7 @@ from django.urls import reverse from rest_framework import status -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase from .models import Company, Contact, SupplierPart diff --git a/InvenTree/company/test_migrations.py b/InvenTree/company/test_migrations.py index 4c8b0cb586..f957d17da3 100644 --- a/InvenTree/company/test_migrations.py +++ b/InvenTree/company/test_migrations.py @@ -2,14 +2,14 @@ from django_test_migrations.contrib.unittest_case import MigratorTestCase -from InvenTree import helpers +from InvenTree import unit_test class TestForwardMigrations(MigratorTestCase): """Unit testing class for testing 'company' app migrations""" - migrate_from = ('company', helpers.getOldestMigrationFile('company')) - migrate_to = ('company', helpers.getNewestMigrationFile('company')) + migrate_from = ('company', unit_test.getOldestMigrationFile('company')) + migrate_to = ('company', unit_test.getNewestMigrationFile('company')) def prepare(self): """Create some simple Company data, and ensure that it migrates OK.""" diff --git a/InvenTree/company/test_views.py b/InvenTree/company/test_views.py index b9e95af7e2..274162ccea 100644 --- a/InvenTree/company/test_views.py +++ b/InvenTree/company/test_views.py @@ -2,7 +2,7 @@ from django.urls import reverse -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase class CompanyViewTest(InvenTreeTestCase): diff --git a/InvenTree/label/test_api.py b/InvenTree/label/test_api.py index 3c94c89fb6..2bba71f723 100644 --- a/InvenTree/label/test_api.py +++ b/InvenTree/label/test_api.py @@ -2,7 +2,7 @@ from django.urls import reverse -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase class TestReportTests(InvenTreeAPITestCase): diff --git a/InvenTree/label/tests.py b/InvenTree/label/tests.py index 810b348b5d..6a94328605 100644 --- a/InvenTree/label/tests.py +++ b/InvenTree/label/tests.py @@ -9,8 +9,8 @@ from django.core.files.base import ContentFile from django.urls import reverse from common.models import InvenTreeSetting -from InvenTree.api_tester import InvenTreeAPITestCase from InvenTree.helpers import validateFilterString +from InvenTree.unit_test import InvenTreeAPITestCase from part.models import Part from stock.models import StockItem diff --git a/InvenTree/order/test_api.py b/InvenTree/order/test_api.py index 212036d148..1e0f5f6a2b 100644 --- a/InvenTree/order/test_api.py +++ b/InvenTree/order/test_api.py @@ -15,10 +15,10 @@ from rest_framework import status from common.settings import currency_codes from company.models import Company -from InvenTree.api_tester import InvenTreeAPITestCase from InvenTree.status_codes import (PurchaseOrderStatus, ReturnOrderLineStatus, ReturnOrderStatus, SalesOrderStatus, StockStatus) +from InvenTree.unit_test import InvenTreeAPITestCase from order import models from part.models import Part from stock.models import StockItem diff --git a/InvenTree/order/test_views.py b/InvenTree/order/test_views.py index d878cbc604..bb1e5bddf8 100644 --- a/InvenTree/order/test_views.py +++ b/InvenTree/order/test_views.py @@ -2,7 +2,7 @@ from django.urls import reverse -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase class OrderViewTestCase(InvenTreeTestCase): diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index af15ad5de7..d26bbd1374 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -18,9 +18,9 @@ import company.models import order.models from common.models import InvenTreeSetting from company.models import Company, SupplierPart -from InvenTree.api_tester import InvenTreeAPITestCase from InvenTree.status_codes import (BuildStatus, PurchaseOrderStatus, StockStatus) +from InvenTree.unit_test import InvenTreeAPITestCase from part.models import (BomItem, BomItemSubstitute, Part, PartCategory, PartCategoryParameterTemplate, PartParameterTemplate, PartRelated, PartStocktake) diff --git a/InvenTree/part/test_bom_export.py b/InvenTree/part/test_bom_export.py index c40b7607ed..e2f299dcc3 100644 --- a/InvenTree/part/test_bom_export.py +++ b/InvenTree/part/test_bom_export.py @@ -4,7 +4,7 @@ import csv from django.urls import reverse -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase class BomExportTest(InvenTreeTestCase): diff --git a/InvenTree/part/test_bom_import.py b/InvenTree/part/test_bom_import.py index 4d1d6f29e3..7f77d4254a 100644 --- a/InvenTree/part/test_bom_import.py +++ b/InvenTree/part/test_bom_import.py @@ -5,7 +5,7 @@ from django.urls import reverse import tablib -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase from part.models import Part diff --git a/InvenTree/part/test_migrations.py b/InvenTree/part/test_migrations.py index afa2078bf1..a20c14fa3e 100644 --- a/InvenTree/part/test_migrations.py +++ b/InvenTree/part/test_migrations.py @@ -2,14 +2,14 @@ from django_test_migrations.contrib.unittest_case import MigratorTestCase -from InvenTree import helpers +from InvenTree import unit_test class TestForwardMigrations(MigratorTestCase): """Test entire schema migration sequence for the part app.""" - migrate_from = ('part', helpers.getOldestMigrationFile('part')) - migrate_to = ('part', helpers.getNewestMigrationFile('part')) + migrate_from = ('part', unit_test.getOldestMigrationFile('part')) + migrate_to = ('part', unit_test.getNewestMigrationFile('part')) def prepare(self): """Create initial data.""" @@ -52,7 +52,7 @@ class TestBomItemMigrations(MigratorTestCase): """Tests for BomItem migrations""" migrate_from = ('part', '0002_auto_20190520_2204') - migrate_to = ('part', helpers.getNewestMigrationFile('part')) + migrate_to = ('part', unit_test.getNewestMigrationFile('part')) def prepare(self): """Create intial dataset""" diff --git a/InvenTree/part/test_part.py b/InvenTree/part/test_part.py index e1a7db6006..9718d606a9 100644 --- a/InvenTree/part/test_part.py +++ b/InvenTree/part/test_part.py @@ -14,7 +14,7 @@ from common.models import (InvenTreeSetting, InvenTreeUserSetting, NotificationEntry, NotificationMessage) from common.notifications import UIMessageNotification, storage from InvenTree import version -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase from .models import (Part, PartCategory, PartCategoryStar, PartRelated, PartStar, PartStocktake, PartTestTemplate, diff --git a/InvenTree/part/test_pricing.py b/InvenTree/part/test_pricing.py index e470b2389d..8859acca47 100644 --- a/InvenTree/part/test_pricing.py +++ b/InvenTree/part/test_pricing.py @@ -10,8 +10,8 @@ import company.models import order.models import part.models import stock.models -from InvenTree.helpers import InvenTreeTestCase from InvenTree.status_codes import PurchaseOrderStatus +from InvenTree.unit_test import InvenTreeTestCase class PartPricingTests(InvenTreeTestCase): diff --git a/InvenTree/part/test_views.py b/InvenTree/part/test_views.py index 5471da647b..a43bb91134 100644 --- a/InvenTree/part/test_views.py +++ b/InvenTree/part/test_views.py @@ -2,7 +2,7 @@ from django.urls import reverse -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase from .models import Part diff --git a/InvenTree/plugin/base/action/test_action.py b/InvenTree/plugin/base/action/test_action.py index d343af677a..7650658ca0 100644 --- a/InvenTree/plugin/base/action/test_action.py +++ b/InvenTree/plugin/base/action/test_action.py @@ -2,7 +2,7 @@ from django.test import TestCase -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase from plugin import InvenTreePlugin from plugin.mixins import ActionMixin diff --git a/InvenTree/plugin/base/barcodes/test_barcode.py b/InvenTree/plugin/base/barcodes/test_barcode.py index 97f43bbd9d..b3fa5a1a94 100644 --- a/InvenTree/plugin/base/barcodes/test_barcode.py +++ b/InvenTree/plugin/base/barcodes/test_barcode.py @@ -4,7 +4,7 @@ from django.urls import reverse from rest_framework import status -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase from stock.models import StockItem diff --git a/InvenTree/plugin/base/integration/test_mixins.py b/InvenTree/plugin/base/integration/test_mixins.py index c5e8c4e712..fde9df5352 100644 --- a/InvenTree/plugin/base/integration/test_mixins.py +++ b/InvenTree/plugin/base/integration/test_mixins.py @@ -8,7 +8,7 @@ from django.urls import include, re_path, reverse from error_report.models import Error -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase from plugin import InvenTreePlugin from plugin.base.integration.mixins import PanelMixin from plugin.helpers import MixinNotImplementedError diff --git a/InvenTree/plugin/base/label/test_label_mixin.py b/InvenTree/plugin/base/label/test_label_mixin.py index 1a16e2d8c8..2c69473dbc 100644 --- a/InvenTree/plugin/base/label/test_label_mixin.py +++ b/InvenTree/plugin/base/label/test_label_mixin.py @@ -8,7 +8,7 @@ from django.urls import reverse from PIL import Image from common.models import InvenTreeSetting -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase from label.models import PartLabel, StockItemLabel, StockLocationLabel from part.models import Part from plugin.base.label.mixins import LabelPrintingMixin diff --git a/InvenTree/plugin/base/locate/test_locate.py b/InvenTree/plugin/base/locate/test_locate.py index 32e8540fb2..227f7553ec 100644 --- a/InvenTree/plugin/base/locate/test_locate.py +++ b/InvenTree/plugin/base/locate/test_locate.py @@ -2,7 +2,7 @@ from django.urls import reverse -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase from plugin import InvenTreePlugin, MixinNotImplementedError, registry from plugin.base.locate.mixins import LocateMixin from stock.models import StockItem, StockLocation diff --git a/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py b/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py index d998f0172f..038030952c 100644 --- a/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py +++ b/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py @@ -4,7 +4,7 @@ from django.urls import reverse import part.models import stock.models -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase class TestInvenTreeBarcode(InvenTreeAPITestCase): diff --git a/InvenTree/plugin/samples/integration/test_sample.py b/InvenTree/plugin/samples/integration/test_sample.py index bd04377f97..1aad91928e 100644 --- a/InvenTree/plugin/samples/integration/test_sample.py +++ b/InvenTree/plugin/samples/integration/test_sample.py @@ -1,6 +1,6 @@ """Unit tests for action plugins.""" -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase class SampleIntegrationPluginTests(InvenTreeTestCase): diff --git a/InvenTree/plugin/samples/integration/test_simpleactionplugin.py b/InvenTree/plugin/samples/integration/test_simpleactionplugin.py index af5159458e..2599984a66 100644 --- a/InvenTree/plugin/samples/integration/test_simpleactionplugin.py +++ b/InvenTree/plugin/samples/integration/test_simpleactionplugin.py @@ -1,6 +1,6 @@ """Unit tests for action plugins.""" -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase from plugin.samples.integration.simpleactionplugin import SimpleActionPlugin diff --git a/InvenTree/plugin/samples/locate/test_locate_sample.py b/InvenTree/plugin/samples/locate/test_locate_sample.py index 2221accbd9..04f1d674bc 100644 --- a/InvenTree/plugin/samples/locate/test_locate_sample.py +++ b/InvenTree/plugin/samples/locate/test_locate_sample.py @@ -2,7 +2,7 @@ from django.urls import reverse -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase from plugin import InvenTreePlugin, registry from plugin.helpers import MixinNotImplementedError from plugin.mixins import LocateMixin diff --git a/InvenTree/plugin/test_api.py b/InvenTree/plugin/test_api.py index 919fdf9cb6..9804ebb532 100644 --- a/InvenTree/plugin/test_api.py +++ b/InvenTree/plugin/test_api.py @@ -4,7 +4,7 @@ from django.urls import reverse from rest_framework.exceptions import NotFound -from InvenTree.api_tester import InvenTreeAPITestCase, PluginMixin +from InvenTree.unit_test import InvenTreeAPITestCase, PluginMixin from plugin.api import check_plugin from plugin.models import PluginConfig diff --git a/InvenTree/report/tests.py b/InvenTree/report/tests.py index 4adb0aa12d..7f834ff87b 100644 --- a/InvenTree/report/tests.py +++ b/InvenTree/report/tests.py @@ -16,7 +16,7 @@ from PIL import Image import report.models as report_models from build.models import Build from common.models import InvenTreeSetting, InvenTreeUserSetting -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase from report.templatetags import barcode as barcode_tags from report.templatetags import report as report_tags from stock.models import StockItem, StockItemAttachment diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index de508af79c..38fb8f912b 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -16,8 +16,8 @@ from rest_framework import status import company.models import part.models from common.models import InvenTreeSetting -from InvenTree.api_tester import InvenTreeAPITestCase from InvenTree.status_codes import StockStatus +from InvenTree.unit_test import InvenTreeAPITestCase from part.models import Part from stock.models import StockItem, StockItemTestResult, StockLocation diff --git a/InvenTree/stock/test_migrations.py b/InvenTree/stock/test_migrations.py index af14af6f6d..51e00c8093 100644 --- a/InvenTree/stock/test_migrations.py +++ b/InvenTree/stock/test_migrations.py @@ -2,14 +2,14 @@ from django_test_migrations.contrib.unittest_case import MigratorTestCase -from InvenTree import helpers +from InvenTree import unit_test class TestSerialNumberMigration(MigratorTestCase): """Test data migration which updates serial numbers""" migrate_from = ('stock', '0067_alter_stockitem_part') - migrate_to = ('stock', helpers.getNewestMigrationFile('stock')) + migrate_to = ('stock', unit_test.getNewestMigrationFile('stock')) def prepare(self): """Create initial data for this migration""" @@ -73,7 +73,7 @@ class TestScheduledForDeletionMigration(MigratorTestCase): """Test data migration for removing 'scheduled_for_deletion' field""" migrate_from = ('stock', '0066_stockitem_scheduled_for_deletion') - migrate_to = ('stock', helpers.getNewestMigrationFile('stock')) + migrate_to = ('stock', unit_test.getNewestMigrationFile('stock')) def prepare(self): """Create some initial stock items""" diff --git a/InvenTree/stock/test_views.py b/InvenTree/stock/test_views.py index eed3023c6e..200541cbd8 100644 --- a/InvenTree/stock/test_views.py +++ b/InvenTree/stock/test_views.py @@ -4,8 +4,8 @@ from django.contrib.auth.models import Group from django.urls import reverse from common.models import InvenTreeSetting -from InvenTree.helpers import InvenTreeTestCase from InvenTree.status_codes import StockStatus +from InvenTree.unit_test import InvenTreeTestCase from stock.models import StockItem, StockLocation from users.models import Owner diff --git a/InvenTree/stock/tests.py b/InvenTree/stock/tests.py index b9f66f2df3..17ec2a9331 100644 --- a/InvenTree/stock/tests.py +++ b/InvenTree/stock/tests.py @@ -9,8 +9,8 @@ from django.test import override_settings from build.models import Build from common.models import InvenTreeSetting from company.models import Company -from InvenTree.helpers import InvenTreeTestCase from InvenTree.status_codes import StockHistoryCode +from InvenTree.unit_test import InvenTreeTestCase from order.models import SalesOrder from part.models import Part diff --git a/InvenTree/users/test_api.py b/InvenTree/users/test_api.py index 1f4d466ba4..017655646f 100644 --- a/InvenTree/users/test_api.py +++ b/InvenTree/users/test_api.py @@ -3,7 +3,7 @@ from django.contrib.auth.models import Group, User from django.urls import reverse -from InvenTree.api_tester import InvenTreeAPITestCase +from InvenTree.unit_test import InvenTreeAPITestCase class UserAPITests(InvenTreeAPITestCase): diff --git a/InvenTree/users/test_migrations.py b/InvenTree/users/test_migrations.py index 9cc8b404f8..9cc3b2af24 100644 --- a/InvenTree/users/test_migrations.py +++ b/InvenTree/users/test_migrations.py @@ -2,14 +2,14 @@ from django_test_migrations.contrib.unittest_case import MigratorTestCase -from InvenTree import helpers +from InvenTree import unit_test class TestForwardMigrations(MigratorTestCase): """Test entire schema migration sequence for the users app.""" - migrate_from = ('users', helpers.getOldestMigrationFile('users')) - migrate_to = ('users', helpers.getNewestMigrationFile('users')) + migrate_from = ('users', unit_test.getOldestMigrationFile('users')) + migrate_to = ('users', unit_test.getNewestMigrationFile('users')) def prepare(self): """Setup the initial state of the database before migrations""" diff --git a/InvenTree/users/tests.py b/InvenTree/users/tests.py index 20455ba696..2158209cf5 100644 --- a/InvenTree/users/tests.py +++ b/InvenTree/users/tests.py @@ -7,7 +7,7 @@ from django.urls import reverse from rest_framework.authtoken.models import Token -from InvenTree.helpers import InvenTreeTestCase +from InvenTree.unit_test import InvenTreeTestCase from users.models import Owner, RuleSet