chrono/tests/manager/test_shared_custody_agenda.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

156 lines
6.3 KiB
Python
Raw Normal View History

import datetime
import pytest
from chrono.agendas.models import Person, SharedCustodyAgenda, SharedCustodyPeriod, SharedCustodyRule
from tests.utils import login
pytestmark = pytest.mark.django_db
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday
def test_shared_custody_agenda_settings_rules(app, admin_user):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
app = login(app)
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
resp = resp.click('Settings')
assert 'Custody agenda of John Doe and Jane Doe' in resp.text
assert 'Custody rules are not complete.' in resp.text
assert 'This agenda doesn\'t have any custody rules yet.' in resp.text
resp = resp.click('Add custody rule')
resp.form['guardian'] = father.pk
resp.form['days'] = list(range(7))
resp.form['weeks'] = 'even'
resp = resp.form.submit().follow()
assert 'Custody rules are not complete.' in resp.text
assert 'John Doe, daily, on even weeks' in resp.text
resp = resp.click('Add custody rule')
resp.form['guardian'] = mother.pk
resp.form['days'] = list(range(7))
resp.form['weeks'] = 'odd'
resp = resp.form.submit().follow()
assert 'Custody rules are not complete.' not in resp.text
assert 'John Doe, daily, on even weeks' in resp.text
assert 'Jane Doe, daily, on odd weeks' in resp.text
resp = resp.click('John Doe, daily, on even weeks')
resp.form['days'] = list(range(6))
resp = resp.form.submit().follow()
assert 'Custody rules are not complete.' in resp.text
resp = resp.click('John Doe, from Monday to Saturday, on even weeks')
resp.form['days'] = [0]
resp.form['weeks'] = 'odd'
resp = resp.form.submit()
assert 'Rule overlaps existing rules.' in resp.text
resp.form['weeks'] = 'even'
resp = resp.form.submit().follow()
resp = resp.click('remove', index=1)
resp = resp.form.submit().follow()
assert SharedCustodyRule.objects.count() == 1
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday
def test_shared_custody_agenda_settings_periods(app, admin_user):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
app = login(app)
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk)
assert 'This agenda doesn\'t have any custody period.' in resp.text
resp = resp.click('Add custody period')
resp.form['guardian'] = father.pk
resp.form['date_start'] = '2022-03-01'
resp.form['date_end'] = '2022-03-03'
resp = resp.form.submit().follow()
assert 'This agenda doesn\'t have any custody period.' not in resp.text
assert 'John Doe, 03/01/2022 → 03/03/2022' in resp.text
resp = resp.click('John Doe, 03/01/2022 → 03/03/2022')
resp.form['guardian'] = mother.pk
resp = resp.form.submit().follow()
assert 'Jane Doe, 03/01/2022 → 03/03/2022' in resp.text
resp = resp.click('Add custody period')
resp.form['guardian'] = mother.pk
resp.form['date_start'] = '2022-03-05'
resp.form['date_end'] = '2022-03-03'
resp = resp.form.submit()
assert 'End date must be greater than start date.' in resp.text
resp.form['date_start'] = '2022-03-02'
resp.form['date_end'] = '2022-03-06'
resp = resp.form.submit()
assert 'Period overlaps existing periods.' in resp.text
resp = app.get('/manage/shared-custody/%s/settings/' % agenda.pk)
resp = resp.click('remove', href='delete')
resp = resp.form.submit().follow()
assert not SharedCustodyPeriod.objects.exists()
@pytest.mark.freeze_time('2022-02-22 14:00') # Tuesday
def test_shared_custody_agenda_month_view(app, admin_user):
father = Person.objects.create(user_external_id='father_id', name='John Doe')
mother = Person.objects.create(user_external_id='mother_id', name='Jane Doe')
agenda = SharedCustodyAgenda.objects.create(first_guardian=father, second_guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='even')
app = login(app)
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
assert 'Custody agenda of John Doe and Jane Doe' in resp.text
assert 'February 2022' in resp.text
2022-03-15 13:15:45 +01:00
assert 'Configuration is not completed yet.' in resp.text
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='odd')
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
2022-03-15 13:15:45 +01:00
assert 'Configuration is not completed yet.' not in resp.text
assert all('Week %s' % i in resp.text for i in range(5, 10))
assert resp.pyquery('tbody tr th.today span').text() == 'Tuesday 22'
days = [x.text for x in resp.pyquery('tbody tr th span')]
assert len(days) == 7 * 5
assert days[:3] == ['Monday 31', 'Tuesday 1', 'Wednesday 2']
assert days[-3:] == ['Friday 4', 'Saturday 5', 'Sunday 6']
tds = [x.text for x in resp.pyquery('tbody tr td')]
for week_number, i in zip(range(5, 10), range(0, 29, 7)):
guardian = 'Jane Doe' if week_number % 2 else 'John Doe'
assert tds[i : i + 7] == [guardian] * 7
SharedCustodyPeriod.objects.create(
agenda=agenda,
guardian=father,
date_start=datetime.date(2022, 2, 1),
date_end=datetime.date(2022, 2, 3),
)
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
tds = [x.text for x in resp.pyquery('tbody tr td')]
assert tds[:7] == ['Jane Doe', 'John Doe', 'John Doe', 'Jane Doe', 'Jane Doe', 'Jane Doe', 'Jane Doe']
old_resp = resp
resp = resp.click('')
assert 'March 2022' in resp.text
assert 'today' not in resp.text
assert all('Week %s' % i in resp.text for i in range(9, 14))
days = [x.text for x in resp.pyquery('tbody tr th span')]
assert len(days) == 7 * 5
assert days[:3] == ['Monday 28', 'Tuesday 1', 'Wednesday 2']
assert days[-3:] == ['Friday 1', 'Saturday 2', 'Sunday 3']
resp = resp.click('')
assert resp.text == old_resp.text
app.get('/manage/shared-custody/%s/42/42/' % agenda.pk, status=404)