Skip to content

Commit a3a1cdc

Browse files
committed
fixing endpoint issue in the api
1 parent 6c12b04 commit a3a1cdc

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

onepyece/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"chapter_by_title",
1717
"count_chapters",
1818
"arc_by_id",
19-
# "arc_by_title",
19+
"arc_by_title",
2020
"arc_by_saga_id",
2121
"count_arcs",
2222
"saga_by_id",

onepyece/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"movies": ["id", "count", "title"],
77
"tomes": ["id", "count", "title"],
88
"chapters": ["id", "count", "title", "tome_id"],
9-
"arcs": ["id", "count", "saga_id"],
9+
"arcs": ["id", "count", "title", "saga_id"],
1010
"sagas": ["id", "count", "title"],
1111
"hakis": ["id", "count", "name", "roman_name", "characters_id"],
1212
"characters": ["id", "count", "name", "job", "bounty", "status", "size", "crew_id", "fruit_id"],
@@ -51,7 +51,8 @@ def build_url(endpoint, search=None, resource=None):
5151

5252

5353
def adding_search(endpoint, search, resource=None):
54-
if search in STRING_SEARCHES:
54+
# This is a special case cause the API endpoints are weird
55+
if search in STRING_SEARCHES or search == "title" and endpoint == "arcs":
5556
return f"{URL}{endpoint}/search/{search}/{resource}"
5657
elif search in NO_SEARCH_ID_SEARCHES and endpoint not in ['boats', 'arcs']:
5758
return f"{URL}{endpoint}/{search[:-3]}/{resource}"

onepyece/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ def count_chapters():
6868
def arc_by_id(resource):
6969
return API("arcs", "id", resource)
7070

71-
# This functions is not working because the API link is not working
72-
# def arc_by_title(resource):
73-
# return API("arcs", "title", resource)
71+
72+
def arc_by_title(resource):
73+
return API("arcs", "title", resource)
7474

7575

7676
def arc_by_saga_id(resource):

tests/__main__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import unittest
22

3-
# from .test_api import *
4-
# from .test_common import *
5-
# from .test_functions import *
3+
from .test_api import *
4+
from .test_common import *
5+
from .test_functions import *
66
from .test_interface import *
77

88
if __name__ == '__main__':

tests/test_interface.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,16 @@ def test_edit_resource_not_allowed(self):
8484
api_object.edit_resource('zoro')
8585
with self.assertRaises(ValueError):
8686
api_object_2.edit_resource('zoro')
87-
87+
88+
def test_edit_resource_attributes(self):
89+
api_object = interface.API('characters', 'name', 'luffy')
90+
self.assertEqual(api_object.french_name, 'Monkey D Luffy')
91+
self.assertEqual(api_object.url, 'https://api.api-onepiece.com/characters/search/name/luffy')
92+
api_object.edit_resource('zoro')
93+
self.assertEqual(api_object.french_name, 'Roronoa Zoro')
94+
self.assertEqual(api_object.url, 'https://api.api-onepiece.com/characters/search/name/zoro')
95+
96+
def test_edit_resource_with_wrong_resource(self):
97+
api_object = interface.API('characters', 'name', 'luffy')
98+
with self.assertRaises(ValueError):
99+
api_object.edit_resource('wrong')

0 commit comments

Comments
 (0)