Example #1
0
    def test_multiple_leaders(self):
        """ 1 unapproved membership, 3 leaders -> only 1 email """

        pre_gp = models.GivingProject.objects.get(title='Pre training')
        member = models.Member.objects.create_with_user(email='*****@*****.**',
                                                        first_name='Ab',
                                                        last_name='Cd')
        member.save()
        membership = models.Membership(giving_project=pre_gp, member=member)
        membership.save(skip=True)

        member = models.Member.objects.create_with_user(
            email='*****@*****.**', first_name='Leader', last_name='')
        member.save()
        membership = models.Membership(giving_project=pre_gp,
                                       member=member,
                                       approved=True,
                                       leader=True)
        membership.save(skip=True)

        member = models.Member.objects.create_with_user(
            email='*****@*****.**', first_name='Three', last_name='Tre')
        member.save()
        membership = models.Membership(giving_project=pre_gp,
                                       member=member,
                                       approved=True,
                                       leader=True)
        membership.save(skip=True)

        response = self.client.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 1)
Example #2
0
    def test_multiple(self):
        """ 3 unapproved memberships in 2 GPs -> only 2 emails sent """

        pre_gp = models.GivingProject.objects.get(title='Pre training')
        member = models.Member.objects.create_with_user(email='*****@*****.**',
                                                        first_name='Ab',
                                                        last_name='Cd')
        member.save()
        membership = models.Membership(giving_project=pre_gp, member=member)
        membership.save(skip=True)

        member = models.Member.objects.create_with_user(
            email='*****@*****.**', first_name='Second', last_name='')
        member.save()
        membership = models.Membership(giving_project=pre_gp, member=member)
        membership.save(skip=True)

        post_gp = models.GivingProject.objects.get(title='Post training')
        member = models.Member.objects.create_with_user(
            email='*****@*****.**', first_name='Three', last_name='Tre')
        member.save()
        membership = models.Membership(giving_project=post_gp, member=member)
        membership.save(skip=True)

        response = self.client.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 2)
Example #3
0
    def setUp(self):
        super(OverdueEmails, self).setUp()
        self.login_as_member('new')

        # create 2 donors on new member's pre membership
        donor = models.Donor(firstname='En', membership_id=self.pre_id)
        donor.save()
        self.donor1 = donor.pk
        donor = models.Donor(firstname='Tva', membership_id=self.pre_id)
        donor.save()
        self.donor2 = donor.pk

        # create another member, membership, donor
        member = models.Member.objects.create_with_user(email='*****@*****.**',
                                                        first_name='Two',
                                                        last_name='Dos')
        member.save()
        gp = models.GivingProject.objects.get(title='Post training')
        membership = models.Membership(giving_project=gp,
                                       member=member,
                                       approved=True)
        membership.save()
        donor = models.Donor(firstname='Tre', membership=membership)
        donor.save()
        self.donor3 = donor.pk
Example #4
0
    def test_repeat(self):

        pre_gp = models.GivingProject.objects.get(title='Pre training')
        member = models.Member.objects.create_with_user(email='*****@*****.**',
                                                        first_name='Ab',
                                                        last_name='Cd')
        member.save()
        membership = models.Membership(giving_project=pre_gp, member=member)
        membership.save(skip=True)

        response = self.client.get(self.url, follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 1)

        # will send another email if membership has still not been approved
        response = self.client.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 2)

        # will not send another after approval
        membership.approved = True
        membership.save()
        self.assertEqual(len(mail.outbox), 3)  # approval email

        response = self.client.get(self.url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 3)  # no additional email to leaders
