mirror of
https://github.com/RicterZ/nhentai.git
synced 2025-07-02 00:19:29 +02:00
add tests
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
36
tests/test_download.py
Normal file
36
tests/test_download.py
Normal file
@ -0,0 +1,36 @@
|
||||
import unittest
|
||||
import os
|
||||
import urllib3.exceptions
|
||||
|
||||
from nhentai import constant
|
||||
from nhentai.cmdline import load_config
|
||||
from nhentai.downloader import Downloader
|
||||
from nhentai.parser import doujinshi_parser
|
||||
from nhentai.doujinshi import Doujinshi
|
||||
from nhentai.utils import generate_html, generate_cbz
|
||||
|
||||
|
||||
class TestDownload(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
load_config()
|
||||
constant.CONFIG['cookie'] = os.getenv('NHENTAI_COOKIE')
|
||||
constant.CONFIG['useragent'] = os.getenv('NHENTAI_UA')
|
||||
|
||||
def test_download(self):
|
||||
did = 440546
|
||||
info = Doujinshi(**doujinshi_parser(did), name_format='%i')
|
||||
info.downloader = Downloader(path='/tmp', size=5)
|
||||
info.download()
|
||||
|
||||
self.assertTrue(os.path.exists(f'/tmp/{did}/001.jpg'))
|
||||
|
||||
generate_html('/tmp', info)
|
||||
self.assertTrue(os.path.exists(f'/tmp/{did}/index.html'))
|
||||
|
||||
generate_cbz('/tmp', info)
|
||||
self.assertTrue(os.path.exists(f'/tmp/{did}.cbz'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
26
tests/test_login.py
Normal file
26
tests/test_login.py
Normal file
@ -0,0 +1,26 @@
|
||||
import os
|
||||
import unittest
|
||||
import urllib3.exceptions
|
||||
|
||||
from nhentai import constant
|
||||
from nhentai.cmdline import load_config
|
||||
from nhentai.utils import check_cookie
|
||||
|
||||
|
||||
class TestLogin(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
load_config()
|
||||
constant.CONFIG['cookie'] = os.getenv('NHENTAI_COOKIE')
|
||||
constant.CONFIG['useragent'] = os.getenv('NHENTAI_UA')
|
||||
|
||||
def test_cookie(self):
|
||||
try:
|
||||
check_cookie()
|
||||
self.assertTrue(True)
|
||||
except Exception as e:
|
||||
self.assertIsNone(e)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
27
tests/test_parser.py
Normal file
27
tests/test_parser.py
Normal file
@ -0,0 +1,27 @@
|
||||
import unittest
|
||||
import os
|
||||
import urllib3.exceptions
|
||||
|
||||
from nhentai import constant
|
||||
from nhentai.cmdline import load_config
|
||||
from nhentai.parser import search_parser, doujinshi_parser, favorites_parser
|
||||
|
||||
|
||||
class TestParser(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
load_config()
|
||||
constant.CONFIG['cookie'] = os.getenv('NHENTAI_COOKIE')
|
||||
constant.CONFIG['useragent'] = os.getenv('NHENTAI_UA')
|
||||
|
||||
def test_search(self):
|
||||
result = search_parser('umaru', 'recent', [1], False)
|
||||
self.assertTrue(len(result) > 0)
|
||||
|
||||
def test_doujinshi_parser(self):
|
||||
result = doujinshi_parser(123456)
|
||||
self.assertTrue(result['pages'] == 84)
|
||||
|
||||
def test_favorites_parser(self):
|
||||
result = favorites_parser(page=[1])
|
||||
self.assertTrue(len(result) > 0)
|
Reference in New Issue
Block a user