Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display updated label if changes made to event within four days of start date #574

Merged
merged 3 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '2.4'
services:
app:
image: lametro
image: lametro:upgrade
container_name: lametro
restart: always
build: .
Expand Down
10 changes: 8 additions & 2 deletions lametro/templatetags/lametro_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,14 @@ def updates_made(event_id):
"Updated" tag.
'''
event = LAMetroEvent.objects.get(id=event_id)
three_days_ago = LAMetroEvent._time_ago(days=3)
return event.updated_at > three_days_ago

try:
event.documents.get(note__icontains='agenda')
except EventDocument.DoesNotExist:
return False

four_days_before_meeting = event.start_time - timedelta(days=4)
return event.updated_at >= four_days_before_meeting

@register.filter
def find_agenda_url(all_documents):
Expand Down
21 changes: 17 additions & 4 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ def test_agenda_pdf_form_error():
assert agenda_pdf_form.is_valid() == False


@pytest.mark.parametrize('has_updates', [True, False])
def test_updates_made(event, has_updates, mocker):
@pytest.mark.parametrize('has_updates,has_agenda', [
(True, True),
(True, False),
(False, True),
(False, False),
])
def test_updates_made(event, event_document, mocker, has_updates, has_agenda):
if has_updates:
updated_at = LAMetroEvent._time_ago(days=1)
else:
Expand All @@ -67,8 +72,16 @@ def test_updates_made(event, has_updates, mocker):
mock_update = mocker.patch('lametro.models.LAMetroEvent.updated_at', new_callable=mocker.PropertyMock)
mock_update.return_value = updated_at

event = event.build()
assert updates_made(event.id) == has_updates
event = event.build(start_date=datetime.now().isoformat()[:25])

if has_agenda:
document = event_document.build(note='Agenda')
else:
document = event_document.build(note='Some document')

event.documents.add(document)

assert updates_made(event.id) == (has_updates and has_agenda)


@pytest.fixture
Expand Down