File: test_nulls.py

package info (click to toggle)
django-recurrence 1.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: python: 2,530; javascript: 2,502; makefile: 159; sh: 6
file content (27 lines) | stat: -rw-r--r-- 866 bytes parent folder | download | duplicates (5)
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
from django.db import IntegrityError
from recurrence import Recurrence
from tests.models import EventWithNulls, EventWithNoNulls
import pytest


@pytest.mark.django_db
def test_recurs_can_be_explicitly_none_if_none_is_allowed():
    # Check we can save None correctly
    event = EventWithNulls.objects.create(recurs=None)
    assert event.recurs is None

    # Check we can deserialize None correctly
    reloaded = EventWithNulls.objects.get(pk=event.pk)
    assert reloaded.recurs is None


@pytest.mark.django_db
def test_recurs_cannot_be_explicitly_none_if_none_is_disallowed():
    with pytest.raises(IntegrityError):
        EventWithNoNulls.objects.create(recurs=None)


@pytest.mark.django_db
def test_recurs_can_be_empty_even_if_none_is_disallowed():
    event = EventWithNoNulls.objects.create(recurs=Recurrence())
    assert event.recurs == Recurrence()