def test_create_with_description_only(self): x = Embed(description="They said the age of heroes would never come again.") self.assertEqual( x.description, "They said the age of heroes would never come again." ) self.assertEqual(x.type, "rich") self.assertDictEqual( x.asdict(), { "type": "rich", "description": "They said the age of heroes would never come again.", }, )
def test_detects_max_embed_limit(self): description = "x" * 2000 fields = list() for x in range(5): fields.append(Field(name="name" + str(x), value="value" + "x" * 1000)) with self.assertRaises(ValueError): x = Embed(description=description, fields=fields)
def test_from_dict_full(self): embed = Embed( title="Justice League", description="They said the age of heroes would never come again.", url="url-1", timestamp=self.now, color=0x5CDBF0, footer=Footer("TOP SECRET", "url-2", "url-11"), image=Image("url-3", "url-4", height=200, width=150), thumbnail=Thumbnail("url-5", "url-6", height=100, width=80), author=Author("Bruce Wayne", "url-8", "url-9"), fields=[Field("fruit", "orange", False), Field("vegetable", "onion", True)], ) embed_dict = embed.asdict() embed_2 = Embed.from_dict(embed_dict) self.assertEqual(embed, embed_2)
def test_detects_max_fields_limit(self): fields = list() for x in range(26): fields.append(Field(name="name {}".format(x), value="value {}".format(x))) with self.assertRaises(ValueError): x = Embed(fields=fields)
def test_detects_max_title_limit(self): large_string = "x" * 257 with self.assertRaises(ValueError): Embed(title=large_string)
def test_detects_max_description_limit(self): large_string = "x" * 2049 with self.assertRaises(ValueError): Embed(description=large_string)
def test_detects_wrong_type_fields_content(self): with self.assertRaises(TypeError): Embed(fields=[int(1), Field("x", 1)])
def test_detects_wrong_type_fields_list(self): with self.assertRaises(TypeError): Embed(fields=int(1))
def test_detects_wrong_type_author(self): with self.assertRaises(TypeError): Embed(author=int(1))
def test_detects_wrong_type_thumbnail(self): with self.assertRaises(TypeError): Embed(thumbnail=int(1))
def test_detects_wrong_type_image(self): with self.assertRaises(TypeError): Embed(image=int(1))
def test_detects_wrong_type_footer(self): with self.assertRaises(TypeError): Embed(footer=int(1))
def test_detects_wrong_type_timestamp(self): with self.assertRaises(TypeError): Embed(timestamp=int(1))
def test_from_dict_minimal(self): embed = Embed(description="Dummy") embed_dict = embed.asdict() embed_2 = Embed.from_dict(embed_dict) self.assertEqual(embed, embed_2)
def test_create_with_full_params(self): obj = Embed( title="Justice League", description="They said the age of heroes would never come again.", url="url-1", timestamp=self.now, color=0x5CDBF0, footer=Footer("TOP SECRET", "url-2", "url-11"), image=Image("url-3", "url-4", height=200, width=150), thumbnail=Thumbnail("url-5", "url-6", height=100, width=80), author=Author("Bruce Wayne", "url-8", "url-9"), fields=[Field("fruit", "orange", False), Field("vegetable", "onion", True)], ) self.assertEqual(obj.title, "Justice League") self.assertEqual( obj.description, "They said the age of heroes would never come again." ) self.assertEqual(obj.type, "rich") self.assertEqual(obj.url, "url-1") self.assertEqual(obj.timestamp, self.now) self.assertEqual(obj.color, 0x5CDBF0) self.assertEqual(obj.footer, Footer("TOP SECRET", "url-2", "url-11")) self.assertEqual(obj.image, Image("url-3", "url-4", height=200, width=150)) self.assertEqual( obj.thumbnail, Thumbnail("url-5", "url-6", height=100, width=80) ) self.assertEqual(obj.author, Author("Bruce Wayne", "url-8", "url-9")) self.assertEqual( obj.fields, [Field("fruit", "orange", False), Field("vegetable", "onion", True)], ) self.maxDiff = None self.assertDictEqual( obj.asdict(), { "title": "Justice League", "type": "rich", "description": "They said the age of heroes would never come again.", "url": "url-1", "timestamp": self.now, "color": 0x5CDBF0, "image": { "url": "url-3", "proxy_url": "url-4", "height": 200, "width": 150, }, "thumbnail": { "url": "url-5", "proxy_url": "url-6", "height": 100, "width": 80, }, "footer": { "text": "TOP SECRET", "icon_url": "url-2", "proxy_icon_url": "url-11", }, "author": {"name": "Bruce Wayne", "url": "url-8", "icon_url": "url-9"}, "fields": [ {"name": "fruit", "value": "orange", "inline": False}, {"name": "vegetable", "value": "onion", "inline": True}, ], }, )