|
|
|
@ -0,0 +1,138 @@
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from pyquery import PyQuery
|
|
|
|
|
|
|
|
|
|
from chrono.agendas.models import Agenda
|
|
|
|
|
from chrono.apps.journal.utils import audit
|
|
|
|
|
from chrono.utils.timezone import make_aware
|
|
|
|
|
from tests.utils import login
|
|
|
|
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_journal_permission(app, admin_user, manager_user):
|
|
|
|
|
app = login(app, username='manager', password='manager')
|
|
|
|
|
app.get('/manage/journal/', status=403)
|
|
|
|
|
app = login(app)
|
|
|
|
|
app.get('/manage/journal/', status=200)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_journal_feature_flag(app, admin_user, settings):
|
|
|
|
|
app = login(app)
|
|
|
|
|
assert settings.AUDIT_JOURNAL_ENABLED is False
|
|
|
|
|
resp = app.get('/manage/')
|
|
|
|
|
assert 'Audit journal' not in resp.text
|
|
|
|
|
settings.AUDIT_JOURNAL_ENABLED = True
|
|
|
|
|
resp = app.get('/manage/')
|
|
|
|
|
assert 'Audit journal' in resp.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_journal_browse(app, admin_user, manager_user, settings):
|
|
|
|
|
settings.AUDIT_JOURNAL_ENABLED = True
|
|
|
|
|
|
|
|
|
|
admin_user.first_name = 'Admin'
|
|
|
|
|
admin_user.save()
|
|
|
|
|
manager_user.first_name = 'Manager'
|
|
|
|
|
manager_user.save()
|
|
|
|
|
|
|
|
|
|
# some audit events
|
|
|
|
|
agendas = [
|
|
|
|
|
Agenda.objects.create(label='Foo', kind='events'),
|
|
|
|
|
Agenda.objects.create(label='Bar', kind='events'),
|
|
|
|
|
Agenda.objects.create(label='Baz', kind='events'),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
for i in range(20):
|
|
|
|
|
user = admin_user if i % 3 else manager_user
|
|
|
|
|
agenda = agendas[i % 3]
|
|
|
|
|
|
|
|
|
|
entry = audit('booking', 'cancellation of booking (%s)' % i, user=user, agenda=agenda)
|
|
|
|
|
entry.timestamp = make_aware(
|
|
|
|
|
datetime.datetime(
|
|
|
|
|
2024,
|
|
|
|
|
1,
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|
+ datetime.timedelta(days=i, hours=i, minutes=i)
|
|
|
|
|
)
|
|
|
|
|
entry.save()
|
|
|
|
|
|
|
|
|
|
entry = audit('check', 'marked absence (%s)' % i, user=user, agenda=agenda)
|
|
|
|
|
entry.timestamp = make_aware(
|
|
|
|
|
datetime.datetime(
|
|
|
|
|
2024,
|
|
|
|
|
1,
|
|
|
|
|
2,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
)
|
|
|
|
|
+ datetime.timedelta(days=i, hours=i, minutes=i)
|
|
|
|
|
)
|
|
|
|
|
entry.save()
|
|
|
|
|
|
|
|
|
|
app = login(app)
|
|
|
|
|
resp = app.get('/manage/journal/')
|
|
|
|
|
|
|
|
|
|
assert [[x.text for x in PyQuery(x).find('td')] for x in resp.pyquery('tbody tr')] == [
|
|
|
|
|
['Jan. 21, 2024, 7:19 p.m.', 'Admin', 'Bar', 'marked absence (19)'],
|
|
|
|
|
['Jan. 20, 2024, 7:19 p.m.', 'Admin', 'Bar', 'cancellation of booking (19)'],
|
|
|
|
|
['Jan. 20, 2024, 6:18 p.m.', 'Manager', 'Foo', 'marked absence (18)'],
|
|
|
|
|
['Jan. 19, 2024, 6:18 p.m.', 'Manager', 'Foo', 'cancellation of booking (18)'],
|
|
|
|
|
['Jan. 19, 2024, 5:17 p.m.', 'Admin', 'Baz', 'marked absence (17)'],
|
|
|
|
|
['Jan. 18, 2024, 5:17 p.m.', 'Admin', 'Baz', 'cancellation of booking (17)'],
|
|
|
|
|
['Jan. 18, 2024, 4:16 p.m.', 'Admin', 'Bar', 'marked absence (16)'],
|
|
|
|
|
['Jan. 17, 2024, 4:16 p.m.', 'Admin', 'Bar', 'cancellation of booking (16)'],
|
|
|
|
|
['Jan. 17, 2024, 3:15 p.m.', 'Manager', 'Foo', 'marked absence (15)'],
|
|
|
|
|
['Jan. 16, 2024, 3:15 p.m.', 'Manager', 'Foo', 'cancellation of booking (15)'],
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
resp = resp.click('2') # pagination
|
|
|
|
|
|
|
|
|
|
assert [[x.text for x in PyQuery(x).find('td')] for x in resp.pyquery('tbody tr')] == [
|
|
|
|
|
['Jan. 16, 2024, 2:14 p.m.', 'Admin', 'Baz', 'marked absence (14)'],
|
|
|
|
|
['Jan. 15, 2024, 2:14 p.m.', 'Admin', 'Baz', 'cancellation of booking (14)'],
|
|
|
|
|
['Jan. 15, 2024, 1:13 p.m.', 'Admin', 'Bar', 'marked absence (13)'],
|
|
|
|
|
['Jan. 14, 2024, 1:13 p.m.', 'Admin', 'Bar', 'cancellation of booking (13)'],
|
|
|
|
|
['Jan. 14, 2024, 12:12 p.m.', 'Manager', 'Foo', 'marked absence (12)'],
|
|
|
|
|
['Jan. 13, 2024, 12:12 p.m.', 'Manager', 'Foo', 'cancellation of booking (12)'],
|
|
|
|
|
['Jan. 13, 2024, 11:11 a.m.', 'Admin', 'Baz', 'marked absence (11)'],
|
|
|
|
|
['Jan. 12, 2024, 11:11 a.m.', 'Admin', 'Baz', 'cancellation of booking (11)'],
|
|
|
|
|
['Jan. 12, 2024, 10:10 a.m.', 'Admin', 'Bar', 'marked absence (10)'],
|
|
|
|
|
['Jan. 11, 2024, 10:10 a.m.', 'Admin', 'Bar', 'cancellation of booking (10)'],
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# filters
|
|
|
|
|
assert resp.form['timestamp'].attrs == {'type': 'date'}
|
|
|
|
|
resp.form['timestamp'].value = '2024-01-19'
|
|
|
|
|
resp = resp.form.submit()
|
|
|
|
|
assert [[x.text for x in PyQuery(x).find('td')] for x in resp.pyquery('tbody tr')] == [
|
|
|
|
|
['Jan. 19, 2024, 6:18 p.m.', 'Manager', 'Foo', 'cancellation of booking (18)'],
|
|
|
|
|
['Jan. 19, 2024, 5:17 p.m.', 'Admin', 'Baz', 'marked absence (17)'],
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
assert resp.form['timestamp'].value == '2024-01-19'
|
|
|
|
|
resp.form['agenda'].value = agendas[0].id
|
|
|
|
|
resp = resp.form.submit()
|
|
|
|
|
assert [[x.text for x in PyQuery(x).find('td')] for x in resp.pyquery('tbody tr')] == [
|
|
|
|
|
['Jan. 19, 2024, 6:18 p.m.', 'Manager', 'Foo', 'cancellation of booking (18)']
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
resp.form['agenda'].value = agendas[1].id
|
|
|
|
|
resp = resp.form.submit()
|
|
|
|
|
assert [[x.text for x in PyQuery(x).find('td')] for x in resp.pyquery('tbody tr')] == []
|
|
|
|
|
|
|
|
|
|
resp.form['timestamp'].value = ''
|
|
|
|
|
resp.form['action_type'].value = 'booking'
|
|
|
|
|
resp = resp.form.submit()
|
|
|
|
|
assert [[x.text for x in PyQuery(x).find('td')] for x in resp.pyquery('tbody tr')] == [
|
|
|
|
|
['Jan. 20, 2024, 7:19 p.m.', 'Admin', 'Bar', 'cancellation of booking (19)'],
|
|
|
|
|
['Jan. 17, 2024, 4:16 p.m.', 'Admin', 'Bar', 'cancellation of booking (16)'],
|
|
|
|
|
['Jan. 14, 2024, 1:13 p.m.', 'Admin', 'Bar', 'cancellation of booking (13)'],
|
|
|
|
|
['Jan. 11, 2024, 10:10 a.m.', 'Admin', 'Bar', 'cancellation of booking (10)'],
|
|
|
|
|
['Jan. 8, 2024, 7:07 a.m.', 'Admin', 'Bar', 'cancellation of booking (7)'],
|
|
|
|
|
['Jan. 5, 2024, 4:04 a.m.', 'Admin', 'Bar', 'cancellation of booking (4)'],
|
|
|
|
|
['Jan. 2, 2024, 1:01 a.m.', 'Admin', 'Bar', 'cancellation of booking (1)'],
|
|
|
|
|
]
|