File: test_json_field.py

package info (click to toggle)
django-dirtyfields 1.3.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 276 kB
  • sloc: python: 812; makefile: 168
file content (29 lines) | stat: -rw-r--r-- 689 bytes parent folder | download | duplicates (4)
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
import unittest
import pytest
from django.db import models
from dirtyfields import DirtyFieldsMixin

JSON_FIELD_AVAILABLE = False
try:
    from jsonfield import JSONField
    JSON_FIELD_AVAILABLE = True
except ImportError:
    pass


if JSON_FIELD_AVAILABLE:
    class JSONFieldModel(DirtyFieldsMixin, models.Model):
        json_field = JSONField()


@unittest.skipIf(not JSON_FIELD_AVAILABLE, 'django jsonfield library required')
@pytest.mark.django_db
def test_json_field():
    tm = JSONFieldModel.objects.create(json_field={'data': [1, 2, 3]})

    data = tm.json_field['data']
    data.append(4)

    assert tm.get_dirty_fields() == {
        'json_field': {'data': [1, 2, 3]}
    }