Esempio n. 1
0
    def test_member_realized_mail_with_survey(self):
        survey = SurveyFactory(link='https://example.com/survey/1/', active=True)

        task_member = TaskMemberFactory.create(
            task=self.task,
            status='accepted'
        )

        task_member.status = 'realized'
        task_member.save()

        self.assertEquals(len(mail.outbox), 2)

        email = mail.outbox[-1]

        self.assertNotEquals(email.subject.find("realised"), -1)
        self.assertEquals(email.to[0], task_member.member.email)
        self.assertTrue(survey.url(self.task) in email.body)
        self.assertTrue('survey' in email.body)
Esempio n. 2
0
class TestProjectMails(BluebottleTestCase):
    """
    Test the sending of email notifications when a Task' status changes
    """
    def setUp(self):
        super(TestProjectMails, self).setUp()

        self.init_projects()
        self.status_running = ProjectPhase.objects.get(slug='campaign')
        self.complete = ProjectPhase.objects.get(slug='done-complete')
        self.incomplete = ProjectPhase.objects.get(slug='done-incomplete')
        self.project = ProjectFactory.create(status=self.status_running,
                                             organization=None)

    def test_complete(self):
        self.survey = SurveyFactory(link='https://example.com/survey/1/',
                                    active=True)
        self.project.status = self.complete
        self.project.save()

        self.assertEquals(len(mail.outbox), 1)
        email = mail.outbox[0]

        self.assertNotEquals(email.subject.find("has been realised"), -1)

        self.assertTrue(
            self.survey.url(self.project, user_type='initiator') in email.body)
        self.assertTrue('survey' in email.body)

    def test_inactive_survey_complete(self):
        self.survey = SurveyFactory(link='https://example.com/survey/1/',
                                    active=False)
        self.project.status = self.complete
        self.project.save()

        self.assertEquals(len(mail.outbox), 1)
        email = mail.outbox[0]

        self.assertNotEquals(email.subject.find("has been realised"), -1)

        self.assertFalse('survey' in email.body)

    def test_complete_no_celebration(self):
        self.project.celebrate_results = False
        self.project.status = self.complete
        self.project.save()

        self.assertEquals(len(mail.outbox), 1)
        email = mail.outbox[0]

        self.assertNotEquals(email.subject.find("has been realised"), -1)
        self.assertFalse('survey' in email.body)

    def test_complete_with_organization(self):
        self.survey = SurveyFactory(link='https://example.com/survey/1/',
                                    active=True)
        self.project.organization = OrganizationFactory.create(
            email='*****@*****.**')
        self.project.status = self.complete
        self.project.save()

        self.assertEquals(len(mail.outbox), 2)
        initiator_email = mail.outbox[0]
        self.assertEqual(initiator_email.to, [self.project.owner.email])
        self.assertTrue('has been realised' in initiator_email.subject)
        self.assertTrue(
            Survey.url(self.project, user_type='initiator') in
            initiator_email.body)

        organization_email = mail.outbox[1]
        self.assertEqual(organization_email.to,
                         [self.project.organization.email])
        self.assertTrue('has been realised' in organization_email.subject)
        self.assertTrue(
            Survey.url(self.project, user_type='organization') in
            organization_email.body)

    def test_complete_inactive_survey_with_organization(self):
        self.survey = SurveyFactory(link='https://example.com/survey/1/',
                                    active=False)
        self.project.organization = OrganizationFactory.create(
            email='*****@*****.**')
        self.project.status = self.complete
        self.project.save()

        self.assertEquals(len(mail.outbox), 2)
        initiator_email = mail.outbox[0]
        self.assertEqual(initiator_email.to, [self.project.owner.email])
        self.assertTrue('has been realised' in initiator_email.subject)
        self.assertFalse('survey' in initiator_email.body)

        organization_email = mail.outbox[1]
        self.assertEqual(organization_email.to,
                         [self.project.organization.email])
        self.assertTrue('has been realised' in organization_email.subject)
        self.assertFalse('survey' in organization_email.body)

    def test_incomplete(self):
        self.project.status = self.incomplete
        self.project.save()

        self.assertEquals(len(mail.outbox), 1)
        self.assertNotEquals(mail.outbox[0].subject.find("has expired"), -1)

    def test_state_other(self):
        self.project.status = ProjectPhase.objects.get(slug="plan-new")
        self.project.save()

        self.assertEquals(len(mail.outbox), 0)

        self.project.status = ProjectPhase.objects.get(slug="closed")
        self.project.save()

        self.assertEquals(len(mail.outbox), 0)
Esempio n. 3
0
class TestProjectMails(BluebottleTestCase):
    """
    Test the sending of email notifications when a Task' status changes
    """

    def setUp(self):
        super(TestProjectMails, self).setUp()

        self.init_projects()
        self.status_running = ProjectPhase.objects.get(slug='campaign')
        self.complete = ProjectPhase.objects.get(slug='done-complete')
        self.incomplete = ProjectPhase.objects.get(slug='done-incomplete')
        self.project = ProjectFactory.create(status=self.status_running, organization=None)
        self.survey = SurveyFactory(link='https://example.com/survey/1/')

    def test_complete(self):
        self.project.status = self.complete
        self.project.save()

        self.assertEquals(len(mail.outbox), 1)
        email = mail.outbox[0]

        self.assertNotEquals(email.subject.find("has been realised"), -1)

        self.assertTrue(self.survey.url(self.project, user_type='initiator') in email.body)

    def test_complete_no_celebration(self):
        self.project.celebrate_results = False
        self.project.status = self.complete
        self.project.save()

        self.assertEquals(len(mail.outbox), 1)
        email = mail.outbox[0]

        self.assertNotEquals(email.subject.find("has been realised"), -1)
        self.assertFalse('survey' in email.body)

    def test_complete_with_organization(self):
        self.project.organization = OrganizationFactory.create(email='*****@*****.**')
        self.project.status = self.complete
        self.project.save()

        self.assertEquals(len(mail.outbox), 2)
        initiator_email = mail.outbox[0]
        self.assertEqual(initiator_email.to, [self.project.owner.email])
        self.assertTrue('has been realised' in initiator_email.subject)
        self.assertTrue(Survey.url(self.project, user_type='initiator') in initiator_email.body)

        organization_email = mail.outbox[1]
        self.assertEqual(organization_email.to, [self.project.organization.email])
        self.assertTrue('has been realised' in organization_email.subject)
        self.assertTrue(Survey.url(self.project, user_type='organization') in organization_email.body)

    def test_incomplete(self):
        self.project.status = self.incomplete
        self.project.save()

        self.assertEquals(len(mail.outbox), 1)
        self.assertNotEquals(mail.outbox[0].subject.find("has expired"), -1)

    def test_state_other(self):
        self.project.status = ProjectPhase.objects.get(slug="plan-new")
        self.project.save()

        self.assertEquals(len(mail.outbox), 0)

        self.project.status = ProjectPhase.objects.get(slug="closed")
        self.project.save()

        self.assertEquals(len(mail.outbox), 0)