Skip to content

Commit 8543340

Browse files
committed
Fix and Test
1 parent 73143fb commit 8543340

9 files changed

Lines changed: 190 additions & 5 deletions

File tree

.github/workflows/python-test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
name: Test package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: '3.x'
19+
- name: Install dependencies
20+
run: if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
21+
- name: Test with unittest
22+
run: python -m unittest discover -v -s ./tests -p test_*.py

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
animeworld.egg-info/
33
build/
44
dist/
5-
tests/
65
*.pyc
76
*.key

.vscode/settings.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"python.testing.unittestArgs": [
3+
"-v",
4+
"-s",
5+
"./tests",
6+
"-p",
7+
"test_*.py"
8+
],
9+
"python.testing.pytestEnabled": false,
10+
"python.testing.unittestEnabled": true
11+
}
12+
13+
// python -m unittest discover -v -s ./tests -p test_*.py

animeworld/servers/Server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _fileInfoIn(self) -> Dict[str,str]:
101101
"""
102102
url = self.fileLink()
103103

104-
r = SES.head(url)
104+
r = SES.head(url, follow_redirects=True)
105105
r.raise_for_status()
106106

107107
return {

animeworld/servers/Streamtape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def fileLink(self) -> str:
1919
```
2020
"""
2121

22-
sb_get = SES.get(self.link)
22+
sb_get = SES.get(self.link, follow_redirects=True)
2323

2424
if sb_get.status_code == 200:
2525
soupeddata = BeautifulSoup(sb_get.content, "html.parser")

animeworld/utility.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ def find(keyword: str) -> List[Dict]:
126126
for k in elem:
127127
if elem[k] == "??":
128128
elem[k] = None
129-
if elem["release"].find("??") != -1:
129+
if elem["release"] and elem["release"].find("??") != -1:
130130
elem["release"] = elem["release"].replace("??", "1")
131131

132-
133132
data.sort(key=lambda a: a["dub"])
134133

