Change settings._TEST_ENVIRONMENT to settings.TEST_ENVIRONMENT to address not-found issues during initialization

This commit is contained in:
Griatch 2023-11-26 14:25:12 +01:00
parent d353d87628
commit 8914e7b0b6
10 changed files with 26 additions and 35 deletions

View file

@ -27,6 +27,8 @@
into services for easier overriding (Volund) into services for easier overriding (Volund)
- [Feature][issue3307]: Add support for Attribute-categories when using the monitorhandler - [Feature][issue3307]: Add support for Attribute-categories when using the monitorhandler
with input funcs to monitor Attribute changes. with input funcs to monitor Attribute changes.
- [Fix] (Backwards incompatible): Change `settings._TEST_ENVIRONMENT` to
`settings.TEST_ENVIRONMENT` to address issues during refactored startup sequence.
- [Fix][pull3197]: Make sure Global scripts only start in one place, - [Fix][pull3197]: Make sure Global scripts only start in one place,
- [Fix][pull3324]: Make account-post-login-fail signal fire properly. Add - [Fix][pull3324]: Make account-post-login-fail signal fire properly. Add
`CUSTOM_SIGNAL` for adding one's own signals (Volund) `CUSTOM_SIGNAL` for adding one's own signals (Volund)

View file

@ -1246,7 +1246,7 @@ AMP_CLIENT_PROTOCOL_CLASS = "evennia.server.amp_client.AMPServerClientProtocol"
# don't change this manually, it can be checked from code to know if # don't change this manually, it can be checked from code to know if
# being run from a unit test (set by the evennia.utils.test_resources.BaseEvenniaTest # being run from a unit test (set by the evennia.utils.test_resources.BaseEvenniaTest
# and BaseEvenniaTestCase unit testing parents) # and BaseEvenniaTestCase unit testing parents)
_TEST_ENVIRONMENT = False TEST_ENVIRONMENT = False
###################################################################### ######################################################################
# Django extensions # Django extensions

View file

