From f693ab4e70135c87fc79e1864695b33a7413aa63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 13 Dec 2019 13:57:43 +0100
Subject: [PATCH 1/4] misc: black (#29209)

---
 chrono/agendas/models.py | 206 +++++++++++++++---------
 tests/test_agendas.py    |  84 +++++++---
 tests/test_manager.py    | 334 ++++++++++++++++++++++++---------------
 3 files changed, 396 insertions(+), 228 deletions(-)

diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py
index c5c8ae1..3374a50 100644
--- a/chrono/agendas/models.py
+++ b/chrono/agendas/models.py
@@ -71,16 +71,28 @@ class Agenda(models.Model):
     label = models.CharField(_('Label'), max_length=150)
     slug = models.SlugField(_('Identifier'), max_length=160, unique=True)
     kind = models.CharField(_('Kind'), max_length=20, choices=AGENDA_KINDS, default='events')
-    minimal_booking_delay = models.PositiveIntegerField(
-            _('Minimal booking delay (in days)'), default=1)
+    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']
@@ -124,7 +136,7 @@ class Agenda(models.Model):
             'permissions': {
                 'view': self.view_role.name if self.view_role else None,
                 'edit': self.edit_role.name if self.edit_role else None,
-            }
+            },
         }
         if self.kind == 'events':
             agenda['events'] = [x.export_json() for x in self.event_set.all()]
@@ -170,6 +182,7 @@ class Agenda(models.Model):
                 Desk.import_json(desk).save()
         return created
 
+
 WEEKDAYS_LIST = sorted(WEEKDAYS.items(), key=lambda x: x[0])
 
 
@@ -198,9 +211,10 @@ class TimePeriod(models.Model):
 
     def __str__(self):
         return u'%s / %s → %s' % (
-                force_text(WEEKDAYS[self.weekday]),
-                date_format(self.start_time, 'TIME_FORMAT'),
-                date_format(self.end_time, 'TIME_FORMAT'))
+            force_text(WEEKDAYS[self.weekday]),
+            date_format(self.start_time, 'TIME_FORMAT'),
+            date_format(self.end_time, 'TIME_FORMAT'),
+        )
 
     @property
     def weekday_str(self):
@@ -212,9 +226,9 @@ class TimePeriod(models.Model):
 
     def export_json(self):
         return {
-           'weekday': self.weekday,
-           'start_time': self.start_time.strftime('%H:%M'),
-           'end_time': self.end_time.strftime('%H:%M'),
+            'weekday': self.weekday,
+            'start_time': self.start_time.strftime('%H:%M'),
+            'end_time': self.end_time.strftime('%H:%M'),
         }
 
     def get_time_slots(self, min_datetime, max_datetime, meeting_type):
@@ -223,19 +237,21 @@ class TimePeriod(models.Model):
         min_datetime = make_naive(min_datetime)
         max_datetime = make_naive(max_datetime)
 
-        real_min_datetime = min_datetime + datetime.timedelta(
-                days=self.weekday - min_datetime.weekday())
+        real_min_datetime = min_datetime + datetime.timedelta(days=self.weekday - min_datetime.weekday())
         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
             if end_time.time() > self.end_time or event_datetime.date() != next_time.date():
                 # back to morning
-                event_datetime = event_datetime.replace(hour=self.start_time.hour, minute=self.start_time.minute)
+                event_datetime = event_datetime.replace(
+                    hour=self.start_time.hour, minute=self.start_time.minute
+                )
                 # but next week
                 event_datetime += datetime.timedelta(days=7)
                 next_time = event_datetime + duration
@@ -243,7 +259,9 @@ class TimePeriod(models.Model):
             if event_datetime > max_datetime:
                 break
 
-            yield TimeSlot(start_datetime=make_aware(event_datetime), meeting_type=meeting_type, desk=self.desk)
+            yield TimeSlot(
+                start_datetime=make_aware(event_datetime), meeting_type=meeting_type, desk=self.desk
+            )
             event_datetime = next_time
 
 
@@ -265,7 +283,8 @@ class MeetingType(models.Model):
     @classmethod
     def import_json(cls, data):
         meeting_type, created = cls.objects.get_or_create(
-            slug=data['slug'], agenda=data['agenda'], defaults=data)
+            slug=data['slug'], agenda=data['agenda'], defaults=data
+        )
         if not created:
             for k, v in data.items():
                 setattr(meeting_type, k, v)
