On 11/04/2013 2:02pm, Lachlan Musicman wrote:
Hi

I'm new to testing. Not to Django. To my shame.

I'm trying to test some m2m signals connections, so I have a


Inside your test class before writing tests you can have ...

    def setUp(self):
        jack = MaleAccountFactory()
        jill = FemaleAccountFactory()

    def tearDown(self):
        ( here delete jack and jill )


If you have those two methods named exactly as above, setUp() will be called immediately before every test and tearDown() after every test.

def test_parent_account_creation(self):

       # next two lines should not be here
     jack = MaleAccountFactory()
     jill = FemaleAccountFactory()

     jack.parents.add(jill)
     self.assertIn(jill, jack.parents.all())
     #we should check that the reverse relationship has been created too
     self.assertIn(jack, jill.children.all())


This works. Great.

But now I want to create a test for parent *removal*. So I tried this
without success:

   def test_parent_account_removal(self):
       # this line should not be here but it wouldn't work
       # anyway because it should be self.test_parent_account_creation()
     test_parent_account_creation()

     # now we should remove jack as jill's parent
     jack.parents.remove(jill)
     self.assertNotIn(jill, jack.parents.all())
     # and test that jill is not jack's child
     self.assertNotIn(jack, jill.children.all())


Is there a way of calling previous tests to stay DRY? Or am I being a
fool and should just suck up the copy and paste?

Alternatively, am I being too obsessively modular and should I just
put the removal into the first test and change it's title to
test_parent_account(self)?

cheers
L.


--
The new creativity is pointing, not making. Likewise, in the future,
the best writers will be the best information managers.

http://www.theawl.com/2013/02/an-interview-with-avant-garde-poet-kenneth-goldsmith


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to