~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/translations/tests/test_autoapproval.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-10-13 09:33:11 UTC
  • mfrom: (14134.3.2 bug-872646)
  • Revision ID: launchpad@pqm.canonical.com-20111013093311-fiwq3h86bjc5hxog
[r=danilo][bug=872646] Purge Approved translations uploads after half
 a year.

Show diffs side-by-side

added added

removed removed

Lines of Context:
931
931
        entry.syncUpdate()
932
932
 
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
 
936
        # they are.
 
937
        unaffected_statuses = (
 
938
            set(RosettaImportStatus.items) -
 
939
                set(translation_import_queue_entry_age.keys()))
 
940
        self.assertNotEqual(
 
941
            0, len(unaffected_statuses),
 
942
            "This test is no longer needed; "
 
943
            "there are no statuses without expiry ages.")
 
944
 
 
945
        years_ago = datetime.now(UTC) - timedelta(days=2000)
937
946
        entry = self._makeProductEntry()
938
 
        entry.potemplate = (
939
 
            self.factory.makePOTemplate(productseries=entry.productseries))
 
947
        entry.potemplate = self.factory.makePOTemplate(
 
948
                productseries=entry.productseries)
940
949
        entry_id = entry.id
941
 
 
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))
947
 
 
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))
953
954
 
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,
965
 
            ]
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]