@ -6,7 +6,6 @@ import re
from django.conf import settings from django.conf import settings
from django.db.models import Q from django.db.models import Q
from django.db.models.fields import exceptions from django.db.models.fields import exceptions
from evennia.server import signals from evennia.server import signals
from evennia.typeclasses.managers import TypeclassManager, TypedObjectManager from evennia.typeclasses.managers import TypeclassManager, TypedObjectManager
from evennia.utils.utils import ( from evennia.utils.utils import (
@ -721,7 +720,7 @@ class ObjectDBManager(TypedObjectManager):
try: try:
home = dbid_to_obj(home_obj_or_dbref, self.model) home = dbid_to_obj(home_obj_or_dbref, self.model)
except self.model.DoesNotExist: except self.model.DoesNotExist:
if settings._TEST_ENVIRONMENT: if settings.TEST_ENVIRONMENT:
# this happens for databases where the #1 location is flushed during tests # this happens for databases where the #1 location is flushed during tests
home = None home = None
else: else:

View file

@ -9,10 +9,9 @@ Everything starts at handle_setup()
import time import time
import evennia
from django.conf import settings from django.conf import settings
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
import evennia
from evennia.accounts.models import AccountDB from evennia.accounts.models import AccountDB
from evennia.server.models import ServerConfig from evennia.server.models import ServerConfig
from evennia.utils import create, logger from evennia.utils import create, logger
@ -174,7 +173,7 @@ def reset_server():
also checks so the warm-reset mechanism works as it should. also checks so the warm-reset mechanism works as it should.
""" """
if settings._TEST_ENVIRONMENT: if settings.TEST_ENVIRONMENT:
return return
ServerConfig.objects.conf("server_epoch", time.time()) ServerConfig.objects.conf("server_epoch", time.time())

View file

@ -7,15 +7,14 @@ Sessionhandler for portal sessions.
import time import time
from collections import deque, namedtuple from collections import deque, namedtuple
import evennia
from django.conf import settings from django.conf import settings
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from twisted.internet import reactor
import evennia
from evennia.server.portal.amp import PCONN, PCONNSYNC, PDISCONN, PDISCONNALL from evennia.server.portal.amp import PCONN, PCONNSYNC, PDISCONN, PDISCONNALL
from evennia.server.sessionhandler import SessionHandler from evennia.server.sessionhandler import SessionHandler
from evennia.utils.logger import log_trace from evennia.utils.logger import log_trace
from evennia.utils.utils import class_from_module from evennia.utils.utils import class_from_module
from twisted.internet import reactor
# module import # module import
_MOD_IMPORT = None _MOD_IMPORT = None
@ -41,7 +40,7 @@ DUMMYSESSION = namedtuple("DummySession", ["sessid"])(0)
# ------------------------------------------------------------- # -------------------------------------------------------------
DOS_PROTECTION_MSG = _( DOS_PROTECTION_MSG = _(
"{servername} DoS protection is active." "You are queued to connect in {num} seconds ..." "{servername} DoS protection is active.You are queued to connect in {num} seconds ..."
) )
@ -231,7 +230,7 @@ class PortalSessionHandler(SessionHandler):
Disconnect all sessions, informing the Server. Disconnect all sessions, informing the Server.
""" """
if settings._TEST_ENVIRONMENT: if settings.TEST_ENVIRONMENT:
return return
def _callback(result, sessionhandler): def _callback(result, sessionhandler):

View file

@ -7,20 +7,19 @@ import time
import traceback import traceback
import django import django
import evennia
from django.conf import settings from django.conf import settings
from django.db import connection from django.db import connection
from django.db.utils import OperationalError from django.db.utils import OperationalError
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from evennia.utils import logger
from evennia.utils.utils import get_evennia_version, make_iter, mod_import
from twisted.application import internet from twisted.application import internet
from twisted.application.service import MultiService from twisted.application.service import MultiService
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
from twisted.internet.defer import Deferred from twisted.internet.defer import Deferred
from twisted.internet.task import LoopingCall from twisted.internet.task import LoopingCall
import evennia
from evennia.utils import logger
from evennia.utils.utils import get_evennia_version, make_iter, mod_import
_SA = object.__setattr__ _SA = object.__setattr__
@ -406,7 +405,7 @@ class EvenniaServerService(MultiService):
except Exception: except Exception:
# stop server if this happens. # stop server if this happens.
print(traceback.format_exc()) print(traceback.format_exc())
if not settings._TEST_ENVIRONMENT or not evennia.SESSION_HANDLER: if not settings.TEST_ENVIRONMENT or not evennia.SESSION_HANDLER:
print("Error in initial setup. Stopping Server + Portal.") print("Error in initial setup. Stopping Server + Portal.")
evennia.SESSION_HANDLER.portal_shutdown() evennia.SESSION_HANDLER.portal_shutdown()

View file

@ -4,11 +4,10 @@ Test the main server component
""" """
from unittest import TestCase from unittest import TestCase
import evennia
from django.test import override_settings from django.test import override_settings
from mock import DEFAULT, MagicMock, call, patch from mock import DEFAULT, MagicMock, call, patch
import evennia
@patch("evennia.server.service.LoopingCall", new=MagicMock()) @patch("evennia.server.service.LoopingCall", new=MagicMock())
class TestServer(TestCase): class TestServer(TestCase):
@ -148,7 +147,7 @@ class TestServer(TestCase):
for m in (mockscr, mockobj, mockacc, mockchan): for m in (mockscr, mockobj, mockacc, mockchan):
m.objects.filter.assert_called() m.objects.filter.assert_called()
@override_settings(_TEST_ENVIRONMENT=True) @override_settings(TEST_ENVIRONMENT=True)
def test_initial_setup(self): def test_initial_setup(self):
from evennia.utils.create import create_account from evennia.utils.create import create_account
@ -161,7 +160,7 @@ class TestServer(TestCase):
self.server.run_initial_setup() self.server.run_initial_setup()
acct.delete() acct.delete()
@override_settings(_TEST_ENVIRONMENT=True) @override_settings(TEST_ENVIRONMENT=True)
def test_initial_setup_retry(self): def test_initial_setup_retry(self):
from evennia.utils.create import create_account from evennia.utils.create import create_account
@ -218,7 +217,7 @@ class TestInitHooks(TestCase):
for obj in self.objects: for obj in self.objects:
obj.delete() obj.delete()
@override_settings(_TEST_ENVIRONMENT=True) @override_settings(TEST_ENVIRONMENT=True)
def test_run_init_hooks(self): def test_run_init_hooks(self):
with patch.object( with patch.object(
self.server, "at_server_reload_start", new=MagicMock() self.server, "at_server_reload_start", new=MagicMock()

View file

@ -24,13 +24,13 @@ class EvenniaTestSuiteRunner(DiscoverRunner):
from django.conf import settings from django.conf import settings
# set testing flag while suite runs # set testing flag while suite runs
settings._TEST_ENVIRONMENT = True settings.TEST_ENVIRONMENT = True
super().setup_test_environment(**kwargs) super().setup_test_environment(**kwargs)
def teardown_test_environment(self, **kwargs): def teardown_test_environment(self, **kwargs):
# remove testing flag after suite has run # remove testing flag after suite has run
from django.conf import settings from django.conf import settings
settings._TEST_ENVIRONMENT = False settings.TEST_ENVIRONMENT = False
super().teardown_test_environment(**kwargs) super().teardown_test_environment(**kwargs)

View file

@ -1227,7 +1227,7 @@ AMP_CLIENT_PROTOCOL_CLASS = "evennia.server.amp_client.AMPServerClientProtocol"
# don't change this manually, it can be checked from code to know if # don't change this manually, it can be checked from code to know if
# being run from a unit test (set by the evennia.utils.test_resources.BaseEvenniaTest # being run from a unit test (set by the evennia.utils.test_resources.BaseEvenniaTest
# and BaseEvenniaTestCase unit testing parents) # and BaseEvenniaTestCase unit testing parents)
_TEST_ENVIRONMENT = False TEST_ENVIRONMENT = False
###################################################################### ######################################################################
# Django extensions # Django extensions

View file

@ -26,27 +26,21 @@ import re
import sys import sys
import types import types
import evennia
from django.conf import settings from django.conf import settings
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
from mock import MagicMock, Mock, patch
from twisted.internet.defer import Deferred
import evennia
from evennia import settings_default from evennia import settings_default
from evennia.accounts.accounts import DefaultAccount from evennia.accounts.accounts import DefaultAccount
from evennia.commands.command import InterruptCommand from evennia.commands.command import InterruptCommand
from evennia.commands.default.muxcommand import MuxCommand from evennia.commands.default.muxcommand import MuxCommand
from evennia.objects.objects import ( from evennia.objects.objects import DefaultCharacter, DefaultExit, DefaultObject, DefaultRoom
DefaultCharacter,
DefaultExit,
DefaultObject,
DefaultRoom,
)
from evennia.scripts.scripts import DefaultScript from evennia.scripts.scripts import DefaultScript
from evennia.server.serversession import ServerSession from evennia.server.serversession import ServerSession
from evennia.utils import ansi, create from evennia.utils import ansi, create
from evennia.utils.idmapper.models import flush_cache from evennia.utils.idmapper.models import flush_cache
from evennia.utils.utils import all_from_module, to_str from evennia.utils.utils import all_from_module, to_str
from mock import MagicMock, Mock, patch
from twisted.internet.defer import Deferred
_RE_STRIP_EVMENU = re.compile(r"^\+|-+\+|\+-+|--+|\|(?:\s|$)", re.MULTILINE) _RE_STRIP_EVMENU = re.compile(r"^\+|-+\+|\+-+|--+|\|(?:\s|$)", re.MULTILINE)
@ -101,7 +95,7 @@ DEFAULT_SETTING_RESETS = dict(
"evennia.game_template.server.conf.prototypefuncs", "evennia.game_template.server.conf.prototypefuncs",
], ],
BASE_GUEST_TYPECLASS="evennia.accounts.accounts.DefaultGuest", BASE_GUEST_TYPECLASS="evennia.accounts.accounts.DefaultGuest",
# a special setting boolean _TEST_ENVIRONMENT is set by the test runner # a special setting boolean TEST_ENVIRONMENT is set by the test runner
# while the test suite is running. # while the test suite is running.
) )