def test_validates_and_saves_input(self):
        self.user = UserFactory()
        data = {
            'title': 'Foo',
            'venue': 'Bar',
            'start': timezone.now(),
            'end': timezone.now() + timezone.timedelta(days=11),
        }
        form = EventForm(data=data, created_by=self.user)
        self.assertTrue(form.is_valid())
        instance = form.save()
        self.assertEqual(Event.objects.all().count(), 1)

        # Test update
        data.update({'street': 'Foostreet'})
        form = EventForm(data=data, instance=instance, created_by=self.user)
        instance = form.save()
        self.assertEqual(instance.street, 'Foostreet')

        # Test creating an event from a template
        form = EventForm(data=data, instance=instance, created_by=self.user,
                         create_from_template=True)
        self.assertTrue(form.is_valid())
        instance = form.save()
        self.assertEqual(Event.objects.all().count(), 2)

        # Test saving a template
        data.update({'template_name': 'Foo'})
        form = EventForm(data=data, created_by=self.user)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(
            Event.objects.exclude(template_name__exact='').count(), 1)

        # Test updating a template
        data.update({'street': 'Barstreet'})
        instance = Event.objects.get(template_name='Foo')
        form = EventForm(data=data, instance=instance, created_by=self.user)
        self.assertTrue(form.is_valid())
        instance = form.save()
        self.assertEqual(instance.street, 'Barstreet')