On Mon, Nov 10, 2014 at 10:15 AM, Biola Oyeniyi <gbo...@gmail.com> wrote:
> 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()

This creates data from the database, and returns an object with the
values just stored in the database.

>         Session.objects.filter(id=result.id).update(price=Decimal('700'))

This updates data in the database

>         self.assertEqual(result.price,Decimal('700'))

This asserts that the data you fetched from the database before you
updated the database has the value which you just updated it to in the
database.

I hope you can see that is unlikely to ever work. If you want to check
that the data in the database has been updated, you will need to
re-fetch the data from the database after updating it.

Bear in mind that this test is effectively then just testing that
django can store stuff in a database and fetch it out afterwards.
Django itself has lots of tests that verify this happens.

Cheers

Tom

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1KHdfePeJxqtCSCdrYdQ9e9HcCPt8gc8OLLet%3DNvvkNzQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to