From 986309b80a296c1533cce2c311ac24f91db03437 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Mon, 9 Dec 2019 15:53:45 +0100
Subject: [PATCH 1/4] misc: fix flake8 errors (#29209)

---
 chrono/agendas/models.py |  54 +++++----
 tests/test_agendas.py    |  44 +++++--
 tests/test_manager.py    | 246 +++++++++++++++++++++++++--------------
 3 files changed, 225 insertions(+), 119 deletions(-)

diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py
index 12e88da..fb09957 100644
--- a/chrono/agendas/models.py
+++ b/chrono/agendas/models.py
@@ -74,13 +74,15 @@ class Agenda(models.Model):
     minimal_booking_delay = models.PositiveIntegerField(
             _('Minimal booking delay (in days)'), default=1)
     maximal_booking_delay = models.PositiveIntegerField(
-            _('Maximal booking delay (in days)'), default=56) # eight weeks
-    edit_role = models.ForeignKey(Group, blank=True, null=True, default=None,
-            related_name='+', verbose_name=_('Edit Role'),
-            on_delete=models.SET_NULL)
-    view_role = models.ForeignKey(Group, blank=True, null=True, default=None,
-            related_name='+', verbose_name=_('View Role'),
-            on_delete=models.SET_NULL)
+            _('Maximal booking delay (in days)'), default=56)  # eight weeks
+    edit_role = models.ForeignKey(
+        Group, blank=True, null=True, default=None,
+        related_name='+', verbose_name=_('Edit Role'),
+        on_delete=models.SET_NULL)
+    view_role = models.ForeignKey(
+        Group, blank=True, null=True, default=None,
+        related_name='+', verbose_name=_('View Role'),
+        on_delete=models.SET_NULL)
 
     class Meta:
         ordering = ['label']
@@ -170,6 +172,7 @@ class Agenda(models.Model):
                 Desk.import_json(desk).save()
         return created
 
+
 WEEKDAYS_LIST = sorted(WEEKDAYS.items(), key=lambda x: x[0])
 
 
@@ -228,8 +231,9 @@ class TimePeriod(models.Model):
         if real_min_datetime < min_datetime:
             real_min_datetime += datetime.timedelta(days=7)
 
-        event_datetime = real_min_datetime.replace(hour=self.start_time.hour,
-                minute=self.start_time.minute, second=0, microsecond=0)
+        event_datetime = real_min_datetime.replace(
+            hour=self.start_time.hour,
+            minute=self.start_time.minute, second=0, microsecond=0)
         while event_datetime < max_datetime:
             end_time = event_datetime + meeting_duration
             next_time = event_datetime + duration
@@ -286,11 +290,13 @@ class Event(models.Model):
     places = models.PositiveIntegerField(_('Places'))
     waiting_list_places = models.PositiveIntegerField(
             _('Places in waiting list'), default=0)
-    label = models.CharField(_('Label'), max_length=150, null=True, blank=True,
-            help_text=_('Optional label to identify this date.'))
+    label = models.CharField(
+        _('Label'), max_length=150, null=True, blank=True,
+        help_text=_('Optional label to identify this date.'))
     slug = models.SlugField(_('Identifier'), max_length=160, null=True, blank=True, default=None)
-    description = models.TextField(_('Description'), null=True, blank=True,
-            help_text=_('Optional event description.'))
+    description = models.TextField(
+        _('Description'), null=True, blank=True,
+        help_text=_('Optional event description.'))
     full = models.BooleanField(default=False)
     meeting_type = models.ForeignKey(MeetingType, null=True, on_delete=models.CASCADE)
     desk = models.ForeignKey('Desk', null=True, on_delete=models.CASCADE)
@@ -327,13 +333,15 @@ class Event(models.Model):
 
     @property
     def booked_places(self):
-        return self.booking_set.filter(cancellation_datetime__isnull=True,
-                in_waiting_list=False).count()
+        return self.booking_set.filter(
+            cancellation_datetime__isnull=True,
+            in_waiting_list=False).count()
 
     @property
     def waiting_list(self):
-        return self.booking_set.filter(cancellation_datetime__isnull=True,
-                in_waiting_list=True).count()
+        return self.booking_set.filter(
+            cancellation_datetime__isnull=True,
+            in_waiting_list=True).count()
 
     @property
     def end_datetime(self):
@@ -372,8 +380,9 @@ class Booking(models.Model):
     in_waiting_list = models.BooleanField(default=False)
     creation_datetime = models.DateTimeField(auto_now_add=True)
     # primary booking is used to group multiple bookings together
-    primary_booking = models.ForeignKey('self', null=True,
-            on_delete=models.CASCADE, related_name='secondary_booking_set')
+    primary_booking = models.ForeignKey(
+        'self', null=True,
+        on_delete=models.CASCADE, related_name='secondary_booking_set')
 
     label = models.CharField(max_length=250, blank=True)
     user_display_label = models.CharField(verbose_name=_('Label displayed to user'), max_length=250, blank=True)
@@ -422,7 +431,6 @@ class Booking(models.Model):
         return ics.serialize()
 
 
-
 @python_2_unicode_compatible
 class Desk(models.Model):
     agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE)
@@ -591,8 +599,10 @@ class Desk(models.Model):
 
             if keep_synced_by_uid:
                 # delete all outdated exceptions from remote calendar
-                TimePeriodException.objects.filter(update_datetime__lt=update_datetime,
-                                    desk=self).exclude(external_id='').delete()
+                TimePeriodException.objects.filter(
+                    update_datetime__lt=update_datetime,
+                    desk=self
+                ).exclude(external_id='').delete()
 
         return total_created
 
diff --git a/tests/test_agendas.py b/tests/test_agendas.py
index 820d8a2..daf2e52 100644
--- a/tests/test_agendas.py
+++ b/tests/test_agendas.py
@@ -8,10 +8,10 @@ import requests
 from django.utils.timezone import now, make_aware, localtime
 from django.contrib.auth.models import Group
 from django.core.management import call_command
-from django.core.management.base import CommandError
 
