From f8ae11c57f2207f58238339395017324a51474a5 Mon Sep 17 00:00:00 2001 From: Cedric Leporcq Date: Sat, 23 Apr 2022 18:40:34 +0200 Subject: [PATCH] Fix database --- ordigi/database.py | 4 +++- tests/test_database.py | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ordigi/database.py b/ordigi/database.py index e5a0a71..91b4621 100644 --- a/ordigi/database.py +++ b/ordigi/database.py @@ -310,7 +310,9 @@ class Sqlite: value = None self.cur.execute('SELECT * FROM location') for row in self.cur: - distance = distance_between_two_points(latitude, longitude, row[0], row[1]) + distance = distance_between_two_points( + latitude, longitude, row['Latitude'], row['Longitude'] + ) # Use if closer then threshold_km reuse lookup if distance < shorter_distance and distance <= threshold_m: shorter_distance = distance diff --git a/tests/test_database.py b/tests/test_database.py index 38c36dd..5ba37e8 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -28,7 +28,7 @@ class TestSqlite: 'CameraMake': 'camera_make', 'CameraModel': 'camera_model', 'OriginalName':'original_name', - 'SrcPath': 'src_path', + 'SrcDir': 'src_dir', 'Subdirs': 'subdirs', 'Filename': 'filename' } @@ -44,8 +44,8 @@ class TestSqlite: 'Location': 'location' } - cls.sqlite.add_row('metadata', row_data) - cls.sqlite.add_row('location', location_data) + 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) # cls.sqlite.add_location(24.2, 7.3, 'city', 'state', 'country', 'location') @@ -66,6 +66,7 @@ class TestSqlite: result = tuple(self.sqlite.cur.execute("""select * from metadata where rowid=1""").fetchone()) assert result == ( + 1, 'file_path', 'checksum', 'album', @@ -79,7 +80,7 @@ class TestSqlite: 'camera_make', 'camera_model', 'original_name', - 'src_path', + 'src_dir', 'subdirs', 'filename' ) @@ -96,7 +97,9 @@ class TestSqlite: result = tuple(self.sqlite.cur.execute("""select * from location where rowid=1""").fetchone()) assert result == ( - 24.2, 7.3, + 1, + 24.2, + 7.3, 'latitude_ref', 'longitude_ref', 'city',