Example #5
0
    def test_gift_notifications(self):
        # enter gift received from donor
        test_donor = models.Donor.objects.get(pk=self.donor_id)
        test_donor.received_this = 100
        test_donor.save()

        member = models.Member.objects.create_with_user(email='*****@*****.**',
                                                        password='******',
                                                        first_name='A',
                                                        last_name='B')
        membership = models.Membership(member=member, giving_project_id=1)
        membership.save()
        donor = models.Donor(membership=membership,
                             firstname='Greta',
                             lastname='Polkis',
                             received_next=55)
        donor.save()

        # run cron task
        response = self.client.get(self.cron_url, follow=True)
        self.assertEqual(response.status_code, 200)

        # verify notification shows
        response = self.client.get(self.url, follow=True)

        self.assertTemplateUsed(response, 'fund/home.html')
        self.assertContains(response, 'gift or pledge received')
        self.assertContains(response, unicode(test_donor))

        # verify notification doesn't show on reload
        response = self.client.get(self.url, follow=True)

        self.assertTemplateUsed(response, 'fund/home.html')
        self.assertNotContains(response, 'gift or pledge received')

        # verify emails sent
        self.assertEqual(len(mail.outbox), 2)
        testacct_emailed = False
        abcd_emailed = False
        for email in mail.outbox:
            self.assertIn('gift or pledge received', email.body)
            if email.to == [member.user.username]:
                self.assertFalse(abcd_emailed)
                self.assertIn(unicode(donor), email.body)
                self.assertNotIn(unicode(test_donor), email.body)
                abcd_emailed = True
            elif email.to == [self.email]:
                self.assertFalse(testacct_emailed)
                self.assertIn(unicode(test_donor), email.body)
                self.assertNotIn(unicode(donor), email.body)
                testacct_emailed = True
            else:
                self.fail(
                    'Unexpected gift notification email recipient: {}'.format(
                        email.to))

        self.assertTrue(abcd_emailed)
        self.assertTrue(testacct_emailed)
Example #6
0
    def setup_member(self, member):
        self.member_id = member.pk

        post_gp = models.GivingProject.objects.get(title="Post training")
        post_ship = models.Membership(giving_project=post_gp,
                                      member=member,
                                      approved=True)
        post_ship.save()

        if member.first_name == 'current':
            self.ship_id = post_ship.pk
            member.current = post_ship.pk
            member.save()

            # create donor & step
            donor = models.Donor(membership=post_ship,
                                 firstname='Anna',
                                 amount=500,
                                 talked=True,
                                 likelihood=50)
            donor.save()
            step = models.Step(donor=donor,
                               description='Talk to about project',
                               created=timezone.now(),
                               date='2013-04-06')
            step.save()
            self.donor_id = donor.pk
            self.step_id = step.pk

        elif member.first_name == 'new':
            self.post_id = post_ship.pk

            pre_gp = models.GivingProject.objects.get(title='Pre training')
            pre_ship = models.Membership(giving_project=pre_gp,
                                         member=member,
                                         approved=True)
            pre_ship.save()
            self.pre_id = self.ship_id = pre_ship.pk

            member.current = pre_ship.pk
            member.save()

        else:
            raise Exception('setup_member got unexpected name: {}'.format(
                member.first_name))
Example #7
0
    def setUp(self):
        super(CopyContacts, self).setUp()
        self.login_as_member('first')

        # create a new empty membership and set as member.current
        pre = models.GivingProject.objects.get(title='Pre training')
        membership = models.Membership(giving_project=pre,
                                       member_id=self.member_id,
                                       approved=True)
        membership.save()
        self.membership = membership
        member = models.Member.objects.get(pk=self.member_id)
        member.current = membership.pk
        member.save()
Example #8
0
    def test_one(self):

        pre_gp = models.GivingProject.objects.get(title='Pre training')
        member = models.Member.objects.create_with_user(email='*****@*****.**',
                                                        first_name='Ab',
                                                        last_name='Cd')
        member.save()
        membership = models.Membership(giving_project=pre_gp, member=member)
        membership.save(skip=True)

        response = self.client.get(self.url, follow=True)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(mail.outbox), 1)
Example #9
0
    def test_already_exists(self):
        gp = models.GivingProject.objects.get(title='Pre training')
        member = models.Member.objects.create_with_user(email=TEST_EMAIL,
                                                        first_name='A',
                                                        last_name='P')
        member.save()
        existing_ship = models.Membership(member=member, giving_project=gp)
        existing_ship.save()

        membership, error = _create_membership(member, gp)

        self.assertRegexpMatches(error, 'already registered')
        self.assertEqual(membership,
                         existing_ship,
                         msg='Returns the pre-existing membership')
Example #10
0
    def test_grants_display(self):
        """ Verify that assigned grants are shown on grants page """

        ship = models.Membership(giving_project_id=16,
                                 member_id=self.member_id,
                                 approved=True)
        ship.save()
        models.Member.objects.filter(pk=self.member_id).update(current=ship.pk)

        response = self.client.get(self.url)

        papps = (ProjectApp.objects.filter(
            giving_project_id=16).select_related('application',
                                                 'application__organization'))
        self.assertNotEqual(papps.count(), 0)
        for papp in papps:
            if papp.application.pre_screening_status == 45:
                self.assertNotContains(response,
                                       unicode(papp.application.organization))
            else:
                self.assertContains(response,
                                    unicode(papp.application.organization))