-from chrono.agendas.models import (Agenda, Event, Booking, MeetingType,
-                        Desk, TimePeriod, TimePeriodException, ICSError)
+from chrono.agendas.models import (
+    Agenda, Event, Booking, MeetingType,
+    Desk, TimePeriodException, ICSError)
 
 pytestmark = pytest.mark.django_db
 
@@ -154,6 +154,7 @@ def test_event_manager():
     booking.save()
     assert Event.objects.all()[0].booked_places == 0
 
+
 def test_event_bookable_period():
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -179,6 +180,7 @@ def test_event_bookable_period():
     event.save()
     assert event.in_bookable_period() is False
 
+
 def test_meeting_type_slugs():
     agenda1 = Agenda(label=u'Foo bar')
     agenda1.save()
@@ -197,6 +199,7 @@ def test_meeting_type_slugs():
     meeting_type3.save()
     assert meeting_type3.slug == 'baz'
 
+
 def test_timeperiodexception_creation_from_ics():
     agenda = Agenda(label=u'Test 1 agenda')
     agenda.save()
@@ -206,6 +209,7 @@ def test_timeperiodexception_creation_from_ics():
     assert exceptions_count == 2
     assert TimePeriodException.objects.filter(desk=desk).count() == 2
 
+
 def test_timeperiodexception_creation_from_ics_without_startdt():
     agenda = Agenda(label=u'Test 2 agenda')
     agenda.save()
@@ -219,9 +223,10 @@ def test_timeperiodexception_creation_from_ics_without_startdt():
         lines.append(line)
     ics_sample = "\n".join(lines)
     with pytest.raises(ICSError) as e:
-        exceptions_count = desk.create_timeperiod_exceptions_from_ics(ics_sample)
+        desk.create_timeperiod_exceptions_from_ics(ics_sample)
     assert 'Event "Event 1" has no start date.' == str(e.value)
 
+
 def test_timeperiodexception_creation_from_ics_without_enddt():
     agenda = Agenda(label=u'Test 3 agenda')
     agenda.save()
@@ -234,7 +239,7 @@ def test_timeperiodexception_creation_from_ics_without_enddt():
             continue
         lines.append(line)
     ics_sample = "\n".join(lines)
-    exceptions_count = desk.create_timeperiod_exceptions_from_ics(ics_sample)
+    desk.create_timeperiod_exceptions_from_ics(ics_sample)
     for exception in TimePeriodException.objects.filter(desk=desk):
         end_time = localtime(exception.end_datetime).time()
         assert end_time == datetime.time(23, 59, 59, 999999)
@@ -257,6 +262,7 @@ def test_timeperiodexception_creation_from_ics_with_recurrences():
     assert set(TimePeriodException.objects.values_list('start_datetime', flat=True)) == set([
         make_aware(datetime.datetime(2018, 1, 1)), make_aware(datetime.datetime(2018, 1, 2))])
 
+
 def test_timeexception_creation_from_ics_with_dates():
     agenda = Agenda(label=u'Test 5 agenda')
     agenda.save()
@@ -275,24 +281,27 @@ def test_timeexception_creation_from_ics_with_dates():
         assert localtime(exception.start_datetime) == make_aware(datetime.datetime(2018, 1, 1, 0, 0))
         assert localtime(exception.end_datetime) == make_aware(datetime.datetime(2018, 1, 1, 0, 0))
 
+
 def test_timeexception_create_from_invalid_ics():
     agenda = Agenda(label=u'Test 6 agenda')
     agenda.save()
     desk = Desk(label='Test 6 desk', agenda=agenda)
     desk.save()
     with pytest.raises(ICSError) as e:
-        exceptions_count = desk.create_timeperiod_exceptions_from_ics(INVALID_ICS_SAMPLE)
+        desk.create_timeperiod_exceptions_from_ics(INVALID_ICS_SAMPLE)
     assert str(e.value) == 'File format is invalid.'
 
+
 def test_timeexception_create_from_ics_with_no_events():
     agenda = Agenda(label=u'Test 7 agenda')
     agenda.save()
     desk = Desk(label='Test 7 desk', agenda=agenda)
     desk.save()
     with pytest.raises(ICSError) as e:
-        exceptions_count = desk.create_timeperiod_exceptions_from_ics(ICS_SAMPLE_WITH_NO_EVENTS)
+        desk.create_timeperiod_exceptions_from_ics(ICS_SAMPLE_WITH_NO_EVENTS)
     assert str(e.value) == "The file doesn't contain any events."
 
+
 @mock.patch('chrono.agendas.models.requests.get')
 def test_timeperiodexception_creation_from_remote_ics(mocked_get):
     agenda = Agenda(label=u'Test 8 agenda')
@@ -304,7 +313,7 @@ def test_timeperiodexception_creation_from_remote_ics(mocked_get):
     mocked_get.return_value = mocked_response
     exceptions_count = desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
     assert exceptions_count == 2
-    mocked_response.text = re.sub('SUMMARY:\w+', 'SUMMARY:New summmary', ICS_SAMPLE, re.MULTILINE)
+    mocked_response.text = re.sub(r'SUMMARY:\w+', 'SUMMARY:New summmary', ICS_SAMPLE, re.MULTILINE)
     mocked_get.return_value = mocked_response
     desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
     for timeperiod in TimePeriodException.objects.filter(external_id='desk-%s:' % desk.id, desk=desk):
@@ -316,6 +325,7 @@ def test_timeperiodexception_creation_from_remote_ics(mocked_get):
     assert exceptions_count == 0
     TimePeriodException.objects.filter(external_id='desk-%s:' % desk.id).count() == 0
 
+
 @mock.patch('chrono.agendas.models.requests.get')
 def test_timeperiodexception_creation_from_unreachable_remote_ics(mocked_get):
     agenda = Agenda(label=u'Test 9 agenda')
@@ -325,13 +335,16 @@ def test_timeperiodexception_creation_from_unreachable_remote_ics(mocked_get):
     mocked_response = mock.Mock()
     mocked_response.text = ICS_SAMPLE
     mocked_get.return_value = mocked_response
+
     def mocked_requests_connection_error(*args, **kwargs):
         raise requests.ConnectionError('unreachable')
