-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Download test files with a script * Fix frontpage parsing * Fix article comment parsing * Add mocks
- Loading branch information
Showing
12 changed files
with
13,062 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pathlib import Path | ||
|
||
from tweakers.utils import get | ||
|
||
URLS = { | ||
"topic": "https://gathering.tweakers.net/forum/list_messages/1908208", | ||
"frontpage": "https://tweakers.net/", | ||
"article": "https://tweakers.net/nieuws/212172/whatsapp-introduceert-functie-voor-korte-videoberichten.html", | ||
"user": "https://tweakers.net/gallery/1/", | ||
"active_topics": "https://gathering.tweakers.net/forum/list_activetopics", | ||
"find": "https://tweakers.net/forum/find?keyword=playstation", | ||
} | ||
|
||
|
||
for name, url in URLS.items(): | ||
print("Downloading", name) | ||
html = get(url).text | ||
if "Sorry, je gaat even iets te snel" in html: | ||
raise Exception("Still rate limited???") | ||
path = Path(f"tests/pages/{name}.html") | ||
path.parent.mkdir(parents=True, exist_ok=True) | ||
with path.open("w") as f: | ||
f.write(html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from requests_html import HTML, HTMLResponse, HTMLSession | ||
|
||
|
||
def mock_get(url: str): | ||
if "/nieuws/" in url: | ||
case = "article" | ||
elif "/list_messages/" in url: | ||
case = "topic" | ||
elif "/gallery/" in url: | ||
case = "user" | ||
elif "/list_activetopics" in url: | ||
case = "active_topics" | ||
elif "forum/find" in url: | ||
case = "find" | ||
elif url in ("https://tweakers.net/", "https://tweakers.net"): | ||
case = "frontpage" | ||
else: | ||
raise NotImplementedError(f"Url {url} not implemented") | ||
|
||
with open(f"tests/pages/{case}.html") as f: | ||
response = HTMLResponse(session=HTMLSession) | ||
response._html = HTML(html=f.read()) | ||
return response | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
from unittest import mock | ||
from tests.mocks import mock_get | ||
from tweakers import gathering | ||
|
||
|
||
@mock.patch("tweakers.gathering.get", mock_get) | ||
def test_active_topics(): | ||
assert len(gathering.active_topics()) > 0 | ||
|
||
|
||
@mock.patch("tweakers.gathering.get", mock_get) | ||
def test_search(): | ||
assert len(gathering.search("tweakers")) > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters