def test_safe_get(self):
     Model = self.mox.CreateMockAnything()
     Model.objects = self.mox.CreateMockAnything()
     filters = {'field1': 'value1', 'field2': 'value2'}
     results = self.mox.CreateMockAnything()
     Model.objects.filter(**filters).AndReturn(results)
     results.count().AndReturn(1)
     object = self.mox.CreateMockAnything()
     results[0].AndReturn(object)
     self.mox.ReplayAll()
     returned = db._safe_get(Model, **filters)
     self.assertEqual(returned, object)
     self.mox.VerifyAll()
Example #2
0
 def test_safe_get(self):
     Model = self.mox.CreateMockAnything()
     Model.objects = self.mox.CreateMockAnything()
     filters = {'field1': 'value1', 'field2': 'value2'}
     results = self.mox.CreateMockAnything()
     Model.objects.filter(**filters).AndReturn(results)
     results.count().AndReturn(1)
     object = self.mox.CreateMockAnything()
     results[0].AndReturn(object)
     self.mox.ReplayAll()
     returned = db._safe_get(Model, **filters)
     self.assertEqual(returned, object)
     self.mox.VerifyAll()
 def test_safe_get_no_results(self):
     Model = self.mox.CreateMockAnything()
     Model.__name__ = 'Model'
     Model.objects = self.mox.CreateMockAnything()
     filters = {'field1': 'value1', 'field2': 'value2'}
     results = self.mox.CreateMockAnything()
     Model.objects.filter(**filters).AndReturn(results)
     results.count().AndReturn(0)
     log = self.mox.CreateMockAnything()
     self.setup_mock_log()
     self.log.warn('No records found for Model get.')
     self.mox.ReplayAll()
     returned = db._safe_get(Model, **filters)
     self.assertEqual(returned, None)
     self.mox.VerifyAll()
Example #4
0
 def test_safe_get_no_results(self):
     Model = self.mox.CreateMockAnything()
     Model.__name__ = 'Model'
     Model.objects = self.mox.CreateMockAnything()
     filters = {'field1': 'value1', 'field2': 'value2'}
     results = self.mox.CreateMockAnything()
     Model.objects.filter(**filters).AndReturn(results)
     results.count().AndReturn(0)
     log = self.mox.CreateMockAnything()
     self.setup_mock_log()
     self.log.warn('No records found for Model get.')
     self.mox.ReplayAll()
     returned = db._safe_get(Model, **filters)
     self.assertEqual(returned, None)
     self.mox.VerifyAll()