File: test_modificationdatetime_fields.py

package info (click to toggle)
python-django-extensions 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,820 kB
  • sloc: python: 18,601; javascript: 7,354; makefile: 108; xml: 17
file content (35 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
from datetime import datetime

from django.test import TestCase

from .testapp.models import (
    ModelModificationDateTimeField,
    CustomModelModificationDateTimeField,
    DisabledUpdateModelModificationDateTimeField,
)


class ModificationDatetimeFieldTest(TestCase):
    def test_update_model_with_modification_field(self):
        m = ModelModificationDateTimeField.objects.create()
        current_updated_time = m.modified
        m.field_to_update = False
        m.save()
        self.assertNotEqual(m.modified, current_updated_time)

    def test_custom_modification_field_name(self):
        m = CustomModelModificationDateTimeField.objects.create()
        current_updated_time = m.custom_modified
        m.field_to_update = False
        m.save()
        self.assertNotEqual(m.custom_modified, current_updated_time)

    def test_disabled_update_modification_field(self):
        m = DisabledUpdateModelModificationDateTimeField.objects.create(
            modified=datetime.now()
        )
        current_updated_time = m.modified
        m.field_to_update = False
        m.save()
        self.assertEqual(m.modified, current_updated_time)