File: test_models.py

package info (click to toggle)
python-django-debug-toolbar 1%3A6.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,052 kB
  • sloc: python: 7,555; javascript: 636; makefile: 67; sh: 16
file content (32 lines) | stat: -rw-r--r-- 1,147 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
import uuid

from django.test import TestCase

from debug_toolbar.models import HistoryEntry


class HistoryEntryTestCase(TestCase):
    def test_str_method(self):
        test_uuid = uuid.uuid4()
        entry = HistoryEntry(request_id=test_uuid)
        self.assertEqual(str(entry), str(test_uuid))

    def test_data_field_default(self):
        """Test that the data field defaults to an empty dict"""
        entry = HistoryEntry(request_id=uuid.uuid4())
        self.assertEqual(entry.data, {})

    def test_model_persistence(self):
        """Test saving and retrieving a model instance"""
        test_uuid = uuid.uuid4()
        entry = HistoryEntry(request_id=test_uuid, data={"test": True})
        entry.save()

        # Retrieve from database and verify
        saved_entry = HistoryEntry.objects.get(request_id=test_uuid)
        self.assertEqual(saved_entry.data, {"test": True})
        self.assertEqual(str(saved_entry), str(test_uuid))

    def test_default_ordering(self):
        """Test that the default ordering is by created_at in descending order"""
        self.assertEqual(HistoryEntry._meta.ordering, ["-created_at"])