def handle(self, *args, **options):
        now = timezone.now()
        try:
            last_import_run = ImportRun.objects.latest('timestamp')
            since = last_import_run.timestamp
        except ImportRun.DoesNotExist:
            since = now - timedelta(days=3)
        ImportRun.objects.create(timestamp=now)

        changed_sprinters = set()
        trac_importer = TracImporter()
        changed_sprinters.update(trac_importer.sync(since))

        github_importer = GithubImporter()
        changed_sprinters.update(github_importer.sync(since))
        process_achievements(changed_sprinters)
class ImporterTest(TestCase):
    def setUp(self):
        self.since = make_aware(datetime(2013, 1, 1, 13, 46), utc)
        self.proxy = FakeClient()
        self.importer = Importer(self.proxy)

    def test_pull_requests_get_created(self):
        self.importer.sync(self.since)
        expect(PullRequest.objects.count()) == 2

    def test_sync_is_idempotent(self):
        self.importer.sync(self.since)
        self.importer.sync(self.since)
        expect(PullRequest.objects.count()) == 2

    def test_adds_sprinter_pulls(self):
        SprinterFactory.create(github_login='******')
        self.importer.sync(self.since)
        expect(SprinterPull.objects.count()) == 1
 def setUp(self):
     self.since = make_aware(datetime(2013, 1, 1, 13, 46), utc)
     self.proxy = FakeClient()
     self.importer = Importer(self.proxy)