@@ -273,9 +292,9 @@ class MeetingType(models.Model):
 
     def export_json(self):
         return {
-           'label': self.label,
-           'slug': self.slug,
-           'duration': self.duration,
+            'label': self.label,
+            'slug': self.slug,
+            'duration': self.duration,
         }
 
 
@@ -284,13 +303,18 @@ class Event(models.Model):
     agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE)
     start_datetime = models.DateTimeField(_('Date/time'))
     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.'))
+    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.'),
+    )
     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)
@@ -310,14 +334,24 @@ class Event(models.Model):
 
     def check_full(self):
         self.full = bool(
-            (self.booked_places >= self.places and self.waiting_list_places == 0) or
-            (self.waiting_list_places and self.waiting_list >= self.waiting_list_places))
+            (self.booked_places >= self.places and self.waiting_list_places == 0)
+            or (self.waiting_list_places and self.waiting_list >= self.waiting_list_places)
+        )
 
     def in_bookable_period(self):
-        if localtime(now()).date() > localtime(self.start_datetime - datetime.timedelta(days=self.agenda.minimal_booking_delay)).date():
+        if (
+            localtime(now()).date()
+            > localtime(
+                self.start_datetime - datetime.timedelta(days=self.agenda.minimal_booking_delay)
+            ).date()
+        ):
             return False
         if self.agenda.maximal_booking_delay and (
-                localtime(now()).date() <= localtime(self.start_datetime - datetime.timedelta(days=self.agenda.maximal_booking_delay)).date()):
+            localtime(now()).date()
+            <= localtime(
+                self.start_datetime - datetime.timedelta(days=self.agenda.maximal_booking_delay)
+            ).date()
+        ):
             return False
         if self.start_datetime < now():
             # past the event date, we may want in the future to allow for some
@@ -327,13 +361,11 @@ 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):
@@ -344,8 +376,9 @@ class Event(models.Model):
 
     @classmethod
     def import_json(cls, data):
-        data['start_datetime'] = make_aware(datetime.datetime.strptime(
-            data['start_datetime'], '%Y-%m-%d %H:%M:%S'))
+        data['start_datetime'] = make_aware(
+            datetime.datetime.strptime(data['start_datetime'], '%Y-%m-%d %H:%M:%S')
+        )
         if data.get('slug'):
             event, created = cls.objects.get_or_create(slug=data['slug'], defaults=data)
             if not created:
@@ -372,11 +405,14 @@ 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)
+    user_display_label = models.CharField(
+        verbose_name=_('Label displayed to user'), max_length=250, blank=True
+    )
     user_name = models.CharField(max_length=250, blank=True)
     backoffice_url = models.URLField(blank=True)
 
@@ -405,14 +441,20 @@ class Booking(models.Model):
         ics = vobject.iCalendar()
         ics.add('prodid').value = '-//Entr\'ouvert//NON SGML Publik'
         vevent = vobject.newFromBehavior('vevent')
-        vevent.add('uid').value = '%s-%s-%s' % (self.event.start_datetime.isoformat(), self.event.agenda.pk, self.pk)
+        vevent.add('uid').value = '%s-%s-%s' % (
+            self.event.start_datetime.isoformat(),
+            self.event.agenda.pk,
+            self.pk,
+        )
 
         vevent.add('summary').value = self.user_display_label or self.label
         vevent.add('dtstart').value = self.event.start_datetime
         if self.user_name:
             vevent.add('attendee').value = self.user_name
         if self.event.meeting_type:
-            vevent.add('dtend').value = self.event.start_datetime + datetime.timedelta(minutes=self.event.meeting_type.duration)
+            vevent.add('dtend').value = self.event.start_datetime + datetime.timedelta(
+                minutes=self.event.meeting_type.duration
+            )
 
         for field in ('description', 'location', 'comment', 'url'):
             field_value = request and request.GET.get(field) or self.extra_data.get(field)
@@ -422,15 +464,14 @@ class Booking(models.Model):
         return ics.serialize()
 
 
-
 @python_2_unicode_compatible
 class Desk(models.Model):
     agenda = models.ForeignKey(Agenda, on_delete=models.CASCADE)
     label = models.CharField(_('Label'), max_length=150)
     slug = models.SlugField(_('Identifier'), max_length=160)
     timeperiod_exceptions_remote_url = models.URLField(
-            _('URL to fetch time period exceptions from'),
-            blank=True, max_length=500)
+        _('URL to fetch time period exceptions from'), blank=True, max_length=500
+    )
 
     def __str__(self):
         return self.label
@@ -448,8 +489,7 @@ class Desk(models.Model):
     def import_json(cls, data):
         timeperiods = data.pop('timeperiods')
         exceptions = data.pop('exceptions')
