view gpp/potd/tests/tools_tests.py @ 515:ae89ba801e8b

For #194, convert the POTD management command to a celery task. Refactored to put the logic for the command into a function, and the command simply calls this function. The task can also just call this function. Added some basic tests for the new function.
author Brian Neal <bgneal@gmail.com>
date Wed, 14 Dec 2011 02:41:15 +0000
parents
children
line wrap: on
line source
"""
Tests for the pick_potd() function.

"""
from django.test import TestCase
from django.contrib.auth.models import User

from potd.models import Current, Photo, Sequence
from potd.tools import pick_potd


class PickPotdTest(TestCase):

    fixtures = ['potd_test.json']

    def test_pick(self):

        pick_potd()

        curr = Current.objects.get(pk=1)
        self.assertEqual(curr.potd.pk, 2)

    def test_shuffle(self):

        photo = Photo.objects.get(pk=3)
        curr = Current.objects.get(pk=1)
        curr.potd = photo
        curr.save()

        pick_potd()

        ids = Sequence.objects.get(pk=1).seq.split(',')
        curr = Current.objects.get(pk=1)
        self.assertEqual(len(ids), 3)
        self.assertEqual(curr.potd.pk, int(ids[0]))