title: Django TestCase not saving my models
body: <p>I'm currently writing some tests for a Django app. I've got the following standalone function in my app's signals.py file:</p>
  
  <pre><code>def updateLeaveCounts():
     # Setting some variables here
      todaysPeriods = Period.objects.filter(end__lte=today_end, end__gte=today_start).filter(request__leavetype="AN")
      for period in todaysPeriods:
          print period
          counter = LeaveCounter.objects.get(pk=period.request.submitter)
          # some Logic here
          period.batch_processed = True
          period.save()
  </code></pre>
  
  <p>and in my TestCase, I'm calling it as follows:</p>
  
  <pre><code>def test_johnsPostLeaveCounters(self):
      # Some setup here
      p = Period.objects.create(request=request,start=datetime(today.year,today.month,today.day,9),end=datetime(today.year,today.month,today.day,16,30),length='whole')
      updateLeaveCounts()
      self.assertEqual(p.batch_processed,True)
  </code></pre>
  
  <p><code>updateLeaveCounts()</code> is catching my newly created Period object in the for loop (I can see its details printed to the console by <code>print period</code>), but my assertEqual() test is failing - telling me that the batch_processed attribute is still False.</p>
  
  <p>It's as if the <code>period.save()</code> transaction isn't being called.</p>
  
  <p>I'm aware that in Django versions prior to 1.8, you'd have to use the TransactionTestCase class, but I'm running 1.8.3 for this project at the moment, so I don't believe that's the issue.</p>
  
  <p>Is there something I need to do to have the TestCases correctly reflect the <code>model.save()</code> action I'm performing in this function and hence have this function covered by tests?</p>