On Jun 17, 1:46 am, "Gene Campbell" <[EMAIL PROTECTED]> wrote:
> Hello Djangonauts
>
> I'm a noob on both Django and Python, so this question might be easy
> for the experts out there.  I am trying to do test first development
> during the development of my model code.  (I have lots of experience
> with test first coding in the Java world, no practical experience in
> the Py world.)
>
> I want to do something like this
>
> class ModelTest(TestCase):
>
>     def test_crud_modelone(self):
>         mo = ModelOne( name="A name" )
>         mo.save()
>
>         saved_mo = mo.objects.get(pk=mo.id)
>
>         assertEqual( vars(mo), vars(saved_mo),"Something not getting saved")
>
> That assertEqual line fails.  I wrote this

You didn't say what exactly happens. If it's failing with a NameError,
notice that you forgot to specify self.assertEqual().
There's no implicit "this" like in Java.

And as others have mentioned, vars() is rarely used in practice.
And if there's a problem, it'll be hard to see what's wrong.
It's more tedious but ultimately more helpful to specify everything:

    self.assertEqual(mo.foo, saved_mo.foo)
    self.assertEqual(mo.bar, saved_mo.bar)

... and so forth.

Also, as a fellow django noob I'm not sure about this, but I seem to
recall that mo and saved_mo should be exactly the same object?
If that's true (hopefully somebody will correct me if not), it's kind
of a silly test; you might instead just do

   self.failUnless(mo is saved_mo)


-- PW

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to