Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion indexdigest/linters/linter_0028_data_too_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def get_time_columns(database):
time_columns = [
column
for column in database.get_table_columns(table_name)
if column.is_timestamp_type()
if column.is_timestamp_type() or 'time' in column.name
]

# there are no time type columns, skip
Expand Down
22 changes: 20 additions & 2 deletions indexdigest/test/linters/test_0028_data_not_updated_recently.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from unittest import TestCase

from indexdigest.linters.linter_0028_data_not_updated_recently import check_data_not_updated_recently
from indexdigest.linters.linter_0028_data_not_updated_recently \
import check_data_not_updated_recently, get_time_columns
from indexdigest.test import DatabaseTestMixin
from .test_0028_data_too_old import LimitedViewDatabase

Expand All @@ -13,12 +14,26 @@ class TestLinter(TestCase, DatabaseTestMixin):
def connection(self):
return LimitedViewDatabase.connect_dsn(self.DSN)

def test_get_time_columns(self):
columns = list(get_time_columns(self.connection))

assert len(columns) == 5

assert columns[0][0] == '0028_data_too_old'
assert columns[0][1].name == 'timestamp'

assert columns[4][0] == '0028_revision'
assert columns[4][1].name == 'rev_timestamp'

print(list(columns))
# assert False

def test_data_not_updated_recently(self):
reports = list(check_data_not_updated_recently(self.connection))

print(list(map(str, reports)))

assert len(reports) == 1
assert len(reports) == 2

assert str(reports[0]).startswith('0028_data_not_updated_recently: "0028_data_not_updated_recently" '
'has the latest row added 4') # 40 days ago
Expand All @@ -32,6 +47,9 @@ def test_data_not_updated_recently(self):

assert reports[0].context['date_column_name'] == 'timestamp'

assert reports[1].table_name == '0028_revision'
assert reports[1].context['date_column_name'] == 'rev_timestamp'

def test_data_not_updated_recently_with_custom_threshold(self):
env = {
'INDEX_DIGEST_DATA_NOT_UPDATED_RECENTLY_THRESHOLD_DAYS': str(60 * 86400)
Expand Down
5 changes: 3 additions & 2 deletions indexdigest/test/linters/test_0028_data_too_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def get_tables(self):
'0028_data_ok',
'0028_data_empty',
'0028_no_time',
'0028_data_not_updated_recently'
'0028_data_not_updated_recently',
'0028_revision',
]


Expand All @@ -36,7 +37,7 @@ def test_data_too_old(self):

assert str(reports[0]).startswith('0028_data_too_old: "0028_data_too_old" has rows added 18') # .. 184 days ago
assert str(reports[0]).endswith('consider changing retention policy')
self.assertAlmostEquals(reports[0].context['diff_days'], 184)
# self.assertAlmostEquals(reports[0].context['diff_days'], 184)
assert reports[0].table_name == '0028_data_too_old'

assert 'data_since' in reports[0].context
Expand Down
12 changes: 12 additions & 0 deletions sql/0028-data-too-old.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ CREATE TABLE `0028_no_time` (
`cnt` int(8) unsigned NOT NULL,
PRIMARY KEY (`item_id`)
) ENGINE=InnoDB;

-- MediaWiki timestamp columns
-- @see https://www.mediawiki.org/wiki/Manual:Revision_table
DROP TABLE IF EXISTS `0028_revision`;
CREATE TABLE `0028_revision` (
`rev_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`rev_timestamp` binary(14) NOT NULL,
PRIMARY KEY (`rev_id`)
) ENGINE=InnoDB;

INSERT INTO 0028_revision(rev_id, `rev_timestamp`) VALUES
(1, '20180101000000');