-        instance, created = cls.objects.get_or_create(
-            slug=data['slug'], agenda=data['agenda'], defaults=data)
+        instance, created = cls.objects.get_or_create(slug=data['slug'], agenda=data['agenda'], defaults=data)
         if not created:
             for k, v in data.items():
                 setattr(instance, k, v)
@@ -462,21 +502,24 @@ class Desk(models.Model):
         return instance
 
     def export_json(self):
-        return {'label': self.label,
-                'slug': self.slug,
-                'timeperiods': [time_period.export_json() for time_period in self.timeperiod_set.all()],
-                'exceptions': [exception.export_json() for exception in self.timeperiodexception_set.all()]
-                }
+        return {
+            'label': self.label,
+            'slug': self.slug,
+            'timeperiods': [time_period.export_json() for time_period in self.timeperiod_set.all()],
+            'exceptions': [exception.export_json() for exception in self.timeperiodexception_set.all()],
+        }
 
     def get_exceptions_within_two_weeks(self):
         in_two_weeks = make_aware(datetime.datetime.today() + datetime.timedelta(days=14))
         exceptions = self.timeperiodexception_set.filter(end_datetime__gte=now()).filter(
-                Q(end_datetime__lte=in_two_weeks) | Q(start_datetime__lt=now()))
+            Q(end_datetime__lte=in_two_weeks) | Q(start_datetime__lt=now())
+        )
         if exceptions.exists():
             return exceptions
         # if none found within the 2 coming weeks, return the next one
-        next_exception = self.timeperiodexception_set.filter(
-            start_datetime__gte=now()).order_by('start_datetime').first()
+        next_exception = (
+            self.timeperiodexception_set.filter(start_datetime__gte=now()).order_by('start_datetime').first()
+        )
         if next_exception:
             return [next_exception]
         return []
@@ -491,12 +534,14 @@ class Desk(models.Model):
             response.raise_for_status()
         except requests.HTTPError as e:
             raise ICSError(
-                _('Failed to retrieve remote calendar (%(url)s, HTTP error %(status_code)s).') %
-                {'url': url, 'status_code': e.response.status_code})
+                _('Failed to retrieve remote calendar (%(url)s, HTTP error %(status_code)s).')
+                % {'url': url, 'status_code': e.response.status_code}
+            )
         except requests.RequestException as e:
             raise ICSError(
-                _('Failed to retrieve remote calendar (%(url)s, %(exception)s).') %
-                {'url': url, 'exception': e})
+                _('Failed to retrieve remote calendar (%(url)s, %(exception)s).')
+                % {'url': url, 'exception': e}
+            )
 
         return self.create_timeperiod_exceptions_from_ics(response.text, keep_synced_by_uid=True)
 
@@ -582,7 +627,9 @@ class Desk(models.Model):
                         if end_dt < update_datetime:
                             TimePeriodException.objects.filter(**kwargs).update(**event)
                         else:
-                            obj, created = TimePeriodException.objects.update_or_create(defaults=event, **kwargs)
+                            obj, created = TimePeriodException.objects.update_or_create(
+                                defaults=event, **kwargs
+                            )
                             if created:
                                 total_created += 1
                     # delete unseen occurrences
@@ -591,8 +638,9 @@ 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
 
@@ -606,8 +654,8 @@ class Desk(models.Model):
         aware_date = make_aware(datetime.datetime(date.year, date.month, date.day))
         aware_next_date = aware_date + datetime.timedelta(days=1)
         for exception in self.timeperiodexception_set.filter(
-                start_datetime__lt=aware_next_date,
-                end_datetime__gt=aware_date):
+            start_datetime__lt=aware_next_date, end_datetime__gt=aware_date
+        ):
             openslots.remove(exception.start_datetime, exception.end_datetime)
 
         return openslots.search(aware_date, aware_next_date)
