43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
# This file is part of the Open Parts Database software
|
|
# Copyright (C) 2022 Valentin Lorentz
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it under the
|
|
# terms of the GNU Affero General Public License version 3, as published by the
|
|
# Free Software Foundation.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
# PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License along with
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
Tests basic insertion and retrieval functions
|
|
"""
|
|
|
|
import datetime
|
|
|
|
from opdb.db import Db, models
|
|
|
|
|
|
def test_missing_web_page_snapshot(opdb_db: Db):
|
|
"""Tests retrieving a missing web page returns None."""
|
|
assert opdb_db.get_last_web_page_snapshot("http://nonexistent.org") is None
|
|
|
|
|
|
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,
|
|
response_headers={"Content-Length": "7"},
|
|
content=b"foo bar",
|
|
)
|
|
opdb_db.add_web_page_snapshots([snapshot])
|
|
|
|
assert opdb_db.get_last_web_page_snapshot("http://example.org/") == snapshot
|