Esempio n. 1
0
	def test_whenNoArgumentsGiven_andNoAliasesDefined_thenPrintUserHasNoAliases(self):
		msg = Mock()
		msg.author.id = 21027
		msg.author.display_name = "Dymorius"
		expectedOutput = f'{msg.author.display_name} has no aliases defined.'

		reply = handleAlias(msg, "")

		self.assertTrue(reply.startswith(expectedOutput), f"{reply=} does not start with {expectedOutput=}")
Esempio n. 2
0
	def test_givenAliasDoesNotExists_whenDefinitionNotSpecified_thenReplyWithError(self):
		msg = Mock()
		for authorName, authorId, content, name in (
			("fBill", 0, "slam=", "slam"),
			("Bert", 86400, " rapier = ", "rapier"),
		):
			msg.author.display_name = authorName
			msg.author.id = authorId
			reply = handleAlias(msg, content)
			self.assertEqual(reply, f"{authorName} -- {name.strip()} is not aliased to anything.")
Esempio n. 3
0
	def test_givenAliasExists_whenDefinitionNotSpecified_thenDelete(self):
		msg = Mock()
		session = bot.Session()
		for authorName, authorId, content, name, definition in (
			("Bill", 0, "slam=", "slam", "slams for d6"),
			("Bert", 86400, " rapier = ", "rapier", "d20adv + 5 then hit for d8"),
		):
			msg.author.display_name = authorName
			msg.author.id = authorId
			session.add(Alias(user=authorId, name=name, definition=definition))
			session.commit()
			reply = handleAlias(msg, content)
			self.assertEqual(reply, f"{authorName} -- {name.strip()} is no longer aliased to {definition.strip()}")
Esempio n. 4
0
	def test_storesAlias_whenDefinedByUser(self):
		msg = Mock()
		session = bot.Session()
		for userId, content, name, definition in (
			(0, "slam = slams for d6", "slam", "slams for d6"),
			(86400, "rapier = d20adv + 5 then hit for d8", "rapier", "d20adv + 5 then hit for d8"),
		):
			msg.author.display_name = "Bob"
			msg.author.id = userId
			reply = handleAlias(msg, content)
			self.assertEqual(reply, f"stored alias for {msg.author.display_name} = {definition}")
			res = session.query(Alias).filter_by(user=userId, name=name)
			self.assertEqual(res.count(), 1)
			self.assertEqual(res[0].definition, definition)
Esempio n. 5
0
	def test_whenNoArgumentsGiven_thenPrintAllAliases(self):
		session = bot.Session()
		msg = Mock()
		msg.author.id = 21027
		msg.author.display_name = "Dymorius"
		expectedHeader = f"{msg.author.display_name} has the following aliases defined:"
		expectedAliases = []
		for content, name, definition in (
			("", "slam", "slams for d6"),
			(" ", "rapier", "d20adv + 5 then hit for d8"),
		):
			expectedAliases.append(f"{name} = {definition.strip()}")
			expectedAliases.sort()
			session.add(Alias(user=msg.author.id, name=name, definition=definition))
			session.commit()

			reply = handleAlias(msg, content)

			aliases = reply.split("\n")[1:]
			aliases.sort()
			self.assertEqual(reply.split("\n")[0], expectedHeader)
			self.assertListEqual(aliases, expectedAliases)