@@ -634,18 +682,21 @@ class TimePeriodException(models.Model):
                 exc_repr = u'%s' % date_format(localtime(self.start_datetime), 'SHORT_DATE_FORMAT')
             else:
                 exc_repr = u'%s → %s' % (
-                        date_format(localtime(self.start_datetime), 'SHORT_DATE_FORMAT'),
-                        date_format(localtime(self.end_datetime), 'SHORT_DATE_FORMAT'))
+                    date_format(localtime(self.start_datetime), 'SHORT_DATE_FORMAT'),
+                    date_format(localtime(self.end_datetime), 'SHORT_DATE_FORMAT'),
+                )
         else:
             if localtime(self.start_datetime).date() == localtime(self.end_datetime).date():
                 # same day
                 exc_repr = u'%s → %s' % (
-                        date_format(localtime(self.start_datetime), 'SHORT_DATETIME_FORMAT'),
-                        date_format(localtime(self.end_datetime), 'TIME_FORMAT'))
+                    date_format(localtime(self.start_datetime), 'SHORT_DATETIME_FORMAT'),
+                    date_format(localtime(self.end_datetime), 'TIME_FORMAT'),
+                )
             else:
                 exc_repr = u'%s → %s' % (
-                        date_format(localtime(self.start_datetime), 'SHORT_DATETIME_FORMAT'),
-                        date_format(localtime(self.end_datetime), 'SHORT_DATETIME_FORMAT'))
+                    date_format(localtime(self.start_datetime), 'SHORT_DATETIME_FORMAT'),
+                    date_format(localtime(self.end_datetime), 'SHORT_DATETIME_FORMAT'),
+                )
 
         if self.label:
             exc_repr = u'%s (%s)' % (self.label, exc_repr)
@@ -662,9 +713,8 @@ class TimePeriodException(models.Model):
             # incomplete time period, can't tell
             return False
         for event in Event.objects.filter(
-                desk=self.desk,
-                booking__isnull=False,
-                booking__cancellation_datetime__isnull=True):
+            desk=self.desk, booking__isnull=False, booking__cancellation_datetime__isnull=True
+        ):
             if self.start_datetime <= event.start_datetime < self.end_datetime:
                 return True
         return False
diff --git a/tests/test_agendas.py b/tests/test_agendas.py
index 820d8a2..c919219 100644
--- a/tests/test_agendas.py
+++ b/tests/test_agendas.py
@@ -10,8 +10,16 @@ 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,
+    TimePeriod,
+    TimePeriodException,
+    ICSError,
+)
 
 pytestmark = pytest.mark.django_db
 
@@ -154,6 +162,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 +188,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 +207,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 +217,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()
@@ -222,6 +234,7 @@ def test_timeperiodexception_creation_from_ics_without_startdt():
         exceptions_count = 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()
@@ -248,14 +261,17 @@ def test_timeperiodexception_creation_from_ics_with_recurrences():
     desk.save()
     assert desk.create_timeperiod_exceptions_from_ics(ICS_SAMPLE_WITH_RECURRENT_EVENT) == 3
     assert TimePeriodException.objects.filter(desk=desk).count() == 3
-    assert set(TimePeriodException.objects.values_list('start_datetime', flat=True)) == set([
-        make_aware(datetime.datetime(2018, 1, 1)), make_aware(datetime.datetime(2019, 1, 1))])
+    assert set(TimePeriodException.objects.values_list('start_datetime', flat=True)) == set(
+        [make_aware(datetime.datetime(2018, 1, 1)), make_aware(datetime.datetime(2019, 1, 1))]
+    )
     assert desk.create_timeperiod_exceptions_from_ics(ICS_SAMPLE_WITH_RECURRENT_EVENT) == 0
     # verify occurences are cleaned when count changed
     assert desk.create_timeperiod_exceptions_from_ics(ICS_SAMPLE_WITH_RECURRENT_EVENT_2) == 0
     assert TimePeriodException.objects.filter(desk=desk).count() == 2
-    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))])
+    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')
@@ -275,6 +291,7 @@ 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()
@@ -284,6 +301,7 @@ def test_timeexception_create_from_invalid_ics():
         exceptions_count = 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()
@@ -293,6 +311,7 @@ def test_timeexception_create_from_ics_with_no_events():
         exceptions_count = 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')
@@ -316,6 +335,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 +345,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')
     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,35 +364,50 @@ 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')
-    assert str(e.value) == "Failed to retrieve remote calendar (http://example.com/sample.ics, HTTP error 403)."
+    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')
     agenda.save()
-    desk = Desk(label='Test 11 desk', agenda=agenda, timeperiod_exceptions_remote_url='http://example.com/sample.ics')
+    desk = Desk(
+        label='Test 11 desk', agenda=agenda, timeperiod_exceptions_remote_url='http://example.com/sample.ics'
+    )
     desk.save()
     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):
     agenda = Agenda(label=u'Test 11 agenda')
     agenda.save()
-    desk = Desk(label='Test 11 desk', agenda=agenda, timeperiod_exceptions_remote_url='http:example.com/sample.ics')
+    desk = Desk(
+        label='Test 11 desk', agenda=agenda, timeperiod_exceptions_remote_url='http:example.com/sample.ics'
+    )
     desk.save()
     mocked_response = mock.Mock()
     mocked_response.text = ICS_SAMPLE
