Ticket #15566: ticket_15566_test.patch

File ticket_15566_test.patch, 2.4 KB (added by Béres Botond, 14 years ago)
  • tests/regressiontests/queries/models.py

    diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
    index d441433..9c5cf65 100644
    a b class ObjectC(models.Model):  
    317317
    318318    def __unicode__(self):
    319319       return self.name
     320
     321# For testing .update + auto_now behaviour for #15566
     322class LogEntry(models.Model):
     323    name = models.CharField(max_length=50)
     324    modify_ts = models.DateTimeField(auto_now=True)
     325    modify_date = models.DateField(auto_now=True)
     326 No newline at end of file
  • tests/regressiontests/queries/tests.py

    diff --git a/tests/regressiontests/queries/tests.py b/tests/regressiontests/queries/tests.py
    index 93e0845..52bc974 100644
    a b from models import (Annotation, Article, Author, Celebrity, Child, Cover, Detail  
    1515    DumbCategory, ExtraInfo, Fan, Item, LeafA, LoopX, LoopZ, ManagedModel,
    1616    Member, NamedCategory, Note, Number, Plaything, PointerA, Ranking, Related,
    1717    Report, ReservedName, Tag, TvChef, Valid, X, Food, Eaten, Node, ObjectA, ObjectB,
    18     ObjectC)
     18    ObjectC, LogEntry)
    1919
    2020
    2121class BaseQuerysetTest(TestCase):
    class Queries4Tests(BaseQuerysetTest):  
    978978        Report.objects.create(name='r1', creator=a1)
    979979        Report.objects.create(name='r2', creator=a3)
    980980        Report.objects.create(name='r3')
     981       
     982        entry = LogEntry.objects.create(name='First entry',
     983                                        modify_date=datetime.date(2000, 1, 1))
     984        self.entry_datetime = entry.modify_ts
     985        self.entry_date = entry.modify_date
    981986
    982987    def test_ticket7095(self):
    983988        # Updates that are filtered on the model being updated are somewhat
    class Queries4Tests(BaseQuerysetTest):  
    10321037            []
    10331038        )
    10341039
     1040    def test_update_with_auto_now(self):
     1041        # Ticket #15566. Make sure .update queries affect DateTimeField-s and
     1042        # DateField-s with auto_now = True
     1043        LogEntry.objects.update(name='First entry modified')
     1044        entry = LogEntry.objects.get()
     1045        self.assertEqual(entry.name, 'First entry modified')
     1046        self.assertNotEqual(entry.modify_ts, self.entry_datetime, 'DateTime field of LogEntry should have been updated')
     1047        self.assertNotEqual(entry.modify_date, self.entry_date, 'Date field of LogEntry should have been updated')
    10351048
    10361049class Queries5Tests(TestCase):
    10371050    def setUp(self):
Back to Top