Skip to content

Commit

Permalink
feat(db): add insert timestamp to blob table
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasschaub committed Apr 16, 2024
1 parent 4eaee8d commit 73ebf88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion sketch_map_tool/database/client_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def insert_files(files) -> list[int]:
CREATE TABLE IF NOT EXISTS blob(
id SERIAL PRIMARY KEY,
file_name VARCHAR,
file BYTEA
file BYTEA,
ts timestamp default current_timestamp
)
"""
insert_query = "INSERT INTO blob(file_name, file) VALUES (%s, %s) RETURNING id"
Expand Down
14 changes: 13 additions & 1 deletion tests/integration/test_database_client_flask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from io import BytesIO
from uuid import uuid4

Expand All @@ -23,7 +24,7 @@ def files(file):
return [file, file]


@pytest.fixture()
@pytest.fixture
def file_ids(files, flask_app):
"""IDs of uploaded files stored in the database."""
with flask_app.app_context():
Expand Down Expand Up @@ -123,3 +124,14 @@ def test_select_map_frame_file_not_found(flask_app):
with flask_app.app_context():
with pytest.raises(CustomFileNotFoundError):
client_flask.select_map_frame(uuid4())


def test_blob_timestamp(file_ids):
"""Test if timestamp is created when inserting data."""
query = "SELECT ts FROM blob WHERE id = %s"
db_conn = client_flask.open_connection()
with db_conn.cursor() as curs:
curs.execute(query, [file_ids[0]])
raw = curs.fetchone()
timestamp = raw[0]
assert isinstance(timestamp, datetime)

0 comments on commit 73ebf88

Please sign in to comment.