def test_purge_legacy(self):
        now = time.time()
        legacy = yield Legacy(ip_address="192.168.211.1",
                              retrieved_time=now).save()
        legacy = yield Legacy(ip_address="192.168.211.2",
                              retrieved_time=now).save()

        legacy = yield Legacy.all()
        self.assertEqual(len(legacy), 2, "Should have two legacy reports")

        yield controllers.purge_reported_addresses()

        legacy = yield Legacy.all()
        self.assertEqual(
            len(legacy), 2,
            "Should still have two legacy reports after purging client reports"
        )

        yield controllers.purge_legacy_addresses()

        legacy = yield Legacy.all()
        self.assertEqual(len(legacy), 0,
                         "Should no legacy reports after purging legacy")

        rows = yield database.run_query(
            'SELECT `value` FROM info WHERE `key`="last_legacy_sync"')
        self.assertEqual(rows[0][0], '0',
                         "Purging legacy should reset last legacy sync time")
    def test_purge_reports(self):
        now = time.time()
        c = yield Cracker(ip_address="192.168.1.1", first_time=now, latest_time=now, total_reports=0, current_reports=0).save()
        c2 = yield Cracker(ip_address="192.168.1.2", first_time=now, latest_time=now, total_reports=0, current_reports=0).save()
        c3 = yield Cracker(ip_address="192.168.1.3", first_time=now, latest_time=now, total_reports=0, current_reports=0).save()

        yield controllers.add_report_to_cracker(c, "127.0.0.1", when=now)
        yield controllers.add_report_to_cracker(c, "127.0.0.2", when=now)
        yield controllers.add_report_to_cracker(c, "127.0.0.9", when=now)
        yield controllers.add_report_to_cracker(c2, "127.0.0.3", when=now)

        yield controllers.purge_legacy_addresses()

        crackers = yield Cracker.all()
        self.assertEqual(len(crackers), 3, "Should still have three crackers after purging legacy")

        reports = yield Report.all()
        self.assertEqual(len(reports), 4, "Should still have four reports after purging legacy")
        
        yield controllers.purge_reported_addresses()

        crackers = yield Cracker.all()
        self.assertEqual(len(crackers), 0, "Should have no crackers after purging reports")

        reports = yield Report.all()
        self.assertEqual(len(reports), 0, "Should have no reports after purging reports")
    def test_purge_reports(self):
        now = time.time()
        c = yield Cracker(ip_address="192.168.1.1",
                          first_time=now,
                          latest_time=now,
                          total_reports=0,
                          current_reports=0).save()
        c2 = yield Cracker(ip_address="192.168.1.2",
                           first_time=now,
                           latest_time=now,
                           total_reports=0,
                           current_reports=0).save()
        c3 = yield Cracker(ip_address="192.168.1.3",
                           first_time=now,
                           latest_time=now,
                           total_reports=0,
                           current_reports=0).save()

        yield controllers.add_report_to_cracker(c, "127.0.0.1", when=now)
        yield controllers.add_report_to_cracker(c, "127.0.0.2", when=now)
        yield controllers.add_report_to_cracker(c, "127.0.0.9", when=now)
        yield controllers.add_report_to_cracker(c2, "127.0.0.3", when=now)

        yield controllers.purge_legacy_addresses()

        crackers = yield Cracker.all()
        self.assertEqual(
            len(crackers), 3,
            "Should still have three crackers after purging legacy")

        reports = yield Report.all()
        self.assertEqual(
            len(reports), 4,
            "Should still have four reports after purging legacy")

        yield controllers.purge_reported_addresses()

        crackers = yield Cracker.all()
        self.assertEqual(len(crackers), 0,
                         "Should have no crackers after purging reports")

        reports = yield Report.all()
        self.assertEqual(len(reports), 0,
                         "Should have no reports after purging reports")
    def test_purge_legacy(self):
        now = time.time()
        legacy = yield Legacy(ip_address="192.168.211.1", retrieved_time=now).save()
        legacy = yield Legacy(ip_address="192.168.211.2", retrieved_time=now).save()

        legacy = yield Legacy.all()
        self.assertEqual(len(legacy), 2, "Should have two legacy reports")

        yield controllers.purge_reported_addresses()

        legacy = yield Legacy.all()
        self.assertEqual(len(legacy), 2, "Should still have two legacy reports after purging client reports")

        yield controllers.purge_legacy_addresses()

        legacy = yield Legacy.all()
        self.assertEqual(len(legacy), 0, "Should no legacy reports after purging legacy")

        rows = yield database.run_query('SELECT `value` FROM info WHERE `key`="last_legacy_sync"')
        self.assertEqual(rows[0][0], '0', "Purging legacy should reset last legacy sync time")