Skip to content

Commit

Permalink
fix tests for ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
safirex committed Dec 10, 2022
1 parent 3c9877b commit a53e471
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
14 changes: 11 additions & 3 deletions src/Downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def onChapterListFetched(self):

# TODO: updateObject should be in a NovelFactory
class Novel(NovelCallbacks):
def __init__(self, codeNovel, titreNovel, keep_text_format=False):
def __init__(self, codeNovel, titreNovel='', keep_text_format=False):
super().__init__()
self.code = codeNovel
self.titre = titreNovel
Expand Down Expand Up @@ -416,6 +416,9 @@ def __init__(self, novel):
super().__init__(novel.code, novel.titre, novel.keep_text_format)
# self.cookie={'autologin':getCookies()}

def setUrl(self):
self.url = self.site + '/%s/' % self.code

def processNovel(self):
import http.cookiejar as cookielib
import mechanize
Expand Down Expand Up @@ -472,7 +475,7 @@ def processChapter(self, chapter_num):

def getNovelTitle(self, html=''):
# https://novel18.syosetu.com/n8451sz/
url = self.site + '/%s/' % self.code
url = self.url
print('\naccessing: ' + url)
# https://novel18.syosetu.com/n8451sz
# cookies={'autologin':'1872412%3C%3E014ebbec6d4b5ba4b35b8b5853e19625f9e6bf77eb2609658c927a0a8b4989b6'}
Expand All @@ -497,6 +500,10 @@ def __createFile__(self, chapterNumber, chapter_title, chapter_content):
file.close()
print('\n\n')


def fetchTOCPage(self):
return self.connectViaMechanize(self.url)

def connectViaMechanize(self, url):
import http.cookiejar as cookielib
import mechanize
Expand Down Expand Up @@ -634,6 +641,7 @@ def processChapter(self, chapter_url, chapter_num):
chapter.getContent(chapter_html)
return chapter


def connectViaMechanize(self, url):
import http.cookiejar as cookielib
from bs4 import BeautifulSoup
Expand Down Expand Up @@ -664,7 +672,7 @@ def connectViaMechanize(self, url):
resp = br.response()
content = resp.get_data()
soup = BeautifulSoup(content, 'html.parser')
return str(soup)
return soup.text

class NovelPia(Novel):
def __init__(self, novel):
Expand Down
68 changes: 54 additions & 14 deletions src/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
sys.path.append('src')

from main_functions import findNovel
from Downloaders import KakuyomuNovel, Novel
from Downloaders import *
from archive_updater import check_env


Expand All @@ -18,27 +18,67 @@

class TestMainFunctions(unittest.TestCase):

def setUp(self):
os.mkdir('novel_list')

def test_find(self):
def setUp(self):
self.assertTrue(len(findNovel("")) ==
len(os.listdir('novel_list')))

def builder(self):
novel=Novel(16816452220453312822)
self.assertTrue(novel.__class__==Novel.__class__)
novel=novel.updateObject();
self.assertTrue(novel.__class__==KakuyomuNovel.__class__)

# def suite():
# suite= unittest.TestSuite()
# suite.addTest()
def test_builder(self):

x = Novel('n18n2935bp', 'memory rewrite ')
x = x.updateObject()
self.assertTrue(x.__class__ == N18SyosetuNovel )

''' tests Syosetu '''
def test_SyosetuNovel(self):
novel=Novel('n5080fi')
self.assertTrue(novel.__class__ == Novel)
novel=novel.updateObject()
self.assertTrue(novel.__class__ == SyosetuNovel)

def test_fetchSyosetu(self):
novel=Novel('n5080fi')
novel=novel.updateObject()
html = novel.fetchTOCPage()
self.assertTrue(html != '')
self.assertRegex(html,'novel_ex')


''' tests kakyomu '''
def test_KakyomuNovel(self):
novel=Novel('16816452220453312822')
self.assertTrue(novel.__class__ == Novel)
novel=novel.updateObject()
self.assertTrue(novel.__class__ == KakuyomuNovel)

def test_fetchKakyomu(self):
novel=Novel('16816452220453312822')
novel=novel.updateObject()
html = novel.fetchTOCPage()
self.assertTrue(html != '')
self.assertRegex(html,'workTitle')



''' tests n18 '''
def test_n18SyosetuNovel(self):
novel=Novel('n18n6426w')
self.assertTrue(novel.__class__ == Novel)
novel=novel.updateObject()
self.assertTrue(novel.__class__ == N18SyosetuNovel)

def test_fetchN18Syosetu(self):
novel=Novel('n18n6426w')
novel=novel.updateObject()
html = novel.fetchTOCPage()
self.assertTrue(html != '')
self.assertRegex(html,'novel_ex')




if __name__ == '__main__':
check_env()
os.mkdir('novel_list')
unittest.main()
# runner = unittest.TextTestRunner()
# runner.run(suite())

0 comments on commit a53e471

Please sign in to comment.