Repos / pytaku / 0d22e2e4af
commit 0d22e2e4afc98b3beadfc12d33f666a56d9b415b
Author: Bùi Thành Nhân <hi@imnhan.com>
Date:   Sat Sep 18 23:59:26 2021 +0700

    fix mangadex

diff --git a/src/mangoapi/mangadex.py b/src/mangoapi/mangadex.py
index 9a2df2d..62d6973 100644
--- a/src/mangoapi/mangadex.py
+++ b/src/mangoapi/mangadex.py
@@ -31,7 +31,7 @@ def get_title(self, title_id):
                 break
 
         cover = None
-        for rel in md_json["relationships"]:
+        for rel in md_json["data"]["relationships"]:
             if rel["type"] == "cover_art":
                 cover = rel["attributes"]["fileName"]
 
@@ -143,11 +143,11 @@ def search_title(self, query):
         }
         md_resp = self.http_get("https://api.mangadex.org/manga", params=params)
         assert md_resp.status_code == 200
-        results = md_resp.json()["results"]
+        results = md_resp.json()["data"]
 
         titles = []
         for result in results:
-            data = result["data"]
+            data = result
             cover = None
             for rel in result["relationships"]:
                 if rel["type"] == "cover_art":
diff --git a/tests/mangoapi/test_mangadex.py b/tests/mangoapi/test_mangadex.py
index 886a20e..aff99b9 100644
--- a/tests/mangoapi/test_mangadex.py
+++ b/tests/mangoapi/test_mangadex.py
@@ -4,6 +4,8 @@
 def test_get_title():
     title = Mangadex().get_title("8af3ad21-3e7e-4fb5-b344-d0044ec154fc")
     chapters = title.pop("chapters")
+    descriptions = title.pop("descriptions")
+    assert descriptions[0]
     assert title == {
         "id": "8af3ad21-3e7e-4fb5-b344-d0044ec154fc",
         "name": "Beelzebub",
@@ -18,27 +20,6 @@ def test_get_title():
             "惡魔奶爸",
             "바알세불",
         ],
-        "descriptions": [
-            "Ishiyama High is a school populated entirely by "
-            "delinquents, where nonstop violence and lawlessness are the "
-            "norm. However, there is one universally acknowledged "
-            "rule—don&#39;t cross first year student Tatsumi Oga, "
-            "Ishiyama&#39;s most vicious fighter.<br /><br />One day, "
-            "Oga is by a riverbed when he encounters a man floating down "
-            "the river. After being retrieved by Oga, the man splits "
-            "down the middle to reveal a baby, which crawls onto "
-            "Oga&#39;s back and immediately forms an attachment to him. "
-            "Though he doesn&#39;t know it yet, this baby is named "
-            "Kaiser de Emperana Beelzebub IV, or &quot;Baby Beel&quot; "
-            "for short—the son of the Demon Lord!<br /><br />As if "
-            "finding the future Lord of the Underworld isn&#39;t enough, "
-            "Oga is also confronted by Hildegard, Beel&#39;s demon maid "
-            "who insists he take responsibility as Beel&#39;s guardian. "
-            "Together they attempt to raise Baby Beel—although "
-            "surrounded by juvenile delinquents and demonic powers, the "
-            "two of them may be in for more of a challenge than they can "
-            "imagine.<br /><hr />"
-        ],
         "descriptions_format": "html",
         "is_webtoon": False,
     }
@@ -47,7 +28,7 @@ def test_get_title():
     assert chapters[1] == {
         "id": "dfd3fd5a-a20f-460f-b726-e9cb168bfe3d",
         "name": "",
-        "volume": 28,
+        "volume": "28",
         "groups": [],
         "number": "245",
         "num_major": 245,
@@ -87,6 +68,12 @@ def test_search():
             "site": "mangadex",
             "thumbnail": "https://uploads.mangadex.org/covers/8af3ad21-3e7e-4fb5-b344-d0044ec154fc/bab3ccbf-7479-4117-ad92-4dedced54ceb.jpg.256.jpg",
         },
+        {
+            "id": "72378871-9afc-47bd-902f-0d8116adb390",
+            "name": "Beelzebub - Digital Colored Comics",
+            "site": "mangadex",
+            "thumbnail": "https://uploads.mangadex.org/covers/72378871-9afc-47bd-902f-0d8116adb390/c8b9b385-b7b9-4101-bf71-4f0d66fc35ff.jpg.256.jpg",
+        },
         {
             "id": "b4320039-9b91-44a7-a60d-c7ba8c0684e7",
             "name": "Beelzebub-jou no Oki ni Mesu mama.",
@@ -99,10 +86,4 @@ def test_search():
             "site": "mangadex",
             "thumbnail": "https://uploads.mangadex.org/covers/a453af66-0dac-4966-b246-b37c96b27245/7e50b22d-b027-4ee1-bd15-94f05fa6cecb.jpg.256.jpg",
         },
-        {
-            "id": "72378871-9afc-47bd-902f-0d8116adb390",
-            "name": "Beelzebub - Digital Colored Comics",
-            "site": "mangadex",
-            "thumbnail": "https://uploads.mangadex.org/covers/72378871-9afc-47bd-902f-0d8116adb390/c8b9b385-b7b9-4101-bf71-4f0d66fc35ff.jpg.256.jpg",
-        },
     ]