Пример #1
0
    def testContext(self):
        """Make sure `get_additional_context` works correctly."""
        a = SelfOrganisedRequestAction(
            trigger=Trigger(action="test-action", template=EmailTemplate()))

        # method fails when obligatory objects are missing
        with self.assertRaises(KeyError):
            a.get_additional_context(dict())  # missing 'event' and 'request'
        with self.assertRaises(AttributeError):
            # now both objects are present, but the method tries to execute
            # `refresh_from_db` on them
            a.get_additional_context(dict(event="dummy", request="dummy"))

        # 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"))

        ctx = a.get_additional_context(objects=dict(event=e, request=r))
        self.maxDiff = None
        self.assertEqual(
            ctx,
            dict(
                workshop=e,
                request=r,
                workshop_main_type="LC",
                dates=e.human_readable_date,
                host=Organization.objects.first(),
                regional_coordinator_email=["*****@*****.**"],
                short_notice=True,
                all_emails=[
                    "*****@*****.**", "*****@*****.**", "*****@*****.**"
                ],
                assignee="Regional Coordinator",
                tags=["automated-email", "Circuits", "LC"],
            ),
        )
Пример #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"],
            [])