"""Test IdleRPG game operations. SPDX-FileCopyrightText: © 2024 Brian S. Stephan 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()