2021-08-31 16:18:41 +02:00
|
|
|
|
2021-09-12 07:41:44 +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)
|
2021-09-12 07:41:44 +02:00
|
|
|
|
|
|
|
row_data = {
|
|
|
|
'FilePath': 'file_path',
|
|
|
|
'Checksum': 'checksum',
|
|
|
|
'Album': 'album',
|
2021-09-26 17:44:13 +02:00
|
|
|
'Title': 'title',
|
2021-09-12 07:41:44 +02:00
|
|
|
'LocationId': 2,
|
2021-09-26 17:44:13 +02:00
|
|
|
'DateMedia': datetime(2012, 3, 27),
|
2021-09-12 07:41:44 +02:00
|
|
|
'DateOriginal': datetime(2013, 3, 27),
|
|
|
|
'DateCreated': 'date_created',
|
|
|
|
'DateModified': 'date_modified',
|
|
|
|
'CameraMake': 'camera_make',
|
|
|
|
'CameraModel': 'camera_model',
|
2021-09-26 17:44:13 +02:00
|
|
|
'OriginalName':'original_name',
|
2021-09-12 07:41:44 +02:00
|
|
|
'SrcPath': 'src_path',
|
|
|
|
'Subdirs': 'subdirs',
|
|
|
|
'Filename': 'filename'
|
|
|
|
}
|
|
|
|
|
|
|
|
location_data = {
|
|
|
|
'Latitude': 24.2,
|
|
|
|
'Longitude': 7.3,
|
|
|
|
'LatitudeRef': 'latitude_ref',
|
|
|
|
'LongitudeRef': 'longitude_ref',
|
|
|
|
'City': 'city',
|
|
|
|
'State': 'state',
|
|
|
|
'Country': 'country',
|
|
|
|
'Default': 'default'
|
|
|
|
}
|
|
|
|
|
|
|
|
cls.sqlite.add_row('metadata', row_data)
|
|
|
|
cls.sqlite.add_row('location', location_data)
|
|
|
|
# cls.sqlite.add_metadata_data('filename', 'ksinslsdosic', 'original_name', 'date_original', 'album', 1)
|
|
|
|
# cls.sqlite.add_location(24.2, 7.3, 'city', 'state', 'country', 'default')
|
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)
|
|
|
|
|
2021-09-12 07:41:44 +02:00
|
|
|
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
|
|
|
|
2021-09-12 07:41:44 +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())
|
2021-09-26 17:44:13 +02:00
|
|
|
assert result == ('file_path', 'checksum', 'album', 'title', 2, '2012-03-27 00:00:00', '2013-03-27 00:00:00', 'date_created', 'date_modified', 'camera_make', 'camera_model', 'original_name', 'src_path', 'subdirs', 'filename')
|
2021-08-31 16:18:41 +02:00
|
|
|
|
|
|
|
def test_get_checksum(self):
|
2021-09-12 07:41:44 +02:00
|
|
|
assert not self.sqlite.get_checksum('invalid')
|
|
|
|
assert self.sqlite.get_checksum('file_path') == 'checksum'
|
2021-08-31 16:18:41 +02:00
|
|
|
|
2021-09-12 07:41:44 +02:00
|
|
|
def test_get_metadata_data(self):
|
|
|
|
assert not self.sqlite.get_metadata_data('invalid', 'DateOriginal')
|
|
|
|
assert self.sqlite.get_metadata_data('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())
|
2021-09-12 07:41:44 +02:00
|
|
|
assert result == (24.2, 7.3, 'latitude_ref', 'longitude_ref', 'city', 'state', 'country', 'default')
|
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):
|
|
|
|
value = self.sqlite.get_location_nearby(24.2005, 7.3004, 'Default')
|
|
|
|
assert value == 'default'
|
|
|
|
|
|
|
|
@pytest.mark.skip('TODO')
|
|
|
|
def test_delete_row(self, table, id):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pytest.mark.skip('TODO')
|
|
|
|
def test_delete_all_rows(self, table):
|
|
|
|
pass
|
|
|
|
|