def testRecipients(self):
     template = EmailTemplate.objects.create(
         slug="sample-template",
         subject="Welcome to {{ site.name }}",
         to_header="{{ request.email }}",
         from_header="*****@*****.**",
         cc_header="*****@*****.**",
         bcc_header="*****@*****.**",
         reply_to_header="{{ reply_to }}",
         body_template="Sample text.",
     )
     trigger = Trigger.objects.create(
         action="workshop-request-response1",
         template=template,
     )
     wr = WorkshopRequest(email="*****@*****.**")
     event = Event.objects.create(
         slug="test-event1",
         host=Organization.objects.first(),
         start=datetime(2020, 10, 30),
         end=datetime(2020, 11, 1),
     )
     event.tags.set([Tag.objects.get(name="SWC")])
     a = GenericAction(trigger=trigger,
                       objects=dict(request=wr, event=event))
     email = a._email()
     self.assertEqual(email.to, ["*****@*****.**"])
    def test_all_recipients(self):
        wr = WorkshopRequest(email="*****@*****.**")
        e = Event.objects.create(
            slug="test-event1",
            host=Organization.objects.first(),
            start=datetime(2020, 10, 30),
            end=datetime(2020, 11, 1),
            country="GB",
            venue="Ministry of Magic",
        )
        e.tags.set(Tag.objects.filter(name="LC"))
        Task.objects.bulk_create([
            Task(event=e, person=self.person1, role=self.instructor_role),
            Task(event=e, person=self.person2, role=self.instructor_role),
        ])

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

        self.assertEqual(
            a.all_recipients(),
            "*****@*****.**",
        )
 def test_event_slug(self):
     wr = WorkshopRequest(email="*****@*****.**")
     event = Event.objects.create(
         slug="test-event1",
         host=Organization.objects.first(),
         start=datetime(2020, 10, 30),
         end=datetime(2020, 11, 1),
     )
     a = GenericAction(
         trigger=Trigger(action="test-action", template=EmailTemplate()),
         objects=dict(request=wr, event=event),
     )
     self.assertEqual(a.event_slug(), "test-event1")
    def testContext(self):
        a = GenericAction(
            trigger=Trigger(action="test-action", template=EmailTemplate()))
        with self.assertRaises(KeyError):
            a.get_additional_context(dict())  # missing 'request' object
        with self.assertRaises(AttributeError):
            # impossible to access `assigned_to` on a string
            a.get_additional_context(dict(request="dummy"))
        with self.assertRaises(AttributeError):
            # impossible to access `refresh_from_db` on a string
            a.get_additional_context(dict(request="dummy", event="dummy"))

        wr = WorkshopRequest()
        ctx = a.get_additional_context(dict(request=wr))
        self.assertEqual(ctx, {
            "request": wr,
            "assignee": "Regional Coordinator"
        })

        event = Event.objects.create(
            slug="test-event1",
            host=Organization.objects.first(),
            start=datetime(2020, 10, 30),
            end=datetime(2020, 11, 1),
        )
        event.tags.set([Tag.objects.get(name="SWC")])
        ctx = a.get_additional_context(dict(request=wr, event=event))
        self.assertEqual(
            ctx,
            {
                "request": wr,
                "workshop": event,
                "workshop_main_type": "SWC",
                "dates": "Oct 30 - Nov 01, 2020",
                "workshop_host": Organization.objects.first(),
                "regional_coordinator_email": ["*****@*****.**"],
                "all_emails": [],
                "assignee": "Regional Coordinator",
                "tags": ["SWC"],
            },
        )
 def testCheckConditions(self):
     e = Event(slug="test-event1", host=Organization.objects.first())
     with self.assertRaises(NotImplementedError):
         GenericAction.check(e)
 def testLaunchAt(self):
     a1 = GenericAction(trigger=Trigger(action="test-action",
                                        template=EmailTemplate()), )
     self.assertEqual(a1.get_launch_at(), timedelta(hours=1))