@@ -397,6 +435,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()
@@ -427,14 +466,18 @@ def test_timeperiodexception_creation_from_ics_with_duration():
     exceptions_count = desk.create_timeperiod_exceptions_from_ics(ICS_SAMPLE_WITH_DURATION)
     assert exceptions_count == 2
     assert TimePeriodException.objects.filter(desk=desk).count() == 2
-    assert set(TimePeriodException.objects.values_list('start_datetime', flat=True)) == set([
-        make_aware(datetime.datetime(2017, 8, 31, 19, 8, 0)),
-        make_aware(datetime.datetime(2017, 8, 30, 20, 8, 0)),
-    ])
-    assert set(TimePeriodException.objects.values_list('end_datetime', flat=True)) == set([
-        make_aware(datetime.datetime(2017, 8, 31, 22, 34, 0)),
-        make_aware(datetime.datetime(2017, 9, 1, 0, 34, 0)),
-    ])
+    assert set(TimePeriodException.objects.values_list('start_datetime', flat=True)) == set(
+        [
+            make_aware(datetime.datetime(2017, 8, 31, 19, 8, 0)),
+            make_aware(datetime.datetime(2017, 8, 30, 20, 8, 0)),
+        ]
+    )
+    assert set(TimePeriodException.objects.values_list('end_datetime', flat=True)) == set(
+        [
+            make_aware(datetime.datetime(2017, 8, 31, 22, 34, 0)),
+            make_aware(datetime.datetime(2017, 9, 1, 0, 34, 0)),
+        ]
+    )
 
 
 @pytest.mark.freeze_time('2017-12-01')
@@ -447,8 +490,9 @@ def test_timeperiodexception_creation_from_ics_with_recurrences_in_the_past():
     desk.save()
     assert desk.create_timeperiod_exceptions_from_ics(ICS_SAMPLE_WITH_RECURRENT_EVENT_IN_THE_PAST) == 2
     assert TimePeriodException.objects.filter(desk=desk).count() == 2
-    assert set(TimePeriodException.objects.values_list('start_datetime', flat=True)) == set([
-        make_aware(datetime.datetime(2018, 1, 1)), make_aware(datetime.datetime(2019, 1, 1))])
+    assert set(TimePeriodException.objects.values_list('start_datetime', flat=True)) == set(
+        [make_aware(datetime.datetime(2018, 1, 1)), make_aware(datetime.datetime(2019, 1, 1))]
+    )
     assert desk.create_timeperiod_exceptions_from_ics(ICS_SAMPLE_WITH_RECURRENT_EVENT_IN_THE_PAST) == 0
 
 
diff --git a/tests/test_manager.py b/tests/test_manager.py
index dc4db09..4bc0b0a 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -16,12 +16,12 @@ from webtest import Upload
 
 from chrono.wsgi import application
 
-from chrono.agendas.models import (Agenda, Event, Booking, MeetingType,
-                                   TimePeriod, Desk, TimePeriodException)
+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 +30,7 @@ def simple_user():
         user = User.objects.create_user('user', password='user')
     return user
 
+
 @pytest.fixture
 def manager_user():
     try:
@@ -42,6 +43,7 @@ def manager_user():
     user.groups.set([group])
     return user
 
+
 @pytest.fixture
 def admin_user():
     try:
@@ -50,17 +52,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 +75,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 +107,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 +135,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]
@@ -156,6 +169,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 +183,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.
@@ -179,6 +194,7 @@ def test_add_agenda_as_manager(app, manager_user):
     resp = app.get('/manage/', status=200)
     resp = app.get('/manage/agendas/add/', status=403)
 
+
 def test_options_agenda(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
@@ -194,6 +210,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]
@@ -227,6 +244,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()
@@ -239,11 +257,11 @@ def test_delete_agenda(app, admin_user):
     resp = resp.follow()
     assert not 'Foo bar' in resp.text
 
+
 def test_delete_busy_agenda(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
-    event = Event(start_datetime=now() + datetime.timedelta(days=10),
-                  places=10, agenda=agenda)
+    event = Event(start_datetime=now() + datetime.timedelta(days=10), places=10, agenda=agenda)
     event.save()
 
     app = login(app)
@@ -272,6 +290,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]
@@ -290,8 +309,7 @@ def test_delete_busy_desk(app, admin_user):
     desk_a = Desk.objects.create(agenda=agenda, label='Desk A')
     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)
