db: Add tests for get_last_web_page_snapshot.
This commit is contained in:
parent
13ca40eaf7
commit
5f3e9d6225
|
@ -17,6 +17,7 @@ Tests basic insertion and retrieval functions
|
|||
"""
|
||||
|
||||
import datetime
|
||||
import random
|
||||
|
||||
from opdb.db import Db, models
|
||||
|
||||
|
@ -29,15 +30,41 @@ def test_missing_web_page_snapshot(opdb_db: Db):
|
|||
def test_add_web_page_snapshot(opdb_db: Db):
|
||||
"""Tests adding a web page and that it can be retrieved."""
|
||||
date = datetime.datetime.now(tz=datetime.timezone.utc)
|
||||
snapshot = models.WebPageSnapshot(
|
||||
url="http://example.org/",
|
||||
snapshot_date=datetime.datetime.now(tz=datetime.timezone.utc),
|
||||
snapshot_url=None,
|
||||
retrieved_at=date,
|
||||
retrieved_by="localhost",
|
||||
response_headers={"Content-Length": "7"},
|
||||
content=b"foo bar",
|
||||
)
|
||||
opdb_db.add_web_page_snapshots([snapshot])
|
||||
snapshots = [
|
||||
models.WebPageSnapshot(
|
||||
url=f"http://example.org/{i}",
|
||||
snapshot_date=datetime.datetime.now(tz=datetime.timezone.utc),
|
||||
snapshot_url=None,
|
||||
retrieved_at=date,
|
||||
retrieved_by="localhost",
|
||||
response_headers={"Content-Length": "7"},
|
||||
content=f"snapshot {i}".encode(),
|
||||
)
|
||||
for i in range(100)
|
||||
]
|
||||
opdb_db.add_web_page_snapshots(snapshots)
|
||||
|
||||
assert opdb_db.get_last_web_page_snapshot("http://example.org/") == snapshot
|
||||
assert opdb_db.get_last_web_page_snapshot("http://example.org/10") == snapshots[10]
|
||||
|
||||
|
||||
def test_get_last_web_page_snapshot(opdb_db: Db):
|
||||
"""Tests adding a web page and that it can be retrieved."""
|
||||
date = datetime.datetime.now(tz=datetime.timezone.utc)
|
||||
|
||||
snapshots = [
|
||||
models.WebPageSnapshot(
|
||||
url="http://example.org/",
|
||||
snapshot_date=datetime.datetime.now(tz=datetime.timezone.utc),
|
||||
snapshot_url=None,
|
||||
retrieved_at=date,
|
||||
retrieved_by="localhost",
|
||||
response_headers={"Content-Length": "7"},
|
||||
content=f"snapshot {i}".encode(),
|
||||
)
|
||||
for i in range(100)
|
||||
]
|
||||
last_snapshot = snapshots[-1]
|
||||
random.shuffle(snapshots)
|
||||
opdb_db.add_web_page_snapshots(snapshots)
|
||||
|
||||
assert opdb_db.get_last_web_page_snapshot("http://example.org/") == last_snapshot
|
||||
|
|
Loading…
Reference in New Issue