mirror of
https://github.com/leoncvlt/loconotion.git
synced 2024-08-30 18:12:12 +00:00
Add a sample unit test
This commit is contained in:
parent
ffc96882ed
commit
1e3e4654f3
0
loconotion/__init__.py
Normal file
0
loconotion/__init__.py
Normal 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")
|
||||
|
||||
|
@ -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,6 +297,8 @@ class Parser:
|
||||
|
||||
subpages = self.find_subpages(url, index, soup, hrefDomain)
|
||||
self.export_parsed_page(url, index, soup)
|
||||
|
||||
if parse_subpages:
|
||||
self.parse_subpages(index, subpages)
|
||||
|
||||
def load_correct_theme(self, url):
|
||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
12
tests/test_parser.py
Normal file
12
tests/test_parser.py
Normal 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
|
Loading…
Reference in New Issue
Block a user