+    event = Event(start_datetime=now() + datetime.timedelta(days=10), places=10, agenda=agenda, desk=desk_a)
     event.save()
 
     app = login(app)
@@ -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]
@@ -378,12 +397,11 @@ def test_add_event_as_manager(app, manager_user):
     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()
-    event = Event(
-            start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)),
-            places=20, agenda=agenda)
+    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)), places=20, agenda=agenda)
     event.save()
     app = login(app)
     resp = app.get('/manage/agendas/%s/settings' % agenda.id, status=200)
@@ -397,16 +415,17 @@ 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]
     agenda.save()
-    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)),
-                  places=20, agenda=agenda)
+    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)), places=20, agenda=agenda)
     event.save()
     app = login(app, username='manager', password='manager')
     resp = app.get('/manage/events/%s/' % event.id, status=403)
@@ -424,11 +443,11 @@ 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()
-    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)),
-                  places=10, agenda=agenda)
+    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)), places=10, agenda=agenda)
     event.save()
     Booking(event=event).save()
     Booking(event=event).save()
@@ -437,11 +456,11 @@ 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()
-    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)),
-                  places=10, agenda=agenda)
+    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)), places=10, agenda=agenda)
     event.save()
     for i in range(2):
         Booking(event=event).save()
@@ -463,11 +482,11 @@ def test_event_classes(app, admin_user):
     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()
-    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)),
-                  places=10, agenda=agenda)
+    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)), places=10, agenda=agenda)
     event.save()
 
     app = login(app)
@@ -478,11 +497,11 @@ 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()
-    event = Event(start_datetime=now() + datetime.timedelta(days=10),
-                  places=10, agenda=agenda)
+    event = Event(start_datetime=now() + datetime.timedelta(days=10), places=10, agenda=agenda)
     event.save()
 
     app = login(app)
@@ -511,12 +530,12 @@ 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]
     agenda.save()
-    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)),
-                  places=10, agenda=agenda)
+    event = Event(start_datetime=make_aware(datetime.datetime(2016, 2, 15, 17, 0)), places=10, agenda=agenda)
     event.save()
 
     app = login(app, username='manager', password='manager')
@@ -527,6 +546,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 +610,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 +622,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 +634,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 +646,23 @@ 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 +699,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 +722,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 +739,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 +802,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 +810,9 @@ 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)
@@ -811,8 +843,9 @@ def test_meetings_agenda_add_time_period_as_manager(app, manager_user):
     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)
-    time_period = TimePeriod(desk=desk, weekday=0, start_time=datetime.time(9, 0),
-                             end_time=datetime.time(12, 0))
+    time_period = TimePeriod(
+        desk=desk, weekday=0, start_time=datetime.time(9, 0), end_time=datetime.time(12, 0)
+    )
     time_period.save()
     resp = app.get('/manage/agendas/%d/' % agenda.id)
     app.get('/manage/timeperiods/%d/edit' % time_period.id, status=403)
@@ -915,8 +948,12 @@ def test_meetings_agenda_add_time_period_exception(app, admin_user):
     resp = resp.form.submit().follow()
     assert TimePeriodException.objects.count() == 1
     time_period_exception = TimePeriodException.objects.first()
-    assert localtime(time_period_exception.start_datetime).strftime(dt_format) == tomorrow.replace(hour=8).strftime(dt_format)
-    assert localtime(time_period_exception.end_datetime).strftime(dt_format) == tomorrow.replace(hour=16).strftime(dt_format)
+    assert localtime(time_period_exception.start_datetime).strftime(dt_format) == tomorrow.replace(
+        hour=8
+    ).strftime(dt_format)
+    assert localtime(time_period_exception.end_datetime).strftime(dt_format) == tomorrow.replace(
+        hour=16
+    ).strftime(dt_format)
     # add an exception beyond 2 weeks and make sure it isn't listed
     resp = resp.click('Add a time period exception', index=1)
     future = tomorrow + datetime.timedelta(days=15)
@@ -927,7 +964,9 @@ def test_meetings_agenda_add_time_period_exception(app, admin_user):
     assert TimePeriodException.objects.count() == 2
     assert 'Exception 1' in resp.text
     assert 'Exception 2' not in resp.text
-    resp = resp.click(href="/manage/time-period-exceptions/%d/exception-extract-list" % agenda.desk_set.first().pk)
+    resp = resp.click(
+        href="/manage/time-period-exceptions/%d/exception-extract-list" % agenda.desk_set.first().pk
+    )
     assert 'Exception 1' in resp.text
     assert 'Exception 2' in resp.text
 
