mirror of
https://codeberg.org/Ewen/rudibridge.git
synced 2024-12-22 03:02:32 +00:00
wip: tests
This commit is contained in:
parent
c7e05772fc
commit
36831099fa
4
api/.coveragerc
Normal file
4
api/.coveragerc
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[run]
|
||||||
|
omit = tests/*,**/__init__.py
|
||||||
|
|
||||||
|
[html]
|
37
api/poetry.lock
generated
37
api/poetry.lock
generated
|
@ -824,6 +824,41 @@ pluggy = ">=1.5,<2.0"
|
||||||
[package.extras]
|
[package.extras]
|
||||||
dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
|
dev = ["argcomplete", "attrs (>=19.2)", "hypothesis (>=3.56)", "mock", "pygments (>=2.7.2)", "requests", "setuptools", "xmlschema"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pytest-cov"
|
||||||
|
version = "5.0.0"
|
||||||
|
description = "Pytest plugin for measuring coverage."
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.8"
|
||||||
|
files = [
|
||||||
|
{file = "pytest-cov-5.0.0.tar.gz", hash = "sha256:5837b58e9f6ebd335b0f8060eecce69b662415b16dc503883a02f45dfeb14857"},
|
||||||
|
{file = "pytest_cov-5.0.0-py3-none-any.whl", hash = "sha256:4f0764a1219df53214206bf1feea4633c3b558a2925c8b59f144f682861ce652"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
coverage = {version = ">=5.2.1", extras = ["toml"]}
|
||||||
|
pytest = ">=4.6"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
testing = ["fields", "hunter", "process-tests", "pytest-xdist", "virtualenv"]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pytest-mock"
|
||||||
|
version = "3.14.0"
|
||||||
|
description = "Thin-wrapper around the mock package for easier use with pytest"
|
||||||
|
optional = false
|
||||||
|
python-versions = ">=3.8"
|
||||||
|
files = [
|
||||||
|
{file = "pytest-mock-3.14.0.tar.gz", hash = "sha256:2719255a1efeceadbc056d6bf3df3d1c5015530fb40cf347c0f9afac88410bd0"},
|
||||||
|
{file = "pytest_mock-3.14.0-py3-none-any.whl", hash = "sha256:0b72c38033392a5f4621342fe11e9219ac11ec9d375f8e2a0c164539e0d70f6f"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
pytest = ">=6.2.5"
|
||||||
|
|
||||||
|
[package.extras]
|
||||||
|
dev = ["pre-commit", "pytest-asyncio", "tox"]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "python-dateutil"
|
name = "python-dateutil"
|
||||||
version = "2.9.0.post0"
|
version = "2.9.0.post0"
|
||||||
|
@ -1208,4 +1243,4 @@ h11 = ">=0.9.0,<1"
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "5daa79623cbf7897be36e0f03161d313b789b393341f1848daaf2c1d0013aed8"
|
content-hash = "4e8ea5ad711699c1fd0d3936d7c03d51d309651e9d46daac7b5eacf90f656b44"
|
||||||
|
|
|
@ -17,8 +17,13 @@ botasaurus = "^4.0.14"
|
||||||
dateparser = "^1.2.0"
|
dateparser = "^1.2.0"
|
||||||
validators = "^0.28.1"
|
validators = "^0.28.1"
|
||||||
flask-cors = "^4.0.1"
|
flask-cors = "^4.0.1"
|
||||||
|
pytest-mock = "^3.14.0"
|
||||||
|
pytest-cov = "^5.0.0"
|
||||||
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core"]
|
requires = ["poetry-core"]
|
||||||
build-backend = "poetry.core.masonry.api"
|
build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
addopts = "-s --cov=api --cov-report html"
|
4813
api/tests/ouest-france_rennes.html
Normal file
4813
api/tests/ouest-france_rennes.html
Normal file
File diff suppressed because one or more lines are too long
19
api/tests/test_feed.py
Normal file
19
api/tests/test_feed.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_InvalidParameters_init():
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_InvalidParameters_to_dict():
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_invalid_parameters():
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_return_rss(mocker):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_return_json(mocker):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_return_valid_rss(mocker):
|
||||||
|
assert False
|
|
@ -4,10 +4,10 @@ import pytest
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"url,missing_parameter",
|
"url,missing_parameter",
|
||||||
[
|
[
|
||||||
("/feed/", "URL"),
|
("/api/feed/", "URL"),
|
||||||
("/feed/?url=https://mozilla.org", "article"),
|
("/api/feed/?url=https://mozilla.org", "article"),
|
||||||
("/feed/?url=https://mozilla.org&article=article", "title"),
|
("/api/feed/?url=https://mozilla.org&article=article", "title"),
|
||||||
("/feed/?url=https://mozilla.org&title=h2&article=article", None),
|
("/api/feed/?url=https://mozilla.org&title=h2&article=article", None),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_missing_parameters(client, url, missing_parameter):
|
def test_missing_parameters(client, url, missing_parameter):
|
||||||
|
@ -29,7 +29,7 @@ def test_missing_parameters(client, url, missing_parameter):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_incorrect_url(client, url, status_code, message):
|
def test_incorrect_url(client, url, status_code, message):
|
||||||
response = client.get(f"/feed/?url={url}&title=h2&article=article")
|
response = client.get(f"/api/feed/?url={url}&title=h2&article=article")
|
||||||
assert response.status_code == status_code
|
assert response.status_code == status_code
|
||||||
if message:
|
if message:
|
||||||
assert response.json["message"] == message
|
assert response.json["message"] == message
|
||||||
|
|
32
api/tests/test_scraping.py
Normal file
32
api/tests/test_scraping.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from api.scraper import scrape
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
import botasaurus as bt
|
||||||
|
|
||||||
|
# Mocks
|
||||||
|
def ouestfrance_soup():
|
||||||
|
with open("./tests/ouest-france_rennes.html") as file:
|
||||||
|
soup = BeautifulSoup(file, "html.parser")
|
||||||
|
return soup
|
||||||
|
|
||||||
|
def test_scrape_contains_title_url_items(mocker):
|
||||||
|
mocker.patch('botasaurus.anti_detect_requests.AntiDetectRequests.bs4', return_value=ouestfrance_soup())
|
||||||
|
toto = scrape({'url': 'toto', 'article': 'article'})
|
||||||
|
print(toto.to_json())
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_scrape_items_list_contains_items(mocker):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_scrape_feed_is_valid(mocker):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_scraped_articles_contain_titles(mocker):
|
||||||
|
assert False
|
||||||
|
|
||||||
|
def test_scraped_articles_contain_images(mocker):
|
||||||
|
assert False
|
||||||
|
|
Loading…
Reference in a new issue