+
     mocked_get.side_effect = mocked_requests_connection_error
     with pytest.raises(ICSError) as e:
-        exceptions_count = desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
+        desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
     assert str(e.value) == "Failed to retrieve remote calendar (http://example.com/sample.ics, unreachable)."
 
+
 @mock.patch('chrono.agendas.models.requests.get')
 def test_timeperiodexception_creation_from_forbidden_remote_ics(mocked_get):
     agenda = Agenda(label=u'Test 10 agenda')
@@ -341,14 +354,17 @@ def test_timeperiodexception_creation_from_forbidden_remote_ics(mocked_get):
     mocked_response = mock.Mock()
     mocked_response.status_code = 403
     mocked_get.return_value = mocked_response
+
     def mocked_requests_http_forbidden_error(*args, **kwargs):
         raise requests.HTTPError(response=mocked_response)
+
     mocked_get.side_effect = mocked_requests_http_forbidden_error
 
     with pytest.raises(ICSError) as e:
-        exceptions_count = desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
+        desk.create_timeperiod_exceptions_from_remote_ics('http://example.com/sample.ics')
     assert str(e.value) == "Failed to retrieve remote calendar (http://example.com/sample.ics, HTTP error 403)."
 
+
 @mock.patch('chrono.agendas.models.requests.get')
 def test_sync_desks_timeperiod_exceptions_from_ics(mocked_get, capsys):
     agenda = Agenda(label=u'Test 11 agenda')
@@ -358,12 +374,17 @@ def test_sync_desks_timeperiod_exceptions_from_ics(mocked_get, capsys):
     mocked_response = mock.Mock()
     mocked_response.status_code = 403
     mocked_get.return_value = mocked_response
+
     def mocked_requests_http_forbidden_error(*args, **kwargs):
         raise requests.HTTPError(response=mocked_response)
+
     mocked_get.side_effect = mocked_requests_http_forbidden_error
     call_command('sync_desks_timeperiod_exceptions')
     out, err = capsys.readouterr()
-    assert err == 'unable to create timeperiod exceptions for "Test 11 desk": Failed to retrieve remote calendar (http://example.com/sample.ics, HTTP error 403).\n'
+    assert err == (
+        'unable to create timeperiod exceptions for "Test 11 desk": '
+        'Failed to retrieve remote calendar (http://example.com/sample.ics, HTTP error 403).\n')
+
 
 @mock.patch('chrono.agendas.models.requests.get')
 def test_sync_desks_timeperiod_exceptions_from_changing_ics(mocked_get, caplog):
