diff --git a/evennia/commands/default/tests.py b/evennia/commands/default/tests.py index 92d3a3a8ca..825db32ab2 100644 --- a/evennia/commands/default/tests.py +++ b/evennia/commands/default/tests.py @@ -31,14 +31,7 @@ from evennia import ( from evennia.commands import cmdparser from evennia.commands.cmdset import CmdSet from evennia.commands.command import Command, InterruptCommand -from evennia.commands.default import ( - account, - admin, - batchprocess, - building, - comms, - general, -) +from evennia.commands.default import account, admin, batchprocess, building, comms, general from evennia.commands.default import help as help_module from evennia.commands.default import syscommands, system, unloggedin from evennia.commands.default.cmdset_character import CharacterCmdSet @@ -83,7 +76,9 @@ class TestGeneral(BaseEvenniaCommandTest): def test_pose(self): self.char2.msg = Mock() self.call(general.CmdPose(), "looks around", "Char looks around") - self.char2.msg.assert_called_with(text=('Char looks around', {'type': 'pose'}), from_obj=self.char1) + self.char2.msg.assert_called_with( + text=("Char looks around", {"type": "pose"}), from_obj=self.char1 + ) def test_nick(self): self.call( @@ -173,7 +168,6 @@ class TestGeneral(BaseEvenniaCommandTest): class TestHelp(BaseEvenniaCommandTest): - maxDiff = None def setUp(self): @@ -584,7 +578,6 @@ class TestAccount(BaseEvenniaCommandTest): ] ) def test_ooc_look(self, multisession_mode, auto_puppet, max_nr_chars, expected_result): - self.account.db._playable_characters = [self.char1] self.account.unpuppet_all() @@ -1563,7 +1556,6 @@ class TestBuilding(BaseEvenniaCommandTest): ) def test_script_multi_delete(self): - script1 = create.create_script() script2 = create.create_script() script3 = create.create_script() @@ -1867,7 +1859,7 @@ class TestCommsChannel(BaseEvenniaCommandTest): self.call(self.cmdchannel(), "/sub testchannel", "You are now subscribed") self.assertTrue(self.char1 in self.channel.subscriptions.all()) self.assertEqual( - self.char1.nicks.nickreplace("testchannel Hello"), "channel testchannel = Hello" + self.char1.nicks.nickreplace("testchannel Hello"), "@channel testchannel = Hello" ) def test_channel__unsub(self): @@ -1883,7 +1875,7 @@ class TestCommsChannel(BaseEvenniaCommandTest): "/alias testchannel = foo", "Added/updated your alias 'foo' for channel testchannel.", ) - self.assertEqual(self.char1.nicks.nickreplace("foo Hello"), "channel testchannel = Hello") + self.assertEqual(self.char1.nicks.nickreplace("foo Hello"), "@channel testchannel = Hello") # use alias self.channel.msg = Mock() @@ -2084,7 +2076,6 @@ class TestBatchProcess(BaseEvenniaCommandTest): class CmdInterrupt(Command): - key = "interrupt" def parse(self): diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index 9a68d31d36..9791e5a930 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -7,6 +7,7 @@ import re from django.contrib.contenttypes.models import ContentType from django.urls import reverse from django.utils.text import slugify + from evennia.comms.managers import ChannelManager from evennia.comms.models import ChannelDB from evennia.typeclasses.models import TypeclassBase @@ -66,7 +67,7 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase): # default nick-alias replacements (default using the 'channel' command) channel_msg_nick_pattern = r"{alias}\s*?|{alias}\s+?(?P.+?)" - channel_msg_nick_replacement = "channel {channelname} = $1" + channel_msg_nick_replacement = "@channel {channelname} = $1" def at_first_save(self): """ diff --git a/evennia/comms/tests.py b/evennia/comms/tests.py index 2795ccf48a..b037730e49 100644 --- a/evennia/comms/tests.py +++ b/evennia/comms/tests.py @@ -1,8 +1,20 @@ +from django.test import SimpleTestCase + from evennia import DefaultChannel +from evennia.commands.default.comms import CmdChannel from evennia.utils.create import create_message from evennia.utils.test_resources import BaseEvenniaTest +class TestCommsNickMatchesCommand(SimpleTestCase): + def test(self): + """ + Verifies that the nick being set by DefaultChannel matches the channel + command key. + """ + self.assertTrue(DefaultChannel.channel_msg_nick_replacement.startswith(CmdChannel.key)) + + class ObjectCreationTest(BaseEvenniaTest): def test_channel_create(self): description = "A place to talk about coffee." @@ -18,6 +30,29 @@ class ObjectCreationTest(BaseEvenniaTest): self.assertEqual(str(msg), "peewee herman->: heh-heh!") +class ChannelSubscriptionTests(BaseEvenniaTest): + def setUp(self): + super().setUp() + self.default_channel, _ = DefaultChannel.create( + "catlovers", description="A place for feline fanciers." + ) + self.default_channel.connect(self.obj1) + + def test_subscribe_unsubscribe(self): + self.default_channel.connect(self.char1) + self.assertTrue(self.default_channel.subscriptions.has(self.char1)) + self.assertEqual( + self.char1.nicks.nickreplace("catlovers I love cats!"), + "@channel catlovers = I love cats!", + ) + self.default_channel.disconnect(self.char1) + self.assertFalse(self.default_channel.subscriptions.has(self.char1)) + self.assertEqual( + self.char1.nicks.nickreplace("catlovers I love cats!"), + "catlovers I love cats!", + ) + + class ChannelWholistTests(BaseEvenniaTest): def setUp(self): super().setUp()