From 875e9753aa86850c48940c97569b6d41632c944e Mon Sep 17 00:00:00 2001 From: Vishnunarayan K I Date: Wed, 13 Mar 2019 19:36:23 +0530 Subject: [PATCH] tests: Try to fix tests pt1 --- Pipfile | 1 + Pipfile.lock | 15 ++++++++--- anime_downloader/sites/helpers/request.py | 2 +- tests/sites/nineanime/nineanime.py | 8 ++++++ tests/sites/nineanime/webpages/naruto.xx8z | 17 +++++++++++++ tests/sites/site.py | 29 ++++++++++++++++++++++ 6 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 tests/sites/nineanime/nineanime.py create mode 100644 tests/sites/nineanime/webpages/naruto.xx8z create mode 100644 tests/sites/site.py diff --git a/Pipfile b/Pipfile index e9db80a..03a6a6a 100644 --- a/Pipfile +++ b/Pipfile @@ -12,3 +12,4 @@ sphinx = "*" sphinx-rtd-theme = "*" radon = "*" "flake8" = "*" +httpretty = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 12ad9c7..eb42874 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "457dc98718285d0b6166dc6acec90e416c6578bc88d2ecc12337a38848c863f3" + "sha256": "b9e8edea14fa675cf93739cb8693974b6265707ca166796e71a56c0c724c9471" }, "pipfile-spec": 6, "requires": {}, @@ -186,6 +186,13 @@ ], "version": "==1.0.2" }, + "httpretty": { + "hashes": [ + "sha256:01b52d45077e702eda491f4fe75328d3468fd886aed5dcc530003e7b2b5939dc" + ], + "index": "pypi", + "version": "==0.9.6" + }, "idna": { "hashes": [ "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", @@ -348,11 +355,11 @@ }, "sphinx": { "hashes": [ - "sha256:b53904fa7cb4b06a39409a492b949193a1b68cc7241a1a8ce9974f86f0d24287", - "sha256:c1c00fc4f6e8b101a0d037065043460dffc2d507257f2f11acaed71fd2b0c83c" + "sha256:9f3e17c64b34afc653d7c5ec95766e03043cc6d80b0de224f59b6b6e19d37c3c", + "sha256:c7658aab75c920288a8cf6f09f244c6cfdae30d82d803ac1634d9f223a80ca08" ], "index": "pypi", - "version": "==1.8.4" + "version": "==1.8.5" }, "sphinx-rtd-theme": { "hashes": [ diff --git a/anime_downloader/sites/helpers/request.py b/anime_downloader/sites/helpers/request.py index 7bebc0d..0779a91 100644 --- a/anime_downloader/sites/helpers/request.py +++ b/anime_downloader/sites/helpers/request.py @@ -116,7 +116,7 @@ def _log_response_body(res): data.append({ 'method': res.request.method, 'url': res.url, - 'file': file, + 'file': '/' + file.split('/')[-1], }) with open(data_file, 'w') as f: json.dump(data, f) diff --git a/tests/sites/nineanime/nineanime.py b/tests/sites/nineanime/nineanime.py new file mode 100644 index 0000000..c3ae0f3 --- /dev/null +++ b/tests/sites/nineanime/nineanime.py @@ -0,0 +1,8 @@ +import httpretty + +from ..site import MockSite + + +class MockNineanime(MockSite): + def url(self): + return 'https://' diff --git a/tests/sites/nineanime/webpages/naruto.xx8z b/tests/sites/nineanime/webpages/naruto.xx8z new file mode 100644 index 0000000..2b19a93 --- /dev/null +++ b/tests/sites/nineanime/webpages/naruto.xx8z @@ -0,0 +1,17 @@ + 9Anime - Watch Naruto English Subbed in HD on 9anime.vip

Naruto

Auto Play
Auto Next
Report

Naruto

Naruto; NARUTO; ナルト

2,097 votes
Type:
TV Series
Studios:
Studio Pierrot
Date aired:
Oct 03, 2002 to Feb 08, 2007
Status:
Completed
Genre:
Action, Comedy, Martial Arts, Shounen, Super Power
Scores:
7.86 / 593,585
Rating:
8.5 / 2,097 times
Premiered:
Fall 2002
Duration:
23 min/ep
Quality:
SD
Views:
1,731,311
Moments prior to Naruto Uzumaki's birth, a huge demon known as the Kyuubi, the Nine-Tailed Fox, attacked Konohagakure, the Hidden Leaf Village, and wreaked havoc. In order to put an end to the Kyuubi's rampage, the leader of the village, the Fourth Hokage, sacrificed his life and sealed the monstrous beast inside the newborn Naruto. Now, Naruto is a hyperactive and knuckle-headed ninja still living in Konohagakure. Shunned because of the Kyuubi inside him, Naruto struggles to find his place in the village, while his burning desire to become the Hokage of Konohagakure leads him not only to some great new friends, but also some deadly foes. [Written by MAL Rewrite]
\ No newline at end of file diff --git a/tests/sites/site.py b/tests/sites/site.py new file mode 100644 index 0000000..84d1fa0 --- /dev/null +++ b/tests/sites/site.py @@ -0,0 +1,29 @@ +from abc import ABCMeta, abstractmethod, abstractproperty +import httpretty +import json + + +class MockSite(metaclass=ABCMeta): + def __init__(self): + self.setup_httpretty() + + def setup_httpretty(self): + data_file = 'webpages/data.json' + data = None + with open(data_file) as f: + data = json.load(f) + + for obj in data: + method = httpretty.POST + if obj['method'] == 'GET': + method = httpretty.GET + with open('webpages' + obj['file']) as f: + httpretty.register_uri( + method, + obj['url'], + f.read(), + ) + + @abstractproperty + def url(self): + raise NotImplementedError