a prior commit made this determination for now, for simplicity's sake (and also what are the odds of running two games at once on the same codebase), but it was'n really enforced until now Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
"""Test IdleRPG game operations.
|
|
|
|
SPDX-FileCopyrightText: © 2024 Brian S. Stephan <bss@incorporeal.org>
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
import logging
|
|
|
|
from django.db import transaction
|
|
from django.db.utils import IntegrityError
|
|
from django.test import TestCase
|
|
from ircbot.models import IrcChannel
|
|
|
|
from idlerpg.models import Game
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class GameTest(TestCase):
|
|
"""Test the Character model."""
|
|
|
|
fixtures = ['tests/fixtures/simple_character.json']
|
|
|
|
def test_string_repr(self):
|
|
"""Test the basic string summary."""
|
|
game = Game.objects.get(pk=1)
|
|
logger.debug(str(game))
|
|
assert str(game) == "test in #test on default (active)"
|
|
|
|
def test_cant_have_two_active(self):
|
|
"""Test that if we create another game, it's disabled, and can't be active until the first is disabled."""
|
|
channel = IrcChannel.objects.get(pk=2)
|
|
game = Game.objects.get(pk=1)
|
|
new_game = Game.objects.create(name='new one', channel=channel)
|
|
|
|
assert game.active is True
|
|
assert new_game.active is False
|
|
with self.assertRaises(IntegrityError):
|
|
with transaction.atomic():
|
|
new_game.active = True
|
|
new_game.save()
|