def setUp(self): """ Simply setup our Guild obj before usage """ self.guild = Guild(None, 15, {}) self.guild.users = User(20, 15, {}) self.guild.users = User(21, 15, {})
def propagate(self, message: discord.Message): """ This method handles a message object and then adds it to the relevant user Parameters ========== message : discord.Message The message that needs to be propagated out """ if not isinstance(message, discord.Message): raise ValueError("Expected message of type: discord.Message") if isinstance(self._channel, int): self.channel = message.channel user = User( self._bot, message.author.id, message.guild.id, self.options, logger=self.logger, ) for userObj in self.users: if user == userObj: return userObj.propagate(message) self.users = user self.logger.info(f"Created User: {user.id}") user.propagate(message)
def setUp(self): """ Simply setup our User obj before usage """ self.user = User( None, 0, 3, Static.DEFAULTS, logger=logging.getLogger(__name__) ) self.user.messages = Message(0, "Hello world", 0, 2, 3) self.user.messages = Message(1, "Foo Bar", 0, 2, 3)
def setUp(self): """ Simply setup our User obj before usage """ self.user = User(0, 3, {}) self.user.messages = Message(0, "Hello world", 0, 2, 3) self.user.messages = Message(1, "Foo Bar", 0, 2, 3)
def test_messageRaisesMismatch(self): with self.assertRaises(ObjectMismatch): self.guild.users = User(None, 22, 16, Static.DEFAULTS, logger=logging.getLogger(__name__))
def test_userRaisesDuplicate(self): with self.assertRaises(DuplicateObject): self.guild.users = User(None, 21, 15, Static.DEFAULTS, logger=logging.getLogger(__name__))
def test_userAssignment(self): self.assertEqual(len(self.guild.users), 2) self.guild.users = User(None, 22, 15, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.assertEqual(len(self.guild.users), 3)
def setUp(self): """ Simply setup our Guild obj before usage """ self.guild = Guild(None, 15, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.guild.users = User(None, 20, 15, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.guild.users = User(None, 21, 15, Static.DEFAULTS, logger=logging.getLogger(__name__))
def setUp(self): """ Simply setup our Guild obj before usage """ self.ash = AntiSpamHandler(commands.Bot(command_prefix="!")) self.ash.guilds = Guild(None, 12, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.ash.guilds = Guild(None, 15, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.ash.guilds[0] = User(None, 20, 15, Static.DEFAULTS, logger=logging.getLogger(__name__))
def test_messageRaisesMismatch(self): with self.assertRaises(ObjectMismatch): self.guild.users = User(22, 16, {})
def test_userRaisesDuplicate(self): with self.assertRaises(DuplicateObject): self.guild.users = User(21, 15, {})
def test_userAssignment(self): self.assertEqual(len(self.guild.users), 2) self.guild.users = User(22, 15, {}) self.assertEqual(len(self.guild.users), 3)
class TestUser(unittest.TestCase): """ Used to test the user object """ def setUp(self): """ Simply setup our User obj before usage """ self.user = User( None, 0, 3, Static.DEFAULTS, logger=logging.getLogger(__name__) ) self.user.messages = Message(0, "Hello world", 0, 2, 3) self.user.messages = Message(1, "Foo Bar", 0, 2, 3) def test_botAssignment(self): # Given we don't want to populate an entire bot, # lets just check its assigned correctly self.assertIsNone(self.user.bot) def test_intAssignment(self): self.assertIsInstance(self.user.id, int) self.assertIsInstance(self.user.guildId, int) def test_listAssignment(self): self.assertIsInstance(self.user.messages, list) def test_dictAssignment(self): self.assertIsInstance(self.user.options, dict) def test_valueAssignment(self): self.assertEqual(self.user.id, 0) self.assertEqual(self.user.guildId, 3) self.assertEqual(self.user.options, Static.DEFAULTS) self.user.id = 10 self.user.guildId = 10 self.assertEqual(self.user.id, 10) self.assertEqual(self.user.guildId, 10) def test_messageAssignment(self): self.assertEqual(len(self.user.messages), 2) self.user.messages = Message(3, "Test", 0, 2, 3) self.assertEqual(len(self.user.messages), 3) def test_messageRaises(self): with self.assertRaises(ValueError): self.user.messages = 1 def test_messageRaisesDuplicate(self): with self.assertRaises(DuplicateObject): self.user.messages = Message(1, "Testing", 0, 2, 3) def test_messageRaisesMismatch(self): with self.assertRaises(ObjectMismatch): self.user.messages = Message(20, "Testing", 20, 20, 20) def test_repr(self): self.assertEqual( repr(self.user), ( f"'{self.user.__class__.__name__} object. User id: {self.user.id}, Guild id: {self.user.guildId}, " f"Len Stored Messages {len(self.user.messages)}'" ), ) def test_str(self): self.assertEqual( str(self.user), f"{self.user.__class__.__name__} object for {self.user.id}." ) def test_eqEqual(self): obj = User(None, 0, 3, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.assertTrue(self.user == obj) def test_eqNotEqual(self): obj = User(None, 2, 2, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.assertFalse(self.user == obj) def test_duplicateCounter(self): self.assertNotEqual( self.user.duplicateCounter, self.user.GetCorrectDuplicateCount() ) self.assertEqual( self.user.duplicateCounter - 1, self.user.GetCorrectDuplicateCount() )
def test_eqNotEqual(self): obj = User(None, 2, 2, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.assertFalse(self.user == obj)
def test_eqEqual(self): obj = User(None, 0, 3, Static.DEFAULTS, logger=logging.getLogger(__name__)) self.assertTrue(self.user == obj)