def test_all_recipients(self):
        # totally fake Event and SelfOrganisedSubmission
        e = Event.objects.create(
            slug="test-event",
            host=Organization.objects.first(),
            administrator=Organization.objects.get(domain="self-organized"),
            start=date.today() + timedelta(days=7),
            end=date.today() + timedelta(days=8),
            country="GB",
        )
        e.tags.set(Tag.objects.filter(name__in=["LC", "Circuits", "automated-email"]))
        r = SelfOrganisedSubmission.objects.create(
            state="p",
            personal="Harry",
            family="Potter",
            email="*****@*****.**",
            institution_other_name="Hogwarts",
            workshop_url="",
            workshop_format="",
            workshop_format_other="",
            workshop_types_other_explain="",
            language=Language.objects.get(name="English"),
            event=e,
            additional_contact=TAG_SEPARATOR.join(["*****@*****.**", "*****@*****.**"]),
        )
        r.workshop_types.set(Curriculum.objects.filter(carpentry="LC"))

        a = SelfOrganisedRequestAction(
            trigger=Trigger(action="test-action", template=EmailTemplate()),
            objects=dict(event=e, request=r),
        )

        self.assertEqual(
            a.all_recipients(), "[email protected], [email protected], [email protected]"
        )
Пример #2
0
    def test_drop_empty_contacts(self):
        e = Event.objects.create(
            slug="test-event",
            host=Organization.objects.first(),
            administrator=Organization.objects.get(domain="self-organized"),
            start=date.today() + timedelta(days=7),
            end=date.today() + timedelta(days=8),
            country="GB",
            contact="*****@*****.**",  # this won't be picked up
        )
        e.tags.set(
            Tag.objects.filter(name__in=["LC", "Circuits", "automated-email"]))
        r = SelfOrganisedSubmission.objects.create(
            state="p",
            personal="Harry",
            family="Potter",
            email="",
            institution_other_name="Hogwarts",
            workshop_url="",
            workshop_format="",
            workshop_format_other="",
            workshop_types_other_explain="",
            language=Language.objects.get(name="English"),
            event=e,
            additional_contact=TAG_SEPARATOR,
        )
        r.workshop_types.set(Curriculum.objects.filter(carpentry="LC"))

        a = SelfOrganisedRequestAction(
            trigger=Trigger(action="test-action", template=EmailTemplate()),
            objects=dict(event=e, request=r),
        )

        self.assertEqual(a.all_recipients(), "")
        self.assertEqual(
            a.get_additional_context(dict(event=e, request=r))["all_emails"],
            [])