ordigi/tests/test_database.py

131 lines
3.7 KiB
Python
Raw Permalink Normal View History

2021-08-31 16:18:41 +02:00
from datetime import datetime
2021-08-31 16:18:41 +02:00
from pathlib import Path
import pytest
import shutil
import sqlite3
from ordigi.database import Sqlite
class TestSqlite:
@pytest.fixture(autouse=True)
def setup_class(cls, tmp_path):
cls.test='abs'
cls.sqlite = Sqlite(tmp_path)
row_data = {
'FilePath': 'file_path',
'Checksum': 'checksum',
'Album': 'album',
'Title': 'title',
'LocationId': 2,
'DateMedia': datetime(2012, 3, 27),
'DateOriginal': datetime(2013, 3, 27),
'DateCreated': 'date_created',
'DateModified': 'date_modified',
'FileModifyDate': 'file_modify_date',
'CameraMake': 'camera_make',
'CameraModel': 'camera_model',
'OriginalName':'original_name',
2022-04-23 18:40:34 +02:00
'SrcDir': 'src_dir',
'Subdirs': 'subdirs',
'Filename': 'filename'
}
location_data = {
'Latitude': 24.2,
'Longitude': 7.3,
'LatitudeRef': 'latitude_ref',
'LongitudeRef': 'longitude_ref',
'City': 'city',
'State': 'state',
'Country': 'country',
2022-04-23 13:01:55 +02:00
'Location': 'location'
}
2022-04-23 18:40:34 +02:00
cls.sqlite.upsert_metadata(row_data)
cls.sqlite.upsert_location(location_data)
# cls.sqlite.add_metadata_data('filename', 'ksinslsdosic', 'original_name', 'date_original', 'album', 1)
2022-04-23 13:01:55 +02:00
# cls.sqlite.add_location(24.2, 7.3, 'city', 'state', 'country', 'location')
2021-08-31 16:18:41 +02:00
yield
shutil.rmtree(tmp_path)
def test_init(self):
assert isinstance(self.sqlite.filename, Path)
assert isinstance(self.sqlite.con, sqlite3.Connection)
assert isinstance(self.sqlite.cur, sqlite3.Cursor)
def test_create_table(self):
assert self.sqlite.is_table('metadata')
assert self.sqlite.is_table('location')
2021-08-31 16:18:41 +02:00
def test_add_metadata_data(self):
result = tuple(self.sqlite.cur.execute("""select * from metadata where
2021-08-31 16:18:41 +02:00
rowid=1""").fetchone())
assert result == (
2022-04-23 18:40:34 +02:00
1,
'file_path',
'checksum',
'album',
'title',
2,
'2012-03-27 00:00:00',
'2013-03-27 00:00:00',
'date_created',
'date_modified',
'file_modify_date',
'camera_make',
'camera_model',
'original_name',
2022-04-23 18:40:34 +02:00
'src_dir',
'subdirs',
'filename'
)
2021-08-31 16:18:41 +02:00
def test_get_checksum(self):
assert not self.sqlite.get_checksum('invalid')
assert self.sqlite.get_checksum('file_path') == 'checksum'
2021-08-31 16:18:41 +02:00
2022-04-23 13:01:55 +02:00
def test_get_metadata(self):
assert not self.sqlite.get_metadata('invalid', 'DateOriginal')
assert self.sqlite.get_metadata('file_path', 'Album') == 'album'
2021-08-31 16:18:41 +02:00
def test_add_location(self):
result = tuple(self.sqlite.cur.execute("""select * from location where
rowid=1""").fetchone())
2022-04-23 13:01:55 +02:00
assert result == (
2022-04-23 18:40:34 +02:00
1,
24.2,
7.3,
2022-04-23 13:01:55 +02:00
'latitude_ref',
'longitude_ref',
'city',
'state',
'country',
'location',
)
2021-08-31 16:18:41 +02:00
@pytest.mark.skip('TODO')
def test_get_location_data(self, LocationId, data):
pass
@pytest.mark.skip('TODO')
def test_get_location(self, Latitude, Longitude, column):
pass
def test_get_location_nearby(self):
2022-04-23 13:01:55 +02:00
value = self.sqlite.get_location_nearby(24.2005, 7.3004, 'Location')
assert value == 'location'
2021-08-31 16:18:41 +02:00
@pytest.mark.skip('TODO')
def test_delete_row(self, table, id):
pass
@pytest.mark.skip('TODO')
def test_delete_all_rows(self, table):
pass