931
931
entry.syncUpdate()
933
933
def test_cleanUpObsoleteEntries_unaffected_statuses(self):
934
# _cleanUpObsoleteEntries leaves entries in some states (i.e.
935
# Approved and Blocked) alone no matter how old they are.
936
one_year_ago = datetime.now(UTC) - timedelta(days=366)
934
# _cleanUpObsoleteEntries leaves entries in states without
935
# expiry age (currently only Blocked) alone no matter how old
937
unaffected_statuses = (
938
set(RosettaImportStatus.items) -
939
set(translation_import_queue_entry_age.keys()))
941
0, len(unaffected_statuses),
942
"This test is no longer needed; "
943
"there are no statuses without expiry ages.")
945
years_ago = datetime.now(UTC) - timedelta(days=2000)
937
946
entry = self._makeProductEntry()
939
self.factory.makePOTemplate(productseries=entry.productseries))
947
entry.potemplate = self.factory.makePOTemplate(
948
productseries=entry.productseries)
940
949
entry_id = entry.id
942
self._setStatus(entry, RosettaImportStatus.APPROVED, one_year_ago)
943
# No write or delete action expected, so no reason to switch the
944
# database user. If it writes or deletes, the test has failed anyway.
945
self.queue._cleanUpObsoleteEntries(self.store)
946
self.assertTrue(self._exists(entry_id))
948
self._setStatus(entry, RosettaImportStatus.BLOCKED, one_year_ago)
949
# No write or delete action expected, so no reason to switch the
950
# database user. If it writes or deletes, the test has failed anyway.
951
self.queue._cleanUpObsoleteEntries(self.store)
952
self.assertTrue(self._exists(entry_id))
950
for status in unaffected_statuses:
951
self._setStatus(entry, status, years_ago)
952
self.queue._cleanUpObsoleteEntries(self.store)
953
self.assertTrue(self._exists(entry_id))
954
955
def test_cleanUpObsoleteEntries_affected_statuses(self):
955
956
# _cleanUpObsoleteEntries deletes entries in terminal states
956
957
# (Imported, Failed, Deleted) after a few days. The exact
957
958
# period depends on the state. Entries in certain other states
958
959
# get cleaned up after longer periods.
959
affected_statuses = [
960
RosettaImportStatus.DELETED,
961
RosettaImportStatus.FAILED,
962
RosettaImportStatus.IMPORTED,
963
RosettaImportStatus.NEEDS_INFORMATION,
964
RosettaImportStatus.NEEDS_REVIEW,
966
for status in affected_statuses:
960
for status in translation_import_queue_entry_age.keys():
967
961
entry = self._makeProductEntry()
968
962
entry.potemplate = self.factory.makePOTemplate()
969
963
maximum_age = translation_import_queue_entry_age[status]