def test_deletes_old_txlogs_within_quantity_limit(self):
        """Test that txnlogs old enough are deleted and are within the quantity
        limit given."""

        owner = self.make_user_without_txlog()
        right_now = now()
        timestamp_limit = right_now - timedelta(days=7)
        # Old enough
        old_datetime = timestamp_limit
        quantity_limit = 2

        txlogs = [
            self.factory.make_transaction_log(owner=owner),
            self.factory.make_transaction_log(
                owner=owner, timestamp=old_datetime),
            self.factory.make_transaction_log(owner=owner),
            self.factory.make_transaction_log(
                owner=owner, timestamp=old_datetime),
            self.factory.make_transaction_log(
                owner=owner, timestamp=old_datetime),
        ]
        expected = [txlogs[0], txlogs[2], txlogs[4], ]

        removed = utils.delete_old_txlogs(timestamp_limit=timestamp_limit,
                                          quantity_limit=quantity_limit)

        txlist = utils.get_txn_recs(num_recs=len(txlogs), last_id=0)
        self.assertEqual(len(txlist), 3)
        self.assertEqual(removed, quantity_limit)
        ids = [int(txdict['txn_id']) for txdict in txlist]
        self.assertItemsEqual(ids, [t.id for t in expected])
Example #2
0
    def test_deletes_old_txlogs_within_quantity_limit(self):
        """Test that txnlogs old enough are deleted and are within the quantity
        limit given."""

        owner = self.make_user_without_txlog()
        right_now = now()
        timestamp_limit = right_now - timedelta(days=7)
        # Old enough
        old_datetime = timestamp_limit
        quantity_limit = 2

        txlogs = [
            self.factory.make_transaction_log(owner=owner),
            self.factory.make_transaction_log(owner=owner,
                                              timestamp=old_datetime),
            self.factory.make_transaction_log(owner=owner),
            self.factory.make_transaction_log(owner=owner,
                                              timestamp=old_datetime),
            self.factory.make_transaction_log(owner=owner,
                                              timestamp=old_datetime),
        ]
        expected = [
            txlogs[0],
            txlogs[2],
            txlogs[4],
        ]

        removed = utils.delete_old_txlogs(timestamp_limit=timestamp_limit,
                                          quantity_limit=quantity_limit)

        txlist = utils.get_txn_recs(num_recs=len(txlogs), last_id=0)
        self.assertEqual(len(txlist), 3)
        self.assertEqual(removed, quantity_limit)
        ids = [int(txdict['txn_id']) for txdict in txlist]
        self.assertItemsEqual(ids, [t.id for t in expected])
    def test_maintains_newish_txlogs_when_purging(self):
        """Test that txnlogs not old enough are maintained, instead of being
        deleted."""
        owner = self.make_user_without_txlog()

        right_now = now()
        limit_datetime = right_now - timedelta(days=7)
        # Not so old
        old_datetime = limit_datetime + timedelta(seconds=1)

        expected = [
            self.factory.make_transaction_log(owner=owner),
            self.factory.make_transaction_log(
                owner=owner, timestamp=old_datetime),
            self.factory.make_transaction_log(owner=owner),
            self.factory.make_transaction_log(
                owner=owner, timestamp=old_datetime),
        ]

        removed = utils.delete_old_txlogs(timestamp_limit=limit_datetime)
        self.assertEqual(removed, 0)

        txlist = utils.get_txn_recs(num_recs=4, last_id=0)
        ids = [int(txdict['txn_id']) for txdict in txlist]
        self.assertItemsEqual(ids, [t.id for t in expected])
Example #4
0
    def test_maintains_newish_txlogs_when_purging(self):
        """Test that txnlogs not old enough are maintained, instead of being
        deleted."""
        owner = self.make_user_without_txlog()

        right_now = now()
        limit_datetime = right_now - timedelta(days=7)
        # Not so old
        old_datetime = limit_datetime + timedelta(seconds=1)

        expected = [
            self.factory.make_transaction_log(owner=owner),
            self.factory.make_transaction_log(owner=owner,
                                              timestamp=old_datetime),
            self.factory.make_transaction_log(owner=owner),
            self.factory.make_transaction_log(owner=owner,
                                              timestamp=old_datetime),
        ]

        removed = utils.delete_old_txlogs(timestamp_limit=limit_datetime)
        self.assertEqual(removed, 0)

        txlist = utils.get_txn_recs(num_recs=4, last_id=0)
        ids = [int(txdict['txn_id']) for txdict in txlist]
        self.assertItemsEqual(ids, [t.id for t in expected])