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)
- [Feature][issue3307]: Add support for Attribute-categories when using the monitorhandler
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][pull3324]: Make account-post-login-fail signal fire properly. Add
`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
# being run from a unit test (set by the evennia.utils.test_resources.BaseEvenniaTest
# and BaseEvenniaTestCase unit testing parents)
_TEST_ENVIRONMENT = False
TEST_ENVIRONMENT = False
######################################################################
# Django extensions

View file

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

View file

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

View file

@ -7,15 +7,14 @@ Sessionhandler for portal sessions.
import time
from collections import deque, namedtuple
import evennia
from django.conf import settings
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.sessionhandler import SessionHandler
from evennia.utils.logger import log_trace
from evennia.utils.utils import class_from_module
from twisted.internet import reactor
# module import
_MOD_IMPORT = None
@ -41,7 +40,7 @@ DUMMYSESSION = namedtuple("DummySession", ["sessid"])(0)
# -------------------------------------------------------------
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.
"""
if settings._TEST_ENVIRONMENT:
if settings.TEST_ENVIRONMENT:
return
def _callback(result, sessionhandler):

View file

@ -7,20 +7,19 @@ import time
import traceback
import django
import evennia
from django.conf import settings
from django.db import connection
from django.db.utils import OperationalError
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.service import MultiService
from twisted.internet import defer, reactor
from twisted.internet.defer import Deferred
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__
@ -406,7 +405,7 @@ class EvenniaServerService(MultiService):
except Exception:
# stop server if this happens.
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.")
evennia.SESSION_HANDLER.portal_shutdown()

View file

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

View file

@ -24,13 +24,13 @@ class EvenniaTestSuiteRunner(DiscoverRunner):
from django.conf import settings
# set testing flag while suite runs
settings._TEST_ENVIRONMENT = True
settings.TEST_ENVIRONMENT = True
super().setup_test_environment(**kwargs)
def teardown_test_environment(self, **kwargs):
# remove testing flag after suite has run
from django.conf import settings
settings._TEST_ENVIRONMENT = False
settings.TEST_ENVIRONMENT = False
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
# being run from a unit test (set by the evennia.utils.test_resources.BaseEvenniaTest
# and BaseEvenniaTestCase unit testing parents)
_TEST_ENVIRONMENT = False
TEST_ENVIRONMENT = False
######################################################################
# Django extensions

View file

@ -26,27 +26,21 @@ import re
import sys
import types
import evennia
from django.conf import 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.accounts.accounts import DefaultAccount
from evennia.commands.command import InterruptCommand
from evennia.commands.default.muxcommand import MuxCommand
from evennia.objects.objects import (
DefaultCharacter,
DefaultExit,
DefaultObject,
DefaultRoom,
)
from evennia.objects.objects import DefaultCharacter, DefaultExit, DefaultObject, DefaultRoom
from evennia.scripts.scripts import DefaultScript
from evennia.server.serversession import ServerSession
from evennia.utils import ansi, create
from evennia.utils.idmapper.models import flush_cache
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)
@ -101,7 +95,7 @@ DEFAULT_SETTING_RESETS = dict(
"evennia.game_template.server.conf.prototypefuncs",
],
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.
)