based on the docs, update()
Performs an SQL update query for the specified fields, and returns the number of rows matched.I have tried updating a model using it on django 1.7.1 with both sqlite and postgres but my test suite keeps failing and indicating no update.
Here is what i have tried.
def create_session(self, email='devito@gmailcom', date=datetime.datetime.now(),
duration=datetime.timedelta(hours=1)):
new_user = UserFactory(email=email)
sf = TutorSessionFactory(tutor_with_skill=self.ts, buyer=new_user,
date=date,duration=duration)
return sf
def test_can_update_ehen_udated(self):
result = self.create_session()
Session.objects.filter(id=result.id).update(price=Decimal('700')) self.assertEqual(result.price,Decimal('700'))
and below is the result from the test suite
Failure
Traceback (most recent call last):
File "C:\Python27\Lib\unittest\case.py", line 329, in run
testMethod()
File "F:\work-projects\python\django-projects\Tuteria\tuteria\tutor_sessions\tests\test_model.py", line 24, in test_can_update_ehen_udated
self.assertEqual(result.price,Decimal('700'))
File "C:\Python27\Lib\unittest\case.py", line 513, in assertEqual
assertion_func(first, second, msg=msg)
File "C:\Python27\Lib\unittest\case.py", line 506, in _baseAssertEqual
raise self.failureException(msg)
AssertionError: 500 != Decimal('700')
Pls can someone confirm is my suspicions are valid. thanks