view PersonasBackend/personas/tests.py @ 98:305fb3a1e0ca

Modified the personas app to take a single url to a persona, rather than two separate urls/two separate images.
author Atul Varma <varmaa@toolness.com>
date Fri, 28 Mar 2008 12:54:06 -0700
parents 663f0410ff39
children
line wrap: on
line source

import unittest
import datetime

from django.test.client import Client
from django.core.urlresolvers import reverse
from PersonasBackend.personas import models

class JsonTests( unittest.TestCase ):
    def setUp( self ):
        for persona in models.Persona.objects.all():
            persona.delete()
        self.cat = models.Category( name = "Random Things" )
        self.cat.save()
        self.persona = models.Persona(
            name = "Test Persona",
            category = self.cat,
            url = "http://www.blarg.com/mypersona",
            status = "published"
            )
        self.persona.save()

    def tearDown( self ):
        self.persona.delete()
        self.cat.delete()

    def testCategoriesWorks( self ):
        # Just a smoke test to make sure nothing crashes...
        client = Client()
        response = client.get( reverse("personas-categories-json") )
        assert response.status_code == 200

    def testAllPersonasWorks( self ):
        # Just a smoke test to make sure nothing crashes...
        client = Client()
        response = client.get( reverse("personas-all-json") )
        assert response.status_code == 200

    def testPublishDateIsUpdatedProperly( self ):
      p = models.Persona(
          name='Yet Another Test Persona',
          url='http://www.test.com/testpersona',
          category=models.Category.objects.get(name='Other'))

      p.save()
      self.assertEquals( p.status, "unpublished" )
      self.assertEquals( p.date_published, None )

      p.status = "published"
      now = datetime.datetime.now()
      p.save()
      assert p.date_published >= now

if __name__ == "__main__":
    unittest.main()