# 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 . """ Tests the ORM """ import datetime import pytest from opdb.db import models def test_naive_datetime(): """Tests using a naive datetime as attribute of a model raises an error.""" tz_date = datetime.datetime.now(tz=datetime.timezone.utc) naive_date = datetime.datetime.now() with pytest.raises(TypeError, match="timezone-aware datetime"): models.WebPageSnapshot( url="http://example.org/", snapshot_date=tz_date, snapshot_url=None, retrieved_at=naive_date, response_headers={"Content-Length": b"7"}, content=b"foo bar", ) with pytest.raises(TypeError, match="timezone-aware datetime"): models.WebPageSnapshot( url="http://example.org/", snapshot_date=naive_date, snapshot_url=None, retrieved_at=tz_date, response_headers={"Content-Length": b"7"}, content=b"foo bar", )