@@ -397,6 +418,7 @@ END:VCALENDAR"""
     call_command('sync_desks_timeperiod_exceptions')
     assert not TimePeriodException.objects.filter(desk=desk).exists()
 
+
 def test_base_meeting_duration():
     agenda = Agenda(label='Meeting', kind='meetings')
     agenda.save()
diff --git a/tests/test_manager.py b/tests/test_manager.py
index dc4db09..48d8c28 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -14,14 +14,12 @@ import pytest
 import requests
 from webtest import Upload
 
-from chrono.wsgi import application
-
 from chrono.agendas.models import (Agenda, Event, Booking, MeetingType,
                                    TimePeriod, Desk, TimePeriodException)
-from chrono.manager.utils import export_site
 
 pytestmark = pytest.mark.django_db
 
+
 @pytest.fixture
 def simple_user():
     try:
@@ -30,6 +28,7 @@ def simple_user():
         user = User.objects.create_user('user', password='user')
     return user
 
+
 @pytest.fixture
 def manager_user():
     try:
@@ -42,6 +41,7 @@ def manager_user():
     user.groups.set([group])
     return user
 
+
 @pytest.fixture
 def admin_user():
     try:
@@ -50,17 +50,20 @@ def admin_user():
         user = User.objects.create_superuser('admin', email=None, password='admin')
     return user
 
+
 @pytest.fixture
 def api_user():
     try:
         user = User.objects.get(username='api-user')
     except User.DoesNotExist:
-        user = User.objects.create(username='john.doe',
-                first_name=u'John', last_name=u'Doe', email='john.doe@example.net')
+        user = User.objects.create(
+            username='john.doe',
+            first_name=u'John', last_name=u'Doe', email='john.doe@example.net')
         user.set_password('password')
         user.save()
     return user
 
+
 def login(app, username='admin', password='admin'):
     login_page = app.get('/login/')
     login_form = login_page.forms[0]
@@ -70,15 +73,18 @@ def login(app, username='admin', password='admin'):
     assert resp.status_int == 302
     return app
 
+
 def test_unlogged_access(app):
     # connect while not being logged in
     assert app.get('/manage/', status=302).location.endswith('/login/?next=/manage/')
 
+
 def test_simple_user_access(app, simple_user):
     # connect while being logged as a simple user, access should be forbidden
     app = login(app, username='user', password='user')
     assert app.get('/manage/', status=403)
 
+
 def test_manager_user_access(app, manager_user):
     # connect while being logged as a manager user, access should be granted if
     # there's at least an agenda that is viewable or editable.
@@ -99,20 +105,24 @@ def test_manager_user_access(app, manager_user):
     agenda.save()
     assert app.get('/manage/', status=200)
 
+
 def test_home_redirect(app):
     assert app.get('/', status=302).location.endswith('/manage/')
 
+
 def test_access(app, admin_user):
     app = login(app)
     resp = app.get('/manage/', status=200)
     assert '<h2>Agendas</h2>' in resp.text
     assert "This site doesn't have any agenda yet." in resp.text
 
+
 def test_logout(app, admin_user):
     app = login(app)
     app.get('/logout/')
     assert app.get('/manage/', status=302).location.endswith('/login/?next=/manage/')
 
+
 def test_menu_json(app, admin_user):
     app = login(app)
     resp = app.get('/manage/menu.json', status=200)
@@ -123,6 +133,7 @@ def test_menu_json(app, admin_user):
     assert resp2.text == 'Q(%s);' % resp.text
     assert resp2.content_type == 'application/javascript'
 
+
 def test_view_agendas_as_manager(app, manager_user):
     agenda = Agenda(label=u'Foo Bar')
     agenda.view_role = manager_user.groups.all()[0]
@@ -143,8 +154,8 @@ def test_view_agendas_as_manager(app, manager_user):
     # check view gives access to the settings page for "events" agenda
     resp = app.get('/manage/agendas/%s/settings' % agenda.id, status=200)
     # but there's no links to actions
-    assert not '>New Event<' in resp.text
-    assert not '>Options<' in resp.text
+    assert '>New Event<' not in resp.text
+    assert '>Options<' not in resp.text
     app.get('/manage/agendas/%s/add-event' % agenda.id, status=403)
     app.get('/manage/agendas/%s/edit' % agenda.id, status=403)
 
@@ -156,6 +167,7 @@ def test_view_agendas_as_manager(app, manager_user):
     # check it gives a 404 on unknown agendas
     resp = app.get('/manage/agendas/%s/settings' % '9999', status=404)
 
+
 def test_add_agenda(app, admin_user):
     app = login(app)
     resp = app.get('/manage/', status=200)
@@ -169,6 +181,7 @@ def test_add_agenda(app, admin_user):
     assert 'Foo bar' in resp.text
     assert '<h2>Settings' in resp.text
 
+
 def test_add_agenda_as_manager(app, manager_user):
     # open /manage/ access to manager_user, and check agenda creation is not
     # allowed.
@@ -176,8 +189,9 @@ def test_add_agenda_as_manager(app, manager_user):
     agenda.view_role = manager_user.groups.all()[0]
     agenda.save()
     app = login(app, username='manager', password='manager')
-    resp = app.get('/manage/', status=200)
-    resp = app.get('/manage/agendas/add/', status=403)
+    app.get('/manage/', status=200)
+    app.get('/manage/agendas/add/', status=403)
+
 
 def test_options_agenda(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
@@ -194,6 +208,7 @@ def test_options_agenda(app, admin_user):
     assert 'Foo baz' in resp.text
     assert '<h2>Settings' in resp.text
 
+
 def test_options_agenda_as_manager(app, manager_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.view_role = manager_user.groups.all()[0]
@@ -201,7 +216,7 @@ def test_options_agenda_as_manager(app, manager_user):
     app = login(app, username='manager', password='manager')
     resp = app.get('/manage/', status=200)
     resp = resp.click('Foo bar')
-    assert not 'Settings' in resp.text
+    assert 'Settings' not in resp.text
     resp = app.get('/manage/agendas/%s/settings' % agenda.id, status=200)  # ok for "events" agendas
     resp = app.get('/manage/agendas/%s/edit' % agenda.id, status=403)
     agenda.kind = 'meetings'
@@ -227,6 +242,7 @@ def test_options_agenda_as_manager(app, manager_user):
     assert 'Foo baz' in resp.text
     assert '<h2>Settings' in resp.text
 
+
 def test_delete_agenda(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -237,7 +253,8 @@ def test_delete_agenda(app, admin_user):
     resp = resp.form.submit()
     assert resp.location.endswith('/manage/')
     resp = resp.follow()
-    assert not 'Foo bar' in resp.text
+    assert 'Foo bar' not in resp.text
+
 
 def test_delete_busy_agenda(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
@@ -272,6 +289,7 @@ def test_delete_busy_agenda(app, admin_user):
     booking.save()
     resp = resp.form.submit(status=403)
 
+
 def test_delete_agenda_as_manager(app, manager_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.edit_role = manager_user.groups.all()[0]
@@ -288,7 +306,7 @@ def test_delete_busy_desk(app, admin_user):
     agenda = Agenda(label=u'Foo bar', kind='meetings')
     agenda.save()
     desk_a = Desk.objects.create(agenda=agenda, label='Desk A')
-    desk_b = Desk.objects.create(agenda=agenda, label='Desk B')
+    Desk.objects.create(agenda=agenda, label='Desk B')
 
     event = Event(start_datetime=now() + datetime.timedelta(days=10),
                   places=10, agenda=agenda, desk=desk_a)
@@ -329,7 +347,7 @@ def test_add_event(app, admin_user):
     resp = resp.follow()
     event = Event.objects.get(places=10)
     assert event.slug is None
-    assert not "This agenda doesn't have any event yet." in resp.text
+    assert "This agenda doesn't have any event yet." not in resp.text
     assert '/manage/events/%s/' % event.id in resp.text
     assert ('Feb. 15, %s, 5 p.m.' % year) in resp.text
     assert '10 places' in resp.text
@@ -354,6 +372,7 @@ def test_add_event_on_missing_agenda(app, admin_user):
     app = login(app)
     app.get('/manage/agendas/%s/add-event' % '999', status=404)
 
+
 def test_add_event_as_manager(app, manager_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.view_role = manager_user.groups.all()[0]
@@ -373,11 +392,12 @@ def test_add_event_as_manager(app, manager_user):
     resp = resp.form.submit()
     resp = resp.follow()
     event = Event.objects.get(places=10)
-    assert not "This agenda doesn't have any event yet." in resp.text
+    assert "This agenda doesn't have any event yet." not in resp.text
     assert '/manage/events/%s/' % event.id in resp.text
     assert 'Feb. 15, 2016, 5 p.m.' in resp.text
     assert '10 places' in resp.text
 
+
 def test_edit_event(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -397,10 +417,12 @@ def test_edit_event(app, admin_user):
     assert 'Feb. 16, 2016, 5 p.m.' in resp.text
     assert '20 places' in resp.text
 
+
 def test_edit_missing_event(app, admin_user):
     app = login(app)
     app.get('/manage/agendas/999/', status=404)
 
+
 def test_edit_event_as_manager(app, manager_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.view_role = manager_user.groups.all()[0]
@@ -424,6 +446,7 @@ def test_edit_event_as_manager(app, manager_user):
     assert 'Feb. 16, 2016, 5 p.m.' in resp.text
     assert '20 places' in resp.text
 
+
 def test_booked_places(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -437,6 +460,7 @@ def test_booked_places(app, admin_user):
     assert '10 places' in resp.text
     assert '2 booked places' in resp.text
 
+
 def test_event_classes(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -448,21 +472,22 @@ def test_event_classes(app, admin_user):
     app = login(app)
 
     resp = app.get('/manage/agendas/%s/settings' % agenda.id, status=200)
-    assert not 'full' in resp.text
-    assert not 'overbooking' in resp.text
+    assert 'full' not in resp.text
+    assert 'overbooking' not in resp.text
 
     for i in range(8):
         Booking(event=event).save()
 
     resp = app.get('/manage/agendas/%s/settings' % agenda.id, status=200)
     assert 'full' in resp.text
-    assert not 'overbooking' in resp.text
+    assert 'overbooking' not in resp.text
 
     Booking(event=event).save()
     resp = app.get('/manage/agendas/%s/settings' % agenda.id, status=200)
     assert 'full' in resp.text
     assert 'overbooking' in resp.text
 
+
 def test_delete_event(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -478,6 +503,7 @@ def test_delete_event(app, admin_user):
     assert resp.location.endswith('/manage/agendas/%s/settings' % agenda.id)
     assert Event.objects.count() == 0
 
+
 def test_delete_busy_event(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -511,6 +537,7 @@ def test_delete_busy_event(app, admin_user):
     booking.save()
     resp = resp.form.submit(status=403)
 
+
 def test_delete_event_as_manager(app, manager_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.edit_role = manager_user.groups.all()[0]
@@ -527,6 +554,7 @@ def test_delete_event_as_manager(app, manager_user):
     assert resp.location.endswith('/manage/agendas/%s/settings' % agenda.id)
     assert Event.objects.count() == 0
 
+
 def test_import_events(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -590,8 +618,9 @@ def test_import_events(app, admin_user):
     Event.objects.all().delete()
 
     resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
-    resp.form['events_csv_file'] = Upload('t.csv',
-            u'2016-09-16,18:00,10,5,éléphant'.encode('utf-8'), 'text/csv')
+    resp.form['events_csv_file'] = Upload(
+        't.csv',
+        u'2016-09-16,18:00,10,5,éléphant'.encode('utf-8'), 'text/csv')
     resp = resp.form.submit(status=302)
     assert Event.objects.count() == 1
     assert Event.objects.all()[0].start_datetime == make_aware(datetime.datetime(2016, 9, 16, 18, 0))
@@ -601,8 +630,9 @@ def test_import_events(app, admin_user):
     Event.objects.all().delete()
 
     resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
-    resp.form['events_csv_file'] = Upload('t.csv',
-            u'2016-09-16,18:00,10,5,éléphant'.encode('iso-8859-15'), 'text/csv')
+    resp.form['events_csv_file'] = Upload(
+        't.csv',
+        u'2016-09-16,18:00,10,5,éléphant'.encode('iso-8859-15'), 'text/csv')
     resp = resp.form.submit(status=302)
     assert Event.objects.count() == 1
     assert Event.objects.all()[0].start_datetime == make_aware(datetime.datetime(2016, 9, 16, 18, 0))
@@ -612,8 +642,9 @@ def test_import_events(app, admin_user):
     Event.objects.all().delete()
 
     resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
-    resp.form['events_csv_file'] = Upload('t.csv',
-            u'2016-09-16,18:00,10,5,éléphant'.encode('eucjp'), 'text/csv')
+    resp.form['events_csv_file'] = Upload(
+        't.csv',
+        u'2016-09-16,18:00,10,5,éléphant'.encode('eucjp'), 'text/csv')
     resp = resp.form.submit(status=302)
     assert Event.objects.count() == 1
     assert Event.objects.all()[0].start_datetime == make_aware(datetime.datetime(2016, 9, 16, 18, 0))
@@ -623,18 +654,21 @@ def test_import_events(app, admin_user):
     Event.objects.all().delete()
 
     resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
-    resp.form['events_csv_file'] = Upload('t.csv', b'date,time,etc.\n'
-                                                   b'2016-09-16,18:00,10,5,bla bla bla\n'
-                                                   b'\n'
-                                                   b'2016-09-19,18:00,10', 'text/csv')
+    resp.form['events_csv_file'] = Upload(
+        't.csv',
+        b'date,time,etc.\n'
+        b'2016-09-16,18:00,10,5,bla bla bla\n'
+        b'\n'
+        b'2016-09-19,18:00,10', 'text/csv')
     resp = resp.form.submit(status=302)
     assert Event.objects.count() == 2
     Event.objects.all().delete()
 
     resp = app.get('/manage/agendas/%s/import-events' % agenda.id, status=200)
-    resp.form['events_csv_file'] = Upload('t.csv', '"date"\t"time"\t"etc."\n'
-                                                   '"2016-09-16"\t"18:00"\t"10"\t"5"\t"éléphant"\n'
-                                                   '"2016-09-19"\t"18:00"\t"10"'.encode('iso-8859-15'), 'text/csv')
+    resp.form['events_csv_file'] = Upload(
+        't.csv', '"date"\t"time"\t"etc."\n'
+        '"2016-09-16"\t"18:00"\t"10"\t"5"\t"éléphant"\n'
+        '"2016-09-19"\t"18:00"\t"10"'.encode('iso-8859-15'), 'text/csv')
     resp = resp.form.submit(status=302)
     assert Event.objects.count() == 2
     Event.objects.all().delete()
@@ -671,6 +705,7 @@ def test_add_meetings_agenda(app, admin_user):
     agenda = Agenda.objects.get(label='Foo bar')
     assert agenda.kind == 'meetings'
 
+
 def test_meetings_agenda_add_meeting_type(app, admin_user):
     agenda = Agenda(label=u'Foo bar', kind='meetings')
     agenda.save()
@@ -693,6 +728,7 @@ def test_meetings_agenda_add_meeting_type(app, admin_user):
     resp = resp.form.submit()
     assert MeetingType.objects.get(agenda=agenda).duration == 30
 
+
 def test_meetings_agenda_delete_meeting_type(app, admin_user):
     agenda = Agenda(label=u'Foo bar', kind='meetings')
     agenda.save()
@@ -709,6 +745,7 @@ def test_meetings_agenda_delete_meeting_type(app, admin_user):
     assert resp.location.endswith('/manage/agendas/%s/settings' % agenda.id)
     assert MeetingType.objects.count() == 0
 
+
 def test_meetings_agenda_add_time_period(app, admin_user):
     agenda = Agenda(label=u'Foo bar', kind='meetings')
     agenda.save()
@@ -771,6 +808,7 @@ def test_meetings_agenda_add_time_period(app, admin_user):
     resp = resp.form.submit()
     assert TimePeriod.objects.filter(desk=desk).count() == 4
 
+
 def test_meetings_agenda_delete_time_period(app, admin_user):
     agenda = Agenda(label=u'Foo bar', kind='meetings')
     agenda.save()
@@ -778,9 +816,10 @@ def test_meetings_agenda_delete_time_period(app, admin_user):
     MeetingType(agenda=agenda, label='Blah').save()
 
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
-    time_period = TimePeriod(desk=desk, weekday=2,
-            start_time=datetime.time(10, 0),
-            end_time=datetime.time(18, 0))
+    time_period = TimePeriod(
+        desk=desk, weekday=2,
+        start_time=datetime.time(10, 0),
+        end_time=datetime.time(18, 0))
     time_period.save()
 
     app = login(app)
@@ -807,7 +846,7 @@ def test_meetings_agenda_add_time_period_as_manager(app, manager_user):
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
     app = login(app, username='manager', password='manager')
     resp = app.get('/manage/agendas/%d/' % agenda.id)
-    assert not 'Settings' in resp.text
+    assert 'Settings' not in resp.text
     resp = app.get('/manage/agendas/%d/settings' % agenda.id, status=403)
     MeetingType(agenda=agenda, label='Blah').save()
     app.get('/manage/agendas/%d/desk/%d/add-time-period' % (agenda.id, desk.id), status=403)
@@ -945,7 +984,7 @@ def test_meetings_agenda_add_time_period_exception_when_booking_exists(app, admi
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
     resp = resp.click('Add a time period exception')
-    resp = resp.form.submit() # submit empty form
+    resp = resp.form.submit()  # submit empty form
     # fields should be marked with errors
     assert resp.text.count('This field is required.') == 2
     # try again with data in fields
@@ -967,6 +1006,7 @@ def test_meetings_agenda_add_time_period_exception_when_booking_exists(app, admi
     resp = resp.form.submit()
     assert TimePeriodException.objects.count() == 1
 
+
 def test_meetings_agenda_add_time_period_exception_when_cancelled_booking_exists(app, admin_user):
     agenda = Agenda.objects.create(label='Foo bar', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
@@ -975,8 +1015,9 @@ def test_meetings_agenda_add_time_period_exception_when_cancelled_booking_exists
                               start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
     event = Event.objects.create(agenda=agenda, places=1,
                                  start_datetime=make_aware(datetime.datetime(2017, 5, 22, 10, 30)))
-    Booking.objects.create(event=event,
-            cancellation_datetime=make_aware(datetime.datetime(2017, 5, 20, 10, 30)))
+    Booking.objects.create(
+        event=event,
+        cancellation_datetime=make_aware(datetime.datetime(2017, 5, 20, 10, 30)))
     login(app)
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -987,6 +1028,7 @@ def test_meetings_agenda_add_time_period_exception_when_cancelled_booking_exists
     assert 'One or several bookings exists within this time slot.' not in resp.text
     assert TimePeriodException.objects.count() == 1
 
+
 def test_meetings_agenda_add_invalid_time_period_exception(app, admin_user):
     agenda = Agenda.objects.create(label='Foo bar', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
@@ -1092,8 +1134,9 @@ def test_agenda_import_time_period_exception_from_ics(app, admin_user):
     resp = resp.click('Settings')
     assert 'Import exceptions from .ics' not in resp.text
 
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk,
+        start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
 
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -1182,8 +1225,9 @@ def test_agenda_import_time_period_exception_with_remote_ics(mocked_get, app, ad
     resp = resp.click('Settings')
     assert 'Import exceptions from .ics' not in resp.text
 
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk,
+        start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
 
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -1193,7 +1237,7 @@ def test_agenda_import_time_period_exception_with_remote_ics(mocked_get, app, ad
     assert 'ics_url' in resp.form.fields
     resp.form['ics_url'] = 'http://example.com/foo.ics'
     mocked_response = mock.Mock()
-    mocked_response.text =  """BEGIN:VCALENDAR
+    mocked_response.text = """BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//foo.bar//EN
 BEGIN:VEVENT
@@ -1213,8 +1257,10 @@ END:VCALENDAR"""
     resp = resp.click('upload')
     resp.form['ics_url'] = ''
     resp = resp.form.submit(status=302)