@@ -936,16 +975,18 @@ def test_meetings_agenda_add_time_period_exception_when_booking_exists(app, admi
     agenda = Agenda.objects.create(label='Foo bar', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
     MeetingType(agenda=agenda, label='Blah').save()
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                              start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
-    event = Event.objects.create(agenda=agenda, places=1, desk=desk,
-                                 start_datetime=make_aware(datetime.datetime(2017, 5, 22, 10, 30)))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk, start_time=datetime.time(10, 0), end_time=datetime.time(12, 0)
+    )
+    event = Event.objects.create(
+        agenda=agenda, places=1, desk=desk, start_datetime=make_aware(datetime.datetime(2017, 5, 22, 10, 30))
+    )
     Booking.objects.create(event=event)
     login(app)
     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
@@ -957,8 +998,9 @@ def test_meetings_agenda_add_time_period_exception_when_booking_exists(app, admi
 
     # check it's possible to add an exception on another desk
     desk = Desk.objects.create(agenda=agenda, label='Desk B')
-    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('Add a time period exception', href='desk/%s/' % desk.id)
@@ -967,16 +1009,20 @@ 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')
     MeetingType(agenda=agenda, label='Blah').save()
-    TimePeriod.objects.create(weekday=1, desk=desk,
-                              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)))
+    TimePeriod.objects.create(
+        weekday=1, desk=desk, 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))
+    )
     login(app)
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -987,12 +1033,14 @@ 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')
     MeetingType(agenda=agenda, label='Blah').save()
-    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)
+    )
     login(app)
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -1007,8 +1055,9 @@ def test_meetings_agenda_delete_time_period_exception(app, admin_user):
     agenda = Agenda.objects.create(label='Foo bar', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
     MeetingType(agenda=agenda, label='Blah').save()
-    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)
+    )
     login(app)
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -1022,8 +1071,12 @@ def test_meetings_agenda_delete_time_period_exception(app, admin_user):
     resp = resp.form.submit().follow()
     assert TimePeriodException.objects.count() == 1
     time_period_exception = TimePeriodException.objects.first()
-    assert localtime(time_period_exception.start_datetime).strftime(dt_format) == tomorrow.replace(hour=8).strftime(dt_format)
-    assert localtime(time_period_exception.end_datetime).strftime(dt_format) == tomorrow.replace(hour=16).strftime(dt_format)
+    assert localtime(time_period_exception.start_datetime).strftime(dt_format) == tomorrow.replace(
+        hour=8
+    ).strftime(dt_format)
+    assert localtime(time_period_exception.end_datetime).strftime(dt_format) == tomorrow.replace(
+        hour=16
+    ).strftime(dt_format)
     resp = resp.click(href='/manage/time-period-exceptions/%d/edit' % time_period_exception.id)
     resp = resp.click('Delete')
     resp = resp.form.submit().follow()
@@ -1035,7 +1088,8 @@ def test_meetings_agenda_delete_time_period_exception(app, admin_user):
         label='Future Exception',
         desk=desk,
         start_datetime=now() + datetime.timedelta(days=1),
-        end_datetime=now() + datetime.timedelta(days=2))
+        end_datetime=now() + datetime.timedelta(days=2),
+    )
     resp = app.get('/manage/time-period-exceptions/%d/exception-list' % desk.pk)
     resp = resp.click(href='/manage/time-period-exceptions/%d/delete' % time_period_exception.pk)
     resp = resp.form.submit(
@@ -1048,23 +1102,27 @@ def test_exception_list(app, admin_user):
     agenda = Agenda.objects.create(label='Foo bar', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
     MeetingType(agenda=agenda, label='Blah').save()
-    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)
+    )
     past_exception = TimePeriodException.objects.create(
         label='Past Exception',
         desk=desk,
         start_datetime=now() - datetime.timedelta(days=2),
-        end_datetime=now() - datetime.timedelta(days=1))
+        end_datetime=now() - datetime.timedelta(days=1),
+    )
     current_exception = TimePeriodException.objects.create(
         label='Current Exception',
         desk=desk,
         start_datetime=now() - datetime.timedelta(days=1),
-        end_datetime=now() + datetime.timedelta(days=1))
+        end_datetime=now() + datetime.timedelta(days=1),
+    )
     future_exception = TimePeriodException.objects.create(
         label='Future Exception',
         desk=desk,
         start_datetime=now() + datetime.timedelta(days=1),
-        end_datetime=now() + datetime.timedelta(days=2))
+        end_datetime=now() + datetime.timedelta(days=2),
+    )
 
     login(app)
     resp = app.get('/manage/agendas/%d/settings' % agenda.pk)
