コード例 #1
0
 def test_create_with_all_params(self):
     x = Image(url="url-1", proxy_url="url-2", width=500, height=400)
     self.assertEqual(x.url, "url-1")
     self.assertEqual(x.proxy_url, "url-2")
     self.assertEqual(x.width, 500)
     self.assertEqual(x.height, 400)
     self.assertDictEqual(
         x.asdict(),
         {"url": "url-1", "proxy_url": "url-2", "width": 500, "height": 400},
     )
コード例 #2
0
 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)
コード例 #3
0
    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},
                ],
            },
        )
コード例 #4
0
 def test_detect_invalid_height(self):
     with self.assertRaises(ValueError):
         Image("my-url", height=-5)
コード例 #5
0
 def test_detect_invalid_width(self):
     with self.assertRaises(ValueError):
         Image("my-url", width=-5)
コード例 #6
0
 def test_create_with_url_only(self):
     x = Image("my-url")
     self.assertEqual(x.url, "my-url")
     self.assertDictEqual(x.asdict(), {"url": "my-url"})
コード例 #7
0
 def test_detect_missing_params_on_create(self):
     with self.assertRaises(ValueError):
         Image(None)