-    assert not TimePeriodException.objects.filter(desk=desk,
-                    external_id='desk-%s:random-event-id' % desk.id).exists()
+    assert not TimePeriodException.objects.filter(
+        desk=desk,
+        external_id='desk-%s:random-event-id' % desk.id).exists()
+
 
 @mock.patch('chrono.agendas.models.requests.get')
 def test_agenda_import_time_period_exception_with_remote_ics_no_events(mocked_get, app, admin_user):
@@ -1226,15 +1272,16 @@ def test_agenda_import_time_period_exception_with_remote_ics_no_events(mocked_ge
     resp = resp.click('Settings')
     assert 'Import exceptions from .ics' not in resp.text
 
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk,
+        start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
 
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
     resp = resp.click('upload')
     resp.form['ics_url'] = 'http://example.com/foo.ics'
     mocked_response = mock.Mock()
-    mocked_response.text =  """BEGIN:VCALENDAR
+    mocked_response.text = """BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//foo.bar//EN
 BEGIN:VEVENT
@@ -1257,8 +1304,9 @@ END:VCALENDAR"""
     resp = resp.click('Settings')
     resp = resp.click('upload')
     resp = resp.form.submit(status=302)
-    assert not TimePeriodException.objects.filter(desk=desk,
-                    external_id='random-event-id').exists()
+    assert not TimePeriodException.objects.filter(
+        desk=desk,
+        external_id='random-event-id').exists()
 
 
 @mock.patch('chrono.agendas.models.requests.get')
@@ -1271,15 +1319,16 @@ def test_agenda_update_time_period_exception_from_remote_ics(mocked_get, app, ad
     resp = resp.click('Settings')
     assert 'Import exceptions from .ics' not in resp.text
 
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk,
+        start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
 
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
     resp = resp.click('upload')
     resp.form['ics_url'] = 'http://example.com/foo.ics'
     mocked_response = mock.Mock()
-    mocked_response.text =  """BEGIN:VCALENDAR
+    mocked_response.text = """BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//foo.bar//EN
 BEGIN:VEVENT
@@ -1316,6 +1365,7 @@ END:VCALENDAR"""
     resp = resp.form.submit(status=302)
     assert TimePeriodException.objects.filter(desk=desk).count() == 1
 
+
 @mock.patch('chrono.agendas.models.requests.get')
 def test_agenda_import_time_period_exception_from_remote_ics_with_connection_error(mocked_get, app, admin_user):
     agenda = Agenda.objects.create(label='New Example', kind='meetings')
@@ -1326,8 +1376,9 @@ def test_agenda_import_time_period_exception_from_remote_ics_with_connection_err
     resp = resp.click('Settings')
     assert 'Import exceptions from .ics' not in resp.text
 
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk,
+        start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
 
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -1338,12 +1389,15 @@ def test_agenda_import_time_period_exception_from_remote_ics_with_connection_err
     resp.form['ics_url'] = 'http://example.com/foo.ics'
     mocked_response = mock.Mock()
     mocked_get.return_value = mocked_response
+
     def mocked_requests_connection_error(*args, **kwargs):
         raise requests.exceptions.ConnectionError('unreachable')
+
     mocked_get.side_effect = mocked_requests_connection_error
     resp = resp.form.submit(status=200)
     assert 'Failed to retrieve remote calendar (http://example.com/foo.ics, unreachable).' in resp.text
 
+
 @mock.patch('chrono.agendas.models.requests.get')
 def test_agenda_import_time_period_exception_from_forbidden_remote_ics(mocked_get, app, admin_user):
     agenda = Agenda.objects.create(label='New Example', kind='meetings')
@@ -1354,8 +1408,9 @@ def test_agenda_import_time_period_exception_from_forbidden_remote_ics(mocked_ge
     resp = resp.click('Settings')
     assert 'Import exceptions from .ics' not in resp.text
 
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk,
+        start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
 
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -1364,12 +1419,15 @@ def test_agenda_import_time_period_exception_from_forbidden_remote_ics(mocked_ge
     mocked_response = mock.Mock()
     mocked_response.status_code = 403
     mocked_get.return_value = mocked_response
+
     def mocked_requests_http_forbidden_error(*args, **kwargs):
         raise requests.exceptions.HTTPError(response=mocked_response)
+
     mocked_get.side_effect = mocked_requests_http_forbidden_error
     resp = resp.form.submit(status=200)
     assert 'Failed to retrieve remote calendar (http://example.com/foo.ics, HTTP error 403).' in resp.text
 
+
 @mock.patch('chrono.agendas.models.requests.get')
 def test_agenda_import_time_period_exception_from_remote_ics_with_ssl_error(mocked_get, app, admin_user):
     agenda = Agenda.objects.create(label='New Example', kind='meetings')
@@ -1379,8 +1437,9 @@ def test_agenda_import_time_period_exception_from_remote_ics_with_ssl_error(mock
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
     assert 'Import exceptions from .ics' not in resp.text
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk,
+        start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
 
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -1388,12 +1447,15 @@ def test_agenda_import_time_period_exception_from_remote_ics_with_ssl_error(mock
     resp.form['ics_url'] = 'https://example.com/foo.ics'
     mocked_response = mock.Mock()
     mocked_get.return_value = mocked_response
+
     def mocked_requests_http_ssl_error(*args, **kwargs):
         raise requests.exceptions.SSLError('SSL error')
+
     mocked_get.side_effect = mocked_requests_http_ssl_error
     resp = resp.form.submit(status=200)
     assert 'Failed to retrieve remote calendar (https://example.com/foo.ics, SSL error).' in resp.text
 
+
 def test_agenda_day_view(app, admin_user, manager_user, api_user):
     agenda = Agenda.objects.create(label='New Example', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='New Desk')
@@ -1409,13 +1471,14 @@ def test_agenda_day_view(app, admin_user, manager_user, api_user):
     resp = resp.follow()
     assert 'No opening hours this day.' in resp.text  # no time pediod
 
-    timeperiod = TimePeriod(desk=desk, weekday=today.weekday(),
-            start_time=datetime.time(10, 0),
-            end_time=datetime.time(18, 0))
+    timeperiod = TimePeriod(
+        desk=desk, weekday=today.weekday(),
+        start_time=datetime.time(10, 0),
+        end_time=datetime.time(18, 0))
     timeperiod.save()
     resp = app.get('/manage/agendas/%s/' % agenda.id, status=302).follow()
-    assert not 'No opening hours this day.' in resp.text
-    assert not 'div class="booking' in resp.text
+    assert 'No opening hours this day.' not in resp.text
+    assert 'div class="booking' not in resp.text
     assert resp.text.count('<tr') == 9  # 10->18 (not included)
 
     timeperiod.end_time = datetime.time(18, 30)  # end during an hour
@@ -1434,8 +1497,9 @@ def test_agenda_day_view(app, admin_user, manager_user, api_user):
     booking_url = resp.json['data'][0]['api']['fillslot_url']
     booking_url2 = resp.json['data'][2]['api']['fillslot_url']
     resp = app.post(booking_url)
-    resp = app.post_json(booking_url2,
-            params={'label': 'foo', 'user': 'bar', 'url': 'http://baz/'})
+    resp = app.post_json(
+        booking_url2,
+        params={'label': 'foo', 'user': 'bar', 'url': 'http://baz/'})
 
     app.reset()
     login(app)
@@ -1488,6 +1552,7 @@ def test_agenda_day_view(app, admin_user, manager_user, api_user):
     resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (
         agenda.id, date.year, date.month, date.day), status=200)
 
+
 def test_agenda_day_view_late_meeting(app, admin_user, manager_user, api_user):
     agenda = Agenda.objects.create(label='New Example', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='New Desk')
@@ -1498,9 +1563,10 @@ def test_agenda_day_view_late_meeting(app, admin_user, manager_user, api_user):
 
     today = datetime.date.today()
 
-    timeperiod = TimePeriod(desk=desk, weekday=today.weekday(),
-            start_time=datetime.time(10, 0),
-            end_time=datetime.time(23, 30))
+    timeperiod = TimePeriod(
+        desk=desk, weekday=today.weekday(),
+        start_time=datetime.time(10, 0),
+        end_time=datetime.time(23, 30))
     timeperiod.save()
 
     login(app)
@@ -1508,6 +1574,7 @@ def test_agenda_day_view_late_meeting(app, admin_user, manager_user, api_user):
     assert resp.text.count('<tr') == 15
     assert '<th class="hour">11 p.m.</th>' in resp.text
 
+
 def test_agenda_invalid_day_view(app, admin_user, manager_user, api_user):
     agenda = Agenda.objects.create(label='New Example', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='New Desk')
@@ -1520,6 +1587,7 @@ def test_agenda_invalid_day_view(app, admin_user, manager_user, api_user):
     resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (agenda.id, 2018, 11, 31), status=302)
     assert resp.location.endswith('2018/11/30/')
 
+
 def test_agenda_month_view(app, admin_user, manager_user, api_user):
     agenda = Agenda.objects.create(label='Passeports', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
@@ -1535,18 +1603,19 @@ def test_agenda_month_view(app, admin_user, manager_user, api_user):
     today = datetime.date.today()
     assert resp.request.url.endswith('%s/%s/' % (today.year, today.month))
 
-    assert 'Day view' in resp.text # date view link should be present
+    assert 'Day view' in resp.text  # date view link should be present
     assert 'No opening hours this month.' in resp.text
 
     today = datetime.date(2018, 11, 10)  # fixed day
     timeperiod_weekday = today.weekday()
-    timeperiod = TimePeriod(desk=desk, weekday=timeperiod_weekday,
-            start_time=datetime.time(10, 0),
-            end_time=datetime.time(18, 0))
+    timeperiod = TimePeriod(
+        desk=desk, weekday=timeperiod_weekday,
+        start_time=datetime.time(10, 0),
+        end_time=datetime.time(18, 0))
     timeperiod.save()
     resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, today.year, today.month))
-    assert not 'No opening hours this month.' in resp.text
-    assert not '<div class="booking' in resp.text
+    assert 'No opening hours this month.' not in resp.text
+    assert '<div class="booking' not in resp.text
     first_month_day = today.replace(day=1)
     last_month_day = today.replace(day=1, month=today.month+1) - datetime.timedelta(days=1)
     start_week_number = first_month_day.isocalendar()[1]
@@ -1564,19 +1633,21 @@ def test_agenda_month_view(app, admin_user, manager_user, api_user):
     booking_url = resp.json['data'][0]['api']['fillslot_url']
     booking_url2 = resp.json['data'][2]['api']['fillslot_url']
     booking = app.post(booking_url)
-    booking_2 = app.post_json(booking_url2,
-            params={'label': 'foo', 'user': 'bar', 'url': 'http://baz/'})
+    booking_2 = app.post_json(
+        booking_url2,
+        params={'label': 'foo', 'user': 'bar', 'url': 'http://baz/'})
 
     app.reset()
     login(app)
     date = Booking.objects.all()[0].event.start_datetime
     resp = app.get('/manage/agendas/%s/%d/%d/' % (
         agenda.id, date.year, date.month))
-    assert resp.text.count('<div class="booking" style="left:1.0%;height:33.0%;') == 2 # booking cells
+    assert resp.text.count('<div class="booking" style="left:1.0%;height:33.0%;') == 2  # booking cells
     desk = Desk.objects.create(agenda=agenda, label='Desk B')
-    timeperiod = TimePeriod(desk=desk, weekday=timeperiod_weekday,
-            start_time=datetime.time(10, 0),
-            end_time=datetime.time(18, 0))
+    timeperiod = TimePeriod(
+        desk=desk, weekday=timeperiod_weekday,
+        start_time=datetime.time(10, 0),
+        end_time=datetime.time(18, 0))
     timeperiod.save()
 
     app.reset()
@@ -1611,7 +1682,8 @@ def test_agenda_month_view(app, admin_user, manager_user, api_user):
     # check December is correctly displayed
     today = datetime.date(2018, 12, 10)
     resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, today.year, today.month))
