Fix unit test base
This commit is contained in:
parent
038c71213a
commit
a8b52b76b3
3 changed files with 21 additions and 26 deletions
|
|
@ -28,7 +28,6 @@ class AuditingTest(BaseEvenniaTest):
|
||||||
session = SESSIONS.session_from_sessid(1) # the real session
|
session = SESSIONS.session_from_sessid(1) # the real session
|
||||||
SESSIONS.login(session, self.account, testmode=True)
|
SESSIONS.login(session, self.account, testmode=True)
|
||||||
self.session = session
|
self.session = session
|
||||||
print("session", type(self.session), self.session)
|
|
||||||
|
|
||||||
@patch("evennia.contrib.utils.auditing.server.AUDIT_CALLBACK",
|
@patch("evennia.contrib.utils.auditing.server.AUDIT_CALLBACK",
|
||||||
"evennia.contrib.utils.auditing.outputs.to_syslog")
|
"evennia.contrib.utils.auditing.outputs.to_syslog")
|
||||||
|
|
|
||||||
|
|
@ -949,6 +949,7 @@ class TestPartialTagAttributes(BaseEvenniaTest):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
self.prot = {
|
self.prot = {
|
||||||
'prototype_key': 'rock',
|
'prototype_key': 'rock',
|
||||||
'typeclass': 'evennia.objects.objects.DefaultObject',
|
'typeclass': 'evennia.objects.objects.DefaultObject',
|
||||||
|
|
|
||||||
|
|
@ -131,27 +131,6 @@ class EvenniaTestMixin:
|
||||||
room_typeclass = DefaultRoom
|
room_typeclass = DefaultRoom
|
||||||
script_typeclass = DefaultScript
|
script_typeclass = DefaultScript
|
||||||
|
|
||||||
def save_backups(self):
|
|
||||||
self.backups = (
|
|
||||||
SESSIONS.data_out,
|
|
||||||
SESSIONS.disconnect,
|
|
||||||
settings.DEFAULT_HOME,
|
|
||||||
settings.PROTOTYPE_MODULES,
|
|
||||||
)
|
|
||||||
|
|
||||||
def restore_backups(self):
|
|
||||||
flush_cache()
|
|
||||||
if hasattr(self, "backups"):
|
|
||||||
SESSIONS.data_out = self.backups[0]
|
|
||||||
SESSIONS.disconnect = self.backups[1]
|
|
||||||
settings.DEFAULT_HOME = self.backups[2]
|
|
||||||
settings.PROTOTYPE_MODULES = self.backups[3]
|
|
||||||
|
|
||||||
def mock_sessions(self):
|
|
||||||
SESSIONS.data_out = Mock()
|
|
||||||
SESSIONS.disconnect = Mock()
|
|
||||||
self.mocked_SESSIONS = SESSIONS
|
|
||||||
|
|
||||||
def create_accounts(self):
|
def create_accounts(self):
|
||||||
self.account = create.create_account(
|
self.account = create.create_account(
|
||||||
"TestAccount",
|
"TestAccount",
|
||||||
|
|
@ -229,8 +208,15 @@ class EvenniaTestMixin:
|
||||||
"""
|
"""
|
||||||
Sets up testing environment
|
Sets up testing environment
|
||||||
"""
|
"""
|
||||||
self.save_backups()
|
self.backups = (
|
||||||
self.mock_sessions()
|
SESSIONS.data_out,
|
||||||
|
SESSIONS.disconnect,
|
||||||
|
settings.DEFAULT_HOME,
|
||||||
|
settings.PROTOTYPE_MODULES,
|
||||||
|
)
|
||||||
|
SESSIONS.data_out = Mock()
|
||||||
|
SESSIONS.disconnect = Mock()
|
||||||
|
|
||||||
self.create_accounts()
|
self.create_accounts()
|
||||||
self.create_rooms()
|
self.create_rooms()
|
||||||
self.create_objs()
|
self.create_objs()
|
||||||
|
|
@ -239,8 +225,17 @@ class EvenniaTestMixin:
|
||||||
self.setup_session()
|
self.setup_session()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.restore_backups()
|
flush_cache()
|
||||||
self.teardown_session()
|
try:
|
||||||
|
SESSIONS.data_out = self.backups[0]
|
||||||
|
SESSIONS.disconnect = self.backups[1]
|
||||||
|
settings.DEFAULT_HOME = self.backups[2]
|
||||||
|
settings.PROTOTYPE_MODULES = self.backups[3]
|
||||||
|
except AttributeError as err:
|
||||||
|
raise AttributeError(f"{err}: Teardown error. If you overrode the `setUp()` method "
|
||||||
|
"in your test, make sure you also added `super().setUp()`!")
|
||||||
|
|
||||||
|
del SESSIONS[self.session.sessid]
|
||||||
self.teardown_accounts()
|
self.teardown_accounts()
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue