diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..164031e --- /dev/null +++ b/.pylintrc @@ -0,0 +1,5 @@ +[MAIN] +disable= + C0114, # missing-module-docstring + C0115, # missing-class-docstring + C0116 # missing-function-docstring \ No newline at end of file diff --git a/defaults/python/db/migration.py b/defaults/python/db/migration.py index 4c7d33f..23ee4ca 100644 --- a/defaults/python/db/migration.py +++ b/defaults/python/db/migration.py @@ -66,6 +66,12 @@ def _current_migration_version(self): def _migration(self, migration: Migration): version = self._current_migration_version() + latest_version_in_migration = max(_migrations, key=lambda m: m.version).version + + if (latest_version_in_migration < version): + raise Exception( + "Database have been updated with latest version. Please update plugin") + if migration.version > version: with self.db.transactional() as con: for stm in migration.statements: diff --git a/defaults/python/helpers.py b/defaults/python/helpers.py index d1bc8fc..b44da76 100644 --- a/defaults/python/helpers.py +++ b/defaults/python/helpers.py @@ -8,8 +8,8 @@ def parse_date(date_str: str) -> date: return datetime.strptime(date_str, DATE_FORMAT).date() -def format_date(datetime: datetime) -> str: - return datetime.strftime(DATE_FORMAT) +def format_date(dt: datetime) -> str: + return dt.strftime(DATE_FORMAT) def end_of_day(day_to_end: datetime) -> datetime: diff --git a/defaults/python/tests/db/migration_test.py b/defaults/python/tests/db/migration_test.py index 8754a47..94928c6 100644 --- a/defaults/python/tests/db/migration_test.py +++ b/defaults/python/tests/db/migration_test.py @@ -40,3 +40,19 @@ def _get_table_meta(self, table: str): return connection.execute( f"PRAGMA table_xinfo({table})" ).fetchall() + + def test_should_fail_migration_if_application_older_then_database(self): + with sqlite3.connect(self.database_file) as connection: + connection.execute( + "CREATE TABLE IF NOT EXISTS migration (id INT PRIMARY KEY)" + ) + connection.execute( + "INSERT INTO MIGRATION (id) VALUES (999999)" + ) + try: + self.get_migration().migrate() + except Exception as e: + self.assertEqual( + str(e), + "Database have been updated with latest version. Please update plugin" + ) diff --git a/defaults/python/tests/time_tracking_test.py b/defaults/python/tests/time_tracking_test.py index 0b000c3..55549c5 100644 --- a/defaults/python/tests/time_tracking_test.py +++ b/defaults/python/tests/time_tracking_test.py @@ -104,7 +104,7 @@ def test_should_split_interval_in_two_day_in_case_night_session(self): } ]) - def test_should_sum_totalTime_per_day(self): + def test_should_sum_total_time_per_day(self): now = datetime(2022, 1, 1, 9, 0) self.time_tracking.add_time( now.timestamp(), (now + timedelta(hours=1)).timestamp(), "100", "Zelda BOTW") @@ -166,6 +166,7 @@ def test_return_only_data_in_requested_interval_without_gaps(self): result = self.playtime_statistics.daily_statistics_for_period( date_02.date(), date_08.date()) + # pylint: disable=C0103 self.maxDiff = None self.assertEqual([dataclasses.asdict(r) for r in result.data], [ {