135134
return [

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
httpx
2+
httpx[http2]
3+
youtube_dl
4+
beautifulsoup4

tests/__init__.py

Whitespace-only changes.

tests/test_animeworld.py

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
import unittest
2+
3+
import unittest
4+
import random
5+
6+
import animeworld as aw
7+
from animeworld.servers import AnimeWorld_Server, Streamtape
8+
9+
class TestGeneral(unittest.TestCase):
10+
def test_find(self):
11+
"""
12+
Testa la funzione find.
13+
"""
14+
res = aw.find("Sabikui Bisco 2")
15+
16+
self.assertIsInstance(res, list)
17+
self.assertGreater(len(res), 0)
18+
19+
anime = random.choice(res)
20+
21+
self.assertIsInstance(anime, dict)
22+
23+
self.assertIn("id", anime)
24+
self.assertIn("name", anime)
25+
self.assertIn("jtitle", anime)
26+
self.assertIn("studio", anime)
27+
self.assertIn("release", anime)
28+
self.assertIn("episodes", anime)
29+
self.assertIn("state", anime)
30+
self.assertIn("story", anime)
31+
self.assertIn("categories", anime)
32+
self.assertIn("image", anime)
33+
self.assertIn("durationEpisodes", anime)
34+
self.assertIn("link", anime)
35+
self.assertIn("createdAt", anime)
36+
self.assertIn("language", anime)
37+
self.assertIn("year", anime)
38+
self.assertIn("dub", anime)
39+
self.assertIn("season", anime)
40+
self.assertIn("totViews", anime)
41+
self.assertIn("dayViews", anime)
42+
self.assertIn("weekViews", anime)
43+
self.assertIn("monthViews", anime)
44+
self.assertIn("malId", anime)
45+
self.assertIn("anilistId", anime)
46+
self.assertIn("mangaworldId", anime)
47+
self.assertIn("malVote", anime)
48+
self.assertIn("trailer", anime)
49+
50+
self.fail("Test")
51+
52+
class TestExceptions(unittest.TestCase):
53+
def test_Error404(self) -> None:
54+
"""
55+
Testa il corretto riconoscimento di una pagina 404.
56+
"""
57+
with self.assertRaises(aw.Error404):
58+
aw.Anime("https://www.animeworld.so/play/ttt")
59+
60+
# @unittest.skip("Link da aggiornare con uno non ancora disponibile.")
61+
def test_AnimeNotAvailable(self) -> None:
62+
"""
63+
Testa il corretto riconoscimento di un anime non ancora disponibile.
64+
"""
65+
res = aw.Anime("https://www.animeworld.so/play/sabikui-bisco-2.6CCbU")
66+
67+
with self.assertRaises(aw.AnimeNotAvailable):
68+
res.getEpisodes()
69+
70+
def test_ServerNotSupported(self) -> None:
71+
"""
72+
Testa il corretto riconoscimento di un server non supportato.
73+
"""
74+
ep = random.choice(aw.Anime("https://www.animeworld.so/play/fullmetal-alchemist-brotherhood.Ihtnf").getEpisodes())
75+
76+
server = [s for s in ep.links if s.Nid == 2][0]
77+
78+
with self.assertRaises(aw.ServerNotSupported):
79+
server.fileLink()
80+
81+
82+
class TestAnimeWorld(unittest.TestCase):
83+
@classmethod
84+
def setUpClass(cls) -> None:
85+
"""Inizializza la classe Anime."""
86+
cls.anime = aw.Anime("https://www.animeworld.so/play/fullmetal-alchemist-brotherhood.Ihtnf")
87+
88+
def test_anime(self):
89+
"""
90+
Testa l'ottenimento delle informazioni relative all'anime.
91+
"""
92+
self.assertIsInstance(self.anime.getName(), str)
93+
self.assertIsInstance(self.anime.getTrama(), str)
94+
95+
info = self.anime.getInfo()
96+
self.assertIsInstance(info, dict)
97+
self.assertIn('Categoria', info)
98+
self.assertIn('Audio', info)
99+
self.assertIn('Data di Uscita', info)
100+
self.assertIn('Stagione', info)
101+
self.assertIn('Studio', info)
102+
self.assertIn('Genere', info)
103+
self.assertIn('Voto', info)
104+
self.assertIn('Durata', info)
105+
self.assertIn('Episodi', info)
106+
self.assertIn('Stato', info)
107+
self.assertIn('Visualizzazioni', info)
108+
109+
def test_servers(self):
110+
"""
111+
Controlli relativi ai server.
112+
"""
113+
ep = random.choice(self.anime.getEpisodes())
114+
115+
servers = ep.links
116+
117+
animeworld_server = [e for e in servers if isinstance(e, AnimeWorld_Server)][0]
118+
streamtape_server = [e for e in servers if isinstance(e, Streamtape)][0]
119+
120+
self.assertEqual(animeworld_server.Nid, 9)
121+
self.assertEqual(animeworld_server.name, "AnimeWorld Server")
122+
123+
self.assertEqual(streamtape_server.Nid, 8)
124+
self.assertEqual(streamtape_server.name, "Streamtape")
125+
126+
self.assertIsInstance(animeworld_server.fileLink(), str)
127+
self.assertIsInstance(streamtape_server.fileLink(), str)
128+
129+
animeworld_info = animeworld_server.fileInfo()
130+
self.assertIsInstance(animeworld_info, dict)
131+
self.assertIn("content_type", animeworld_info)
132+
self.assertIn("total_bytes", animeworld_info)
133+
self.assertIn("last_modified", animeworld_info)
134+
self.assertIn("server_name", animeworld_info)
135+
self.assertIn("server_id", animeworld_info)
136+
self.assertIn("url", animeworld_info)
137+
138+
streamtape_info = streamtape_server.fileInfo()
139+
self.assertIsInstance(animeworld_info, dict)
140+
self.assertIn("content_type", streamtape_info)
141+
self.assertIn("total_bytes", streamtape_info)
142+
self.assertIn("last_modified", streamtape_info)
143+
self.assertIn("server_name", streamtape_info)
144+
self.assertIn("server_id", streamtape_info)
145+
self.assertIn("url", streamtape_info)
146+
147+
if __name__ == '__main__':
148+
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)