mirror of
https://github.com/evennia/evennia.git
synced 2026-03-24 08:46:31 +01:00
Refactor unit test runner and one new unit test
This commit is contained in:
parent
11d39a57b5
commit
cd5979eea0
5 changed files with 52 additions and 39 deletions
0
evennia/server/tests/__init__.py
Normal file
0
evennia/server/tests/__init__.py
Normal file
19
evennia/server/tests/test_initial_setup.py
Normal file
19
evennia/server/tests/test_initial_setup.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
"""
|
||||
Test initial startup procedure
|
||||
|
||||
"""
|
||||
|
||||
from mock import MagicMock, patch
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
|
||||
from evennia.server import initial_setup
|
||||
|
||||
|
||||
class TestInitialSetup(TestCase):
|
||||
|
||||
@patch("evennia.server.initial_setup.AccountDB")
|
||||
def test_get_god_account(self, mocked_accountdb):
|
||||
mocked_accountdb.objects.get = MagicMock(return_value=1)
|
||||
self.assertEqual(initial_setup.get_god_account(), 1)
|
||||
mocked_accountdb.objects.get.assert_called_with(id=1)
|
||||
|
|
@ -1,28 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Unit testing of the 'objects' Evennia component.
|
||||
Testing various individual functionalities in the server package.
|
||||
|
||||
Runs as part of the Evennia's test suite with 'manage.py test"
|
||||
|
||||
Please add new tests to this module as needed.
|
||||
|
||||
Guidelines:
|
||||
A 'test case' is testing a specific component and is defined as a class
|
||||
inheriting from unittest.TestCase. The test case class can have a method
|
||||
setUp() that creates and sets up the testing environment.
|
||||
All methods inside the test case class whose names start with 'test' are
|
||||
used as test methods by the runner. Inside the test methods, special member
|
||||
methods assert*() are used to test the behaviour.
|
||||
"""
|
||||
try:
|
||||
from django.utils.unittest import TestCase
|
||||
except ImportError:
|
||||
from django.test import TestCase
|
||||
try:
|
||||
from django.utils import unittest
|
||||
except ImportError:
|
||||
import unittest
|
||||
import unittest
|
||||
from django.test import TestCase
|
||||
|
||||
from evennia.server.validators import EvenniaPasswordValidator
|
||||
from evennia.utils.test_resources import EvenniaTest
|
||||
|
|
@ -31,23 +14,7 @@ from django.test.runner import DiscoverRunner
|
|||
|
||||
from evennia.server.throttle import Throttle
|
||||
|
||||
from .deprecations import check_errors
|
||||
|
||||
|
||||
class EvenniaTestSuiteRunner(DiscoverRunner):
|
||||
"""
|
||||
This test runner only runs tests on the apps specified in evennia/
|
||||
avoid running the large number of tests defined by Django
|
||||
"""
|
||||
|
||||
def build_suite(self, test_labels, extra_tests=None, **kwargs):
|
||||
"""
|
||||
Build a test suite for Evennia. test_labels is a list of apps to test.
|
||||
If not given, a subset of settings.INSTALLED_APPS will be used.
|
||||
"""
|
||||
import evennia
|
||||
evennia._init()
|
||||
return super(EvenniaTestSuiteRunner, self).build_suite(test_labels, extra_tests=extra_tests, **kwargs)
|
||||
from ..deprecations import check_errors
|
||||
|
||||
|
||||
class MockSettings(object):
|
||||
27
evennia/server/tests/testrunner.py
Normal file
27
evennia/server/tests/testrunner.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
"""
|
||||
Main test-suite runner of Evennia. The runner collates tests from
|
||||
all over the code base and runs them.
|
||||
|
||||
Runs as part of the Evennia's test suite with 'evennia test evennia"
|
||||
|
||||
"""
|
||||
from django.test.runner import DiscoverRunner
|
||||
|
||||
|
||||
class EvenniaTestSuiteRunner(DiscoverRunner):
|
||||
"""
|
||||
Pointed to by the TEST_RUNNER setting.
|
||||
This test runner only runs tests on the apps specified in evennia/
|
||||
avoid running the large number of tests defined by Django
|
||||
|
||||
"""
|
||||
|
||||
def build_suite(self, test_labels, extra_tests=None, **kwargs):
|
||||
"""
|
||||
Build a test suite for Evennia. test_labels is a list of apps to test.
|
||||
If not given, a subset of settings.INSTALLED_APPS will be used.
|
||||
"""
|
||||
import evennia
|
||||
evennia._init()
|
||||
return super(EvenniaTestSuiteRunner, self).build_suite(
|
||||
test_labels, extra_tests=extra_tests, **kwargs)
|
||||
|
|
@ -831,9 +831,9 @@ AUTH_USERNAME_VALIDATORS = [
|
|||
{'NAME': 'evennia.server.validators.EvenniaUsernameAvailabilityValidator'}]
|
||||
|
||||
# Use a custom test runner that just tests Evennia-specific apps.
|
||||
TEST_RUNNER = 'evennia.server.tests.EvenniaTestSuiteRunner'
|
||||
TEST_RUNNER = 'evennia.server.tests.testrunner.EvenniaTestSuiteRunner'
|
||||
|
||||
# Messages and Bootstrap don't classify events the same way; this setting maps
|
||||
# Messages and Bootstrap don't classify events the same way; this setting maps
|
||||
# messages.error() to Bootstrap 'danger' classes.
|
||||
MESSAGE_TAGS = {
|
||||
messages.ERROR: 'danger',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue