示例#1
0
def test_invalid_date_range(space_resource):
    period = Period(resource=space_resource,
                    start=date(2016, 8, 1),
                    end=date(2015, 11, 1),
                    name="test")
    with pytest.raises(ValidationError) as ei:
        period.clean()
    assert ei.value.code == "invalid_date_range"
示例#2
0
def test_invalid_belongings(space_resource, test_unit):
    period = Period(start=date(2015, 8, 1), end=date(2015, 11, 1), name="test")
    with pytest.raises(ValidationError) as ei:
        period.clean()
    assert ei.value.code == "no_belonging"

    period.resource = space_resource
    period.unit = test_unit
    with pytest.raises(ValidationError) as ei:
        period.clean()
    assert ei.value.code == "invalid_belonging"
示例#3
0
def test_invalid_belongings(space_resource, test_unit):
    period = Period(start=date(2015, 8, 1), end=date(2015, 11, 1), name="test")
    with pytest.raises(ValidationError) as ei:
        period.clean()
    assert ei.value.code == "no_belonging"

    period.resource = space_resource
    period.unit = test_unit
    with pytest.raises(ValidationError) as ei:
        period.clean()
    assert ei.value.code == "invalid_belonging"
示例#4
0
def test_period_overlaps(space_resource, offsets):
    big_period = Period.objects.create(
        resource=space_resource, start=date(2015, 1, 1), end=date(2015, 12, 1), name="test"
    )
    start_days, end_days = offsets
    overlap_period = Period(
        resource=space_resource,
        start=big_period.start + timedelta(days=start_days),
        end=big_period.end + timedelta(days=end_days),
        name="overlap"
    )
    with pytest.raises(ValidationError) as ei:
        overlap_period.clean()
    assert ei.value.code == "overlap"
示例#5
0
def test_exceptional_period_with_regular_period(space_resource):
    period = Period(resource=space_resource, start=date(2015, 8, 1), end=date(2015, 11, 1), name="test")
    period.clean()
    period.save()
    exception = Period(
            resource=space_resource,
            start=date(2015, 10, 24),
            end=date(2015, 10, 24),
            name="united_nations_day",
            exception=True
        )
    exception.clean()
    exception.save()
    period.name += "too"
    period.clean()
    period.save()
示例#6
0
def test_invalid_date_range(space_resource):
    period = Period(resource=space_resource, start=date(2016, 8, 1), end=date(2015, 11, 1), name="test")
    with pytest.raises(ValidationError) as ei:
        period.clean()
    assert ei.value.code == "invalid_date_range"
示例#7
0
def test_none_start_end_time(space_resource):
    period = Period(resource=space_resource, start=None, end=None, name="test")
    with pytest.raises(ValidationError) as ei:
        period.clean()
    assert ei.value.code == "empty_start_end"
示例#8
0
def test_none_start_end_time(space_resource):
    period = Period(resource=space_resource, start=None, end=None, name="test")
    with pytest.raises(ValidationError) as ei:
        period.clean()
    assert ei.value.code == "empty_start_end"