-    assert not 'No opening hours this month.' in resp.text
+    assert 'No opening hours this month.' not in resp.text
+
 
 def test_agenda_month_view_dst_change(app, admin_user, manager_user, api_user):
     agenda = Agenda.objects.create(label='Passeports', kind='meetings')
@@ -1621,9 +1693,10 @@ def test_agenda_month_view_dst_change(app, admin_user, manager_user, api_user):
     meetingtype.save()
 
     for weekday in range(0, 7):  # open all mornings
-        TimePeriod(desk=desk, weekday=weekday,
-                start_time=datetime.time(9, 0),
-                end_time=datetime.time(12, 0)).save()
+        TimePeriod(
+            desk=desk, weekday=weekday,
+            start_time=datetime.time(9, 0),
+            end_time=datetime.time(12, 0)).save()
 
     login(app)
     for date in ('2019-10-01', '2019-10-31'):
@@ -1655,8 +1728,9 @@ def test_import_agenda_as_manager(app, manager_user):
     agenda.view_role = manager_user.groups.all()[0]
     agenda.save()
     app = login(app, username='manager', password='manager')
-    resp = app.get('/manage/', status=200)
-    resp = app.get('/manage/agendas/import/', status=403)
+    app.get('/manage/', status=200)
+    app.get('/manage/agendas/import/', status=403)
+
 
 def test_import_agenda(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
-- 
2.20.1

