Exemplo n.º 1
0
 def test_inlines(self):
     """Test inlines"""
     fadm = admin.EventAdmin(Event, self.site)
     inline_instances = fadm.get_inline_instances(MockRequest.instance())
     self.assertListEqual(list(map(type, inline_instances)), [
         admin.MailTemplateInline,
         admin.FamilyInvitationInline,
     ])
Exemplo n.º 2
0
 def test_send_mail_without_mail(self):
     """Test what happend when sending an email using a event without mail template"""
     event_without_mail = self.create_event(self.family, name=None)
     fadm = admin.EventAdmin(Event, self.site)
     with patch.object(fadm, "message_user") as message_user_mock:
         fadm.send_mail("Request", [self.event, event_without_mail])
         message_user_mock.assert_called_once_with(
             "Request",
             "The event of the 2018-12-31 has no email template set",
             admin.messages.ERROR)
Exemplo n.º 3
0
 def test_get_fields(self):
     """Test displayed fields"""
     fadm = admin.EventAdmin(Event, self.site)
     expected_fields = [
         'name',
         'date',
     ]
     self.assertListEqual(
         list(fadm.get_form(MockRequest.instance()).base_fields),
         expected_fields)
     self.assertEqual(list(fadm.get_fields(MockRequest.instance())),
                      expected_fields)
     self.assertEqual(
         list(fadm.get_fields(MockRequest.instance(), self.event)),
         expected_fields)
Exemplo n.º 4
0
 def _send_form(self):
     """Mixin function to send email on the formset with cleaned data"""
     path = reverse("admin:invite_event_change",
                    kwargs={"object_id": self.event.pk})
     event_families_id = Event.families.through.objects.values_list(
         "pk", flat=True)
     data = {
         'Event_families-0-event':
         self.event.pk,
         'Event_families-0-family':
         self.family.pk,
         'Event_families-0-id':
         event_families_id.filter(event=self.event,
                                  family=self.family).first(),
         'Event_families-0-send_mail':
         'on',
         'Event_families-1-event':
         self.event.pk,
         'Event_families-1-family':
         self.family2.pk,
         'Event_families-1-id':
         event_families_id.filter(event=self.event,
                                  family=self.family2).first(),
         'Event_families-INITIAL_FORMS':
         '2',
         'Event_families-TOTAL_FORMS':
         '2',
         'mailtemplate-INITIAL_FORMS':
         '0',
         'mailtemplate-TOTAL_FORMS':
         '0',
     }
     request_mock = Mock(user=MockSuperUser(),
                         POST=data,
                         GET={},
                         method="POST",
                         path=path,
                         current_app="invite",
                         COOKIES={"csrftoken": "mocked"},
                         META={
                             "csrftoken": "mocked",
                             "SCRIPT_NAME": ""
                         })
     fadm = admin.EventAdmin(Event, self.site)
     with patch.object(fadm, "log_change"):
         fadm.changeform_view(request_mock, str(self.event.pk), path)
Exemplo n.º 5
0
 def test_get_list_display(self):
     """Test displayed fields"""
     fadm = admin.EventAdmin(Event, self.site)
     self.assertListEqual(
         list(fadm.get_list_display(MockRequest.instance())), ["__str__"])