Example #1
0
    @unittest.skipIf(not settings.USING_LOCAL_PHOTOS, "Skipping because test is broken when run with transactions")
    def test_create_welcome_album(self):
        with override_settings(WELCOME_ALBUM_ID=self.welcome_album.id):
            welcome_album.create_welcome_album(self.bob, datetime.datetime(2000, 01, 02, 0, 0, 0, tzinfo=utc))

    @unittest.skipIf(not settings.USING_LOCAL_PHOTOS, "Skipping because test is broken when run with transactions")
    def test_scheduled_jobs(self):
        with override_settings(WELCOME_ALBUM_ID=self.welcome_album.id):
            ScheduledWelcomeAlbumJob.objects.schedule_job(
                self.bob, datetime.datetime(2000, 01, 02, 0, 0, 0, tzinfo=utc)
            )

            welcome_album.process_scheduled_jobs(datetime.datetime(2000, 01, 02, 0, 0, 0, tzinfo=utc))
            self.assertEqual(len(Album.objects.get_user_albums(self.bob.id)), 0)

            welcome_album.process_scheduled_jobs(
                datetime.datetime(2000, 01, 02, 0, 0, 0, tzinfo=utc)
                + WELCOME_ALBUM_DELAY
                - datetime.timedelta(seconds=1)
            )
            self.assertEqual(len(Album.objects.get_user_albums(self.bob.id)), 0)

            welcome_album.process_scheduled_jobs(
                datetime.datetime(2000, 01, 02, 0, 0, 0, tzinfo=utc)
                + WELCOME_ALBUM_DELAY
                + datetime.timedelta(seconds=1)
            )
            self.assertEqual(len(Album.objects.get_user_albums(self.bob.id)), 1)
            self.assertEqual(Album.objects.get_user_albums(self.bob.id)[0].creator, self.amanda)
            self.assertEqual(Album.objects.get_user_albums(self.bob.id)[0].name, "Welcome")
 def handle(self, *args, **options):
     now = timezone.now()
     num_ran = welcome_album.process_scheduled_jobs(now)
     self.stdout.write('Successfully ran %d jobs' % num_ran)