Add a sample unit test

This commit is contained in:
Alexey Leshchenko 2022-02-18 13:46:09 +03:00
parent ffc96882ed
commit 1e3e4654f3
5 changed files with 19 additions and 4 deletions

0
loconotion/__init__.py Normal file
View File

View File

@ -6,7 +6,7 @@ import sys
import urllib.parse
from pathlib import Path
from notionparser import Parser
from .notionparser import Parser
log = logging.getLogger("loconotion")

View File

@ -28,7 +28,7 @@ except ModuleNotFoundError as error:
log.critical(f"ModuleNotFoundError: {error}. have your installed the requirements?")
sys.exit()
from conditions import notion_page_loaded, toggle_block_has_opened
from .conditions import notion_page_loaded, toggle_block_has_opened
class Parser:
@ -243,12 +243,13 @@ class Parser:
options=chrome_options,
)
def parse_page(self, url: str, index: str = None):
def parse_page(self, url: str, index: str = None, parse_subpages=True):
"""Parse page at url and write it to file, then recursively parse all subpages.
Args:
url (str): URL of the page to parse.
index (str, optional): URL of the index page. Defaults to None.
parse_subpages (bool): if subpages should be parsed. Used for testing.
After the page at `url` has been parsed, calls itself recursively for every subpage
it has discovered.
@ -296,7 +297,9 @@ class Parser:
subpages = self.find_subpages(url, index, soup, hrefDomain)
self.export_parsed_page(url, index, soup)
self.parse_subpages(index, subpages)
if parse_subpages:
self.parse_subpages(index, subpages)
def load_correct_theme(self, url):
self.load(url)

0
tests/__init__.py Normal file
View File

12
tests/test_parser.py Normal file
View File

@ -0,0 +1,12 @@
import pytest
from loconotion.notionparser import Parser
def test_parse_sample_page():
config={"page": "https://www.notion.so/Loconotion-Example-Page-03c403f4fdc94cc1b315b9469a8950ef"}
args = {"timeout": 10}
parser = Parser(config, args)
parser.processed_pages = {}
parser.parse_page(parser.starting_url, parse_subpages=False)
assert parser.starting_url in parser.processed_pages