2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-14 02:55:41 +00:00

Fixes for circlular imports

This commit is contained in:
Oliver
2023-05-13 22:59:09 +10:00
parent 68a083d8db
commit 26226fc795
23 changed files with 50 additions and 49 deletions

View File

@ -7,6 +7,7 @@ import re
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
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
@ -337,3 +338,8 @@ class InvenTreeAPITestCase(ExchangeRateMixin, UserMixin, APITestCase):
data.append(entry)
return data
class InvenTreeTestCase(ExchangeRateMixin, UserMixin, TestCase):
"""Testcase with user setup buildin."""
pass

View File

@ -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.api_tester import InvenTreeTestCase # pragma: no cover
class RenderJavascriptFiles(InvenTreeTestCase): # pragma: no cover

View File

@ -19,7 +19,6 @@ 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
@ -31,13 +30,8 @@ from djmoney.money import Money
from PIL import Image
import common.models
import common.settings
import InvenTree.version
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')
@ -81,12 +75,12 @@ def constructPathString(path, max_chars=250):
def getMediaUrl(filename):
"""Return the qualified access path for the given file, under the media directory."""
return os.path.join(MEDIA_URL, str(filename))
return os.path.join(settings.MEDIA_URL, str(filename))
def getStaticUrl(filename):
"""Return the qualified access path for the given file, under the static media directory."""
return os.path.join(STATIC_URL, str(filename))
return os.path.join(settings.STATIC_URL, str(filename))
def construct_absolute_url(*arg, **kwargs):
@ -470,7 +464,7 @@ def decimal2money(d, currency=None):
A Money object from the input(s)
"""
if not currency:
currency = currency_code_default()
currency = common.settings.currency_code_default()
return Money(d, currency)
@ -1091,12 +1085,7 @@ 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):
def notify_responsible(instance, sender, content=None, exclude=None):
"""Notify all responsible parties of a change in an instance.
Parses the supplied content with the provided instance and sender and sends a notification to all responsible users,
@ -1108,6 +1097,12 @@ def notify_responsible(instance, sender, content: NotificationBody = InvenTreeNo
content (NotificationBody, optional): _description_. Defaults to InvenTreeNotificationBodies.NewOrder.
exclude (User, optional): User instance that should be excluded. Defaults to None.
"""
import common.notifications
if content is None:
content = common.notifications.InvenTreeNotificationBodies.NewOrder
if instance.responsible is not None:
# Setup context for notification parsing
content_context = {
@ -1130,7 +1125,7 @@ def notify_responsible(instance, sender, content: NotificationBody = InvenTreeNo
}
# Create notification
trigger_notification(
common.notifications.trigger_notification(
instance,
content.slug.format(**content_context),
targets=[instance.responsible],

View File

@ -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.api_tester import InvenTreeAPITestCase, InvenTreeTestCase
from users.models import RuleSet, update_group_roles

View File

@ -6,8 +6,8 @@ from django.urls import reverse
from error_report.models import Error
from InvenTree.api_tester import InvenTreeTestCase
from InvenTree.exceptions import log_error
from InvenTree.helpers import InvenTreeTestCase
class MiddlewareTests(InvenTreeTestCase):

View File

@ -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.api_tester import InvenTreeTestCase
class ViewTests(InvenTreeTestCase):

View File

@ -25,6 +25,7 @@ from InvenTree.status_codes import BuildStatus, StockStatus, StockHistoryCode
from build.validators import generate_next_build_reference, validate_build_order_reference
import common.models
import InvenTree.fields
import InvenTree.helpers
import InvenTree.models
@ -299,7 +300,7 @@ class Build(MPTTModel, InvenTree.models.InvenTreeBarcodeMixin, InvenTree.models.
)
project_code = models.ForeignKey(
'common.ProjectCode',
common.models.ProjectCode,
on_delete=models.SET_NULL,
blank=True, null=True,
verbose_name=_('Project Code'),

View File

@ -4,7 +4,7 @@ from django.urls import reverse
from datetime import datetime, timedelta
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
from .models import Build
from stock.models import StockItem

View File

@ -8,12 +8,12 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.utils.translation import gettext_lazy as _
import common.models
import InvenTree.helpers
from common.models import NotificationEntry, NotificationMessage
import plugin.models
import users.models
from InvenTree.ready import isImportingData
from plugin import registry
from plugin.models import NotificationUserSetting, PluginConfig
from users.models import Owner
logger = logging.getLogger('inventree')
@ -142,7 +142,7 @@ class NotificationMethod:
def usersetting(self, target):
"""Returns setting for this method for a given user."""
return NotificationUserSetting.get_setting(f'NOTIFICATION_METHOD_{self.METHOD_NAME.upper()}', user=target, method=self.METHOD_NAME)
return plugin.models.NotificationUserSetting.get_setting(f'NOTIFICATION_METHOD_{self.METHOD_NAME.upper()}', user=target, method=self.METHOD_NAME)
# endregion
@ -216,7 +216,7 @@ class MethodStorageClass:
# make sure the setting exists
self.user_settings[new_key] = item.USER_SETTING
NotificationUserSetting.get_setting(
plugin.models.NotificationUserSetting.get_setting(
key=new_key,
user=user,
method=item.METHOD_NAME,
@ -247,7 +247,7 @@ class UIMessageNotification(SingleNotificationMethod):
def send(self, target):
"""Send a UI notification to a user."""
NotificationMessage.objects.create(
common.models.NotificationMessage.objects.create(
target_object=self.obj,
source_object=target,
user=target,
@ -338,7 +338,7 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
# Check if we have notified recently...
delta = timedelta(days=1)
if NotificationEntry.check_recent(category, obj_ref_value, delta):
if common.models.NotificationEntry.check_recent(category, obj_ref_value, delta):
logger.info(f"Notification '{category}' has recently been sent for '{str(obj)}' - SKIPPING")
return
@ -369,7 +369,7 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
if user not in target_exclude:
target_users.add(user)
# Owner instance (either 'user' or 'group' is provided)
elif isinstance(target, Owner):
elif isinstance(target, users.models.Owner):
for owner in target.get_related_owners(include_group=False):
user = owner.owner
if user not in target_exclude:
@ -398,12 +398,12 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
logger.error(error)
# Set delivery flag
NotificationEntry.notify(category, obj_ref_value)
common.models.NotificationEntry.notify(category, obj_ref_value)
else:
logger.info(f"No possible users for notification '{category}'")
def trigger_superuser_notification(plugin: PluginConfig, msg: str):
def trigger_superuser_notification(plugin: plugin.models.PluginConfig, msg: str):
"""Trigger a notification to all superusers.
Args:

View File

@ -14,8 +14,8 @@ from django.urls import reverse
import PIL
from InvenTree.api_tester import InvenTreeAPITestCase, PluginMixin
from InvenTree.helpers import InvenTreeTestCase, str2bool
from InvenTree.api_tester import (InvenTreeAPITestCase, InvenTreeTestCase,
PluginMixin, str2bool)
from plugin import registry
from plugin.models import NotificationUserSetting

View File

@ -2,7 +2,7 @@
from django.urls import reverse
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
class CompanyViewTest(InvenTreeTestCase):

View File

@ -2,7 +2,7 @@
from django.urls import reverse
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
class OrderViewTestCase(InvenTreeTestCase):

View File

@ -4,7 +4,7 @@ import csv
from django.urls import reverse
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
class BomExportTest(InvenTreeTestCase):

View File

@ -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.api_tester import InvenTreeTestCase
from .models import (Part, PartCategory, PartCategoryStar, PartRelated,
PartStar, PartStocktake, PartTestTemplate,

View File

@ -10,7 +10,7 @@ import company.models
import order.models
import part.models
import stock.models
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
from InvenTree.status_codes import PurchaseOrderStatus

View File

@ -2,7 +2,7 @@
from django.urls import reverse
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
from .models import Part

View File

@ -2,7 +2,7 @@
from django.test import TestCase
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
from plugin import InvenTreePlugin
from plugin.mixins import ActionMixin

View File

@ -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.api_tester import InvenTreeTestCase
from plugin import InvenTreePlugin
from plugin.base.integration.mixins import PanelMixin
from plugin.helpers import MixinNotImplementedError

View File

@ -1,6 +1,6 @@
"""Unit tests for action plugins."""
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
class SampleIntegrationPluginTests(InvenTreeTestCase):

View File

@ -1,6 +1,6 @@
"""Unit tests for action plugins."""
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
from plugin.samples.integration.simpleactionplugin import SimpleActionPlugin

View File

@ -4,7 +4,7 @@ from django.contrib.auth.models import Group
from django.urls import reverse
from common.models import InvenTreeSetting
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
from InvenTree.status_codes import StockStatus
from stock.models import StockItem, StockLocation
from users.models import Owner

View File

@ -9,7 +9,7 @@ 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.api_tester import InvenTreeTestCase
from InvenTree.status_codes import StockHistoryCode
from order.models import SalesOrder
from part.models import Part

View File

@ -7,7 +7,7 @@ from django.urls import reverse
from rest_framework.authtoken.models import Token
from InvenTree.helpers import InvenTreeTestCase
from InvenTree.api_tester import InvenTreeTestCase
from users.models import Owner, RuleSet