@pytest.mark.django_db
@pytest.mark.parametrize('commit', (False, True))
def test_period_model_form(space_resource, commit):
    period = Period(resource=space_resource, start=date(2015, 8, 1), end=date(2015, 11, 1), name='plop')
    period.full_clean()
    period.save()
    for wd in range(7):
        period.days.create(weekday=wd, opens=time(9, (wd * 2)), closes=time((12 + wd)))
    pmf = PeriodModelForm(instance=period)
    data = get_form_data(pmf, prepared=True)
    for key in list(data.keys()):
        if key.startswith(prefix_weekday(2, '')):
            data[key] = ''
        elif key.endswith('opens'):
            data[key] = '06:00'
    pmf = PeriodModelForm(instance=period, data=data)
    assert pmf.is_valid()
    period = pmf.save(commit=commit)
    if (not commit):
        period.save()
        pmf.save_m2m()
    assert all(((day.opens.hour == 6) for day in period.days.all()))
    assert (not period.days.filter(weekday=2).exists())
@pytest.mark.django_db
@pytest.mark.parametrize('commit', (False, True))
def test_period_model_form(space_resource, commit):
    period = Period(resource=space_resource, start=date(2015, 8, 1), end=date(2015, 11, 1), name='plop')
    period.full_clean()
    period.save()
    for wd in range(7):
        period.days.create(weekday=wd, opens=time(9, (wd * 2)), closes=time((12 + wd)))
    pmf = PeriodModelForm(instance=period)
    data = get_form_data(pmf, prepared=True)
    for key in list(data.keys()):
        if key.startswith(prefix_weekday(2, )):
            data[key] = 
        elif key.endswith('opens'):
            data[key] = '06:00'
    pmf = PeriodModelForm(instance=period, data=data)
    assert pmf.is_valid()
    period = pmf.save(commit=commit)
    if (not commit):
        period.save()
        pmf.save_m2m()
    assert all(((day.opens.hour == 6) for day in period.days.all()))
    assert (not period.days.filter(weekday=2).exists())