Skip to content

Commit 37dc542

Browse files
committed
chore: add integration tests
1 parent 13d5e71 commit 37dc542

7 files changed

Lines changed: 113 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ jobs:
2323
python-version: ${{ matrix.python-version }}
2424
cache: "pip"
2525
- name: Install Dependencies
26-
run: python -m pip install --upgrade pip setuptools tox
26+
run: |
27+
python -m pip install --upgrade pip setuptools playwright tox
28+
playwright install --with-deps --only-shell
2729
- name: Run tox
28-
run: tox
30+
run: tox -p auto
2931
analyze:
3032
runs-on: [ubuntu-latest]
3133
permissions:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ python -m venv .venv
99
source .venv/bin/activate
1010
pip install playwright
1111
playwright install
12-
pip install ruff codespell ty tox
12+
pip install ruff codespell ty pytest pytest-asyncio tox
1313
```
1414

1515
Reenter Virtual Environment

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ dev = [
3434
"ruff>=0.15.14",
3535
"codespell>=2.4.2",
3636
"ty>=0.0.40",
37+
"pytest>=9.1.0",
38+
"pytest-asyncio>=1.4.0",
3739
"tox>=4.55.0",
3840
]
3941

@@ -45,3 +47,4 @@ where = ["src"]
4547

4648
[tool.pytest.ini_options]
4749
testpaths = ["tests"]
50+
addopts = "-ra"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
from playwright.async_api import async_playwright
3+
4+
from graphicnovelpricescraper.retailers.amazon import Amazon
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_scrape():
9+
isbn = 9781779515681
10+
11+
async with async_playwright() as p:
12+
browser = await p.chromium.launch(headless=True)
13+
14+
retailer = Amazon(browser)
15+
await retailer.create_context()
16+
17+
try:
18+
data = await retailer.scrape(isbn, "")
19+
20+
assert data.isbn == isbn
21+
assert data.retailer == "Amazon"
22+
23+
if data.title is not None:
24+
assert isinstance(data.title, str)
25+
if data.price is not None:
26+
assert data.price > 0.0
27+
if data.url is not None:
28+
assert data.url.startswith("https://www.amazon.com")
29+
finally:
30+
if retailer.context is not None:
31+
await retailer.context.close()
32+
await browser.close()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
from playwright.async_api import async_playwright
3+
4+
from graphicnovelpricescraper.retailers.barnesandnoble import BarnesAndNoble
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_scrape():
9+
isbn = 9781779515681
10+
11+
async with async_playwright() as p:
12+
browser = await p.chromium.launch(headless=True)
13+
14+
retailer = BarnesAndNoble(browser)
15+
await retailer.create_context()
16+
17+
try:
18+
data = await retailer.scrape(isbn, "")
19+
20+
assert data.isbn == isbn
21+
assert data.retailer == "Barnes & Noble"
22+
23+
if data.title is not None:
24+
assert isinstance(data.title, str)
25+
if data.price is not None:
26+
assert data.price > 0.0
27+
if data.url is not None:
28+
assert data.url.startswith("https://www.barnesandnoble.com")
29+
finally:
30+
if retailer.context is not None:
31+
await retailer.context.close()
32+
await browser.close()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
from playwright.async_api import async_playwright
3+
4+
from graphicnovelpricescraper.retailers.cheapgraphicnovels import CheapGraphicNovels
5+
6+
7+
@pytest.mark.asyncio
8+
async def test_scrape():
9+
isbn = 9781779515681
10+
11+
async with async_playwright() as p:
12+
browser = await p.chromium.launch(headless=True)
13+
14+
retailer = CheapGraphicNovels(browser)
15+
await retailer.create_context()
16+
17+
try:
18+
data = await retailer.scrape(isbn, "")
19+
20+
assert data.isbn == isbn
21+
assert data.retailer == "Cheap Graphic Novels"
22+
23+
if data.title is not None:
24+
assert isinstance(data.title, str)
25+
if data.price is not None:
26+
assert data.price > 0.0
27+
if data.url is not None:
28+
assert data.url.startswith("https://cheapgraphicnovels.com/")
29+
finally:
30+
if retailer.context is not None:
31+
await retailer.context.close()
32+
await browser.close()

tox.ini

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
env_list = format, spell, type, lint
2+
env_list = format, spell, type, lint, test
33

44
[testenv:format]
55
deps =
@@ -16,6 +16,7 @@ commands =
1616
[testenv:type]
1717
deps =
1818
ty
19+
pytest
1920
commands =
2021
ty check
2122

@@ -24,3 +25,10 @@ deps =
2425
ruff
2526
commands =
2627
ruff check
28+
29+
[testenv:test]
30+
deps =
31+
pytest
32+
pytest-asyncio
33+
commands =
34+
pytest

0 commit comments

Comments
 (0)