@@ -1092,8 +1150,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')
@@ -1150,9 +1209,9 @@ def test_agenda_import_time_period_exception_from_ics_recurrent(app, admin_user)
     agenda = Agenda.objects.create(label='Example', kind='meetings')
     desk = Desk.objects.create(agenda=agenda, label='Test Desk')
     MeetingType(agenda=agenda, label='Foo').save()
-    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)
+    )
     login(app)
     resp = app.get('/manage/agendas/%d/' % agenda.pk).follow()
     resp = resp.click('Settings')
@@ -1182,8 +1241,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 +1253,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 +1273,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 +1288,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 +1320,7 @@ 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 +1333,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,8 +1379,11 @@ 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):
+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')
     desk = Desk.objects.create(agenda=agenda, label='New Desk')
     MeetingType(agenda=agenda, label='Bar').save()
@@ -1326,8 +1392,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 +1405,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 +1424,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 +1435,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 +1453,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 +1463,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,9 +1487,9 @@ 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
@@ -1434,14 +1512,12 @@ 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)
     date = Booking.objects.all()[0].event.start_datetime
-    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (
-        agenda.id, date.year, date.month, date.day))
+    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (agenda.id, date.year, date.month, date.day))
     assert resp.text.count('div class="booking') == 2
     assert 'hourspan-2' in resp.text  # table CSS class
     assert 'height: 50%; top: 0%;' in resp.text  # booking cells
@@ -1450,8 +1526,7 @@ def test_agenda_day_view(app, admin_user, manager_user, api_user):
     # (and visually this will give more room for events)
     meetingtype = MeetingType(agenda=agenda, label='Baz', duration=15)
     meetingtype.save()
-    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (
-        agenda.id, date.year, date.month, date.day))
+    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (agenda.id, date.year, date.month, date.day))
     assert resp.text.count('div class="booking') == 2
     assert 'hourspan-4' in resp.text  # table CSS class
 
@@ -1464,29 +1539,26 @@ def test_agenda_day_view(app, admin_user, manager_user, api_user):
 
     app.reset()
     login(app)
-    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (
-        agenda.id, date.year, date.month, date.day))
+    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (agenda.id, date.year, date.month, date.day))
     assert resp.text.count('div class="booking') == 1
 
     # wrong type
     agenda2 = Agenda(label=u'Foo bar')
     agenda2.save()
-    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (
-        agenda2.id, date.year, date.month, date.day), status=404)
+    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (agenda2.id, date.year, date.month, date.day), status=404)
 
     # not enough permissions
     agenda2.view_role = manager_user.groups.all()[0]
     agenda2.save()
     app.reset()
     app = login(app, username='manager', password='manager')
-    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (
-        agenda.id, date.year, date.month, date.day), status=403)
+    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (agenda.id, date.year, date.month, date.day), status=403)
 
     # just enough permissions
     agenda.view_role = manager_user.groups.all()[0]
     agenda.save()
-    resp = app.get('/manage/agendas/%s/%d/%d/%d/' % (
-        agenda.id, date.year, date.month, date.day), status=200)
+    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')
@@ -1498,9 +1570,9 @@ 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 +1580,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 +1593,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,20 +1609,20 @@ 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
     first_month_day = today.replace(day=1)
-    last_month_day = today.replace(day=1, month=today.month+1) - datetime.timedelta(days=1)
+    last_month_day = today.replace(day=1, month=today.month + 1) - datetime.timedelta(days=1)
     start_week_number = first_month_day.isocalendar()[1]
     end_week_number = last_month_day.isocalendar()[1]
     weeks_number = end_week_number - start_week_number + 1
@@ -1564,19 +1638,17 @@ 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
+    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
     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()
@@ -1613,6 +1685,7 @@ def test_agenda_month_view(app, admin_user, manager_user, api_user):
     resp = app.get('/manage/agendas/%s/%s/%s/' % (agenda.id, today.year, today.month))
     assert not 'No opening hours this month.' 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')
     desk = Desk.objects.create(agenda=agenda, label='Desk A')
@@ -1621,9 +1694,9 @@ 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'):
@@ -1658,6 +1731,7 @@ def test_import_agenda_as_manager(app, manager_user):
     resp = app.get('/manage/', status=200)
     resp = app.get('/manage/agendas/import/', status=403)
 
+
 def test_import_agenda(app, admin_user):
     agenda = Agenda(label=u'Foo bar')
     agenda.save()
-- 
2.20.1

