Test to improve test behavior for postgres/mysql

This commit is contained in:
Griatch 2022-01-20 22:13:21 +01:00
parent d6fbd1572f
commit 7912351e01
3 changed files with 24 additions and 11 deletions

View file

@ -676,19 +676,25 @@ class ObjectDBManager(TypedObjectManager):
location = dbid_to_obj(location, self.model)
destination = dbid_to_obj(destination, self.model)
if home:
home = dbid_to_obj(home, self.model)
if not nohome and not home:
try:
home = dbid_to_obj(settings.DEFAULT_HOME, self.model)
except self.model.DoesNotExist:
if home:
home_obj_or_dbref = home
elif nohome:
home_obj_or_dbref = None
else:
home_obj_or_dbref = settings.DEFAULT_HOME
try:
home = dbid_to_obj(home_obj_or_dbref, self.model)
except self.model.DoesNotExist:
if settings._TEST_ENVIRONMENT:
# this happens for databases where the #1 location is flushed during tests
home = None
else:
raise self.model.DoesNotExist(
"settings.DEFAULT_HOME (= '%s') does not exist, or the setting is malformed."
% settings.DEFAULT_HOME
f"settings.DEFAULT_HOME (= '{settings.DEFAULT_HOME}') does not exist, "
"or the setting is malformed."
)
elif nohome and not home:
home = None
# create new instance
new_object = typeclass(

View file

@ -1149,6 +1149,10 @@ SESSION_SYNC_ATTRS = (
AMP_SERVER_PROTOCOL_CLASS = "evennia.server.portal.amp_server.AMPServerProtocol"
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
######################################################################
# Django extensions

View file

@ -58,6 +58,8 @@ DEFAULT_SETTING_RESETS = dict(
FUNCPARSER_PROTOTYPE_PARSING_MODULES=["evennia.prototypes.protfuncs",
"evennia.game_template.server.conf.prototypefuncs"],
BASE_GUEST_TYPECLASS="evennia.accounts.accounts.DefaultGuest",
# a special flag; test with settings._TEST_ENVIRONMENT to see if code runs in a test
_TEST_ENVIRONMENT=True,
)
DEFAULT_SETTINGS = {
@ -153,7 +155,8 @@ class EvenniaTestMixin:
self.account2.delete()
# Set up fake prototype module for allowing tests to use named prototypes.
@override_settings(PROTOTYPE_MODULES=["evennia.utils.tests.data.prototypes_example"], DEFAULT_HOME="#1")
@override_settings(PROTOTYPE_MODULES=["evennia.utils.tests.data.prototypes_example"],
DEFAULT_HOME="#1")
def create_rooms(self):
self.room1 = create.create_object(self.room_typeclass, key="Room", nohome=True)
self.room1.db.desc = "room_desc"