'Test that select_on_save works correctly if the database
doesn\'t return correct information about matched rows from
UPDATE.'

def test_select_on_save_lying_update(self):

    orig_class = Article._base_manager.__class__
    class FakeQuerySet(QuerySet, ):
        called = False
        def _update(self, *args, **kwargs):
            FakeQuerySet.called = True
            super(FakeQuerySet, self)._update(*args, **kwargs)
            return 0
    class FakeManager(orig_class, ):
        def get_queryset(self):
            return FakeQuerySet(self.model)
    try:
        Article._base_manager.__class__ = FakeManager
        asos = ArticleSelectOnSave.objects.create(pub_date=datetime.now())
        with self.assertNumQueries(2):
            asos.save()
            self.assertTrue(FakeQuerySet.called)
        with self.assertRaises(DatabaseError):
            asos.save(force_update=True)
        with self.assertRaises(DatabaseError):
            asos.save(update_fields=[u'pub_date'])
    finally:
        Article._base_manager.__class__ = orig_class
