Ejemplo n.º 1
0
 def test_creating_and_deleting_an_account_does_so_successfully(self):
     from django.contrib.auth.models import User
     a1 = Factory.create_demo_site("test1", quick=True, create_subscription=True)
     a2 = Factory.create_demo_site("test2", quick=True)
     a1.delete()
     time.sleep(5)
     a3 = Factory.create_demo_site("test3", quick=True)
     a3.delete()
     self.assertEqual(Account.objects.all().count(), 1)
     self.assertEqual(User.objects.all().count(), 3)
     a2.delete()
     self.assertEqual(Account.objects.all().count(), 0)
     self.assertEqual(User.objects.all().count(), 0)
Ejemplo n.º 2
0
    def test_num_volunteer_hours(self):
        a = Factory.create_demo_site("test", quick=True)
        hours = 0
        for c in CompletedShift.objects.all():
            hours += c.duration

        self.assertEqual(a.num_volunteer_hours, hours)
Ejemplo n.º 3
0
    def test_deleting_an_account_cancels_its_subscription(self):
        a1 = Factory.create_demo_site("test1", quick=True, create_subscription=True)
        stripe_id = a1.stripe_customer_id
        c = self.stripe.Customer.retrieve(stripe_id)
        assert hasattr(c, "subscription")
        
        a1.delete()

        c = self.stripe.Customer.retrieve(stripe_id)
        assert not hasattr(c, "subscription")
Ejemplo n.º 4
0
    def test_factory_account_can_be_run_multiple_times(self):
        for i in range(0,Factory.rand_int(2,6)):
            Factory.create_demo_site("test%s" % i, quick=True)

        assert True == True # Finished successfully.        
Ejemplo n.º 5
0
 def setUp(self):
     self.signal_kwargs = None
     self.account = Factory.create_demo_site("test1", quick=True, create_subscription=True)
     mail.outbox = []
Ejemplo n.º 6
0
 def test_num_spreadsheets(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.num_spreadsheets, Spreadsheet.objects_by_account(a).count())
Ejemplo n.º 7
0
 def create_demo_site(self, name="test", mostly_empty=False, **kwargs):
     return Factory.create_demo_site(name, quick=True, delete_existing=True,  mostly_empty=mostly_empty, create_subscription=True, **kwargs)
Ejemplo n.º 8
0
def test_donations_by_year_for_non_donors_returns_properly():
    person = Factory.person(Factory.create_demo_site("test1", quick=True, delete_existing=True))
    target = []

    assert person.donor.donations_by_year == target
Ejemplo n.º 9
0
    def test_by_the_numbers_numbers(self):
        # test against hand-counted queries
        from dashboard.views import _account_numbers_dict
        a1 = Factory.create_demo_site("test2", quick=True)

        nums = _account_numbers_dict(a1)

        start_of_this_year = datetime.date(month=1, day=1, year=datetime.date.today().year)
        
        # total_donations
        total_donations_hand_count = 0
        for d in Donation.objects.all():
            if d.account == a1 and d.date >= start_of_this_year:
                total_donations_hand_count += 1
        self.assertEqual(Decimal(nums["total_donations"]), Decimal(total_donations_hand_count))
        

        # total_donors
        total_donors_hand_count = 0
        donors_list = []
        for d in Donation.objects.all():
            if d.account == a1 and d.date >= start_of_this_year:
                if d.donor not in donors_list:
                    total_donors_hand_count += 1
                    donors_list.append(d.donor)
        self.assertEqual(nums["total_donors"], total_donors_hand_count)


        # total donation amount
        total_donation_amount_hand_count = 0
        for d in Donation.objects.all():
            if d.account == a1 and d.date >= start_of_this_year:
                total_donation_amount_hand_count += d.amount

        self.assertEqual(nums["total_donation_amount"], total_donation_amount_hand_count)
        
        # average
        nums_avg = "%f" % nums["average_donation"]
        if total_donations_hand_count == 0:
            calc_avg = "%f" % 0.0
        else:
            calc_avg = "%f" % (total_donation_amount_hand_count/total_donations_hand_count)
        nums_avg = nums_avg[:-2]
        calc_avg = calc_avg[:-2]
        self.assertEqual(nums_avg, calc_avg )   
        
        # total_volunteer_hours
        total_volunteer_hours_hand_count = 0
        for d in CompletedShift.objects.all():
            if d.account == a1 and d.date >= start_of_this_year:
                total_volunteer_hours_hand_count += d.duration

        self.assertEqual(nums["total_volunteer_hours"], total_volunteer_hours_hand_count)

        # total_people
        total_people = 0
        for d in Person.objects.all():
            if d.account == a1:
                total_people += 1

        self.assertEqual(nums["total_people"], total_people)

        # total_orgs
        total_orgs = 0
        for d in Organization.objects.all():
            if d.account == a1:
                total_orgs += 1

        self.assertEqual(nums["total_orgs"], total_orgs)

        # total_groups
        total_groups = 0
        for d in Group.objects.all():
            if d.account == a1:
                total_groups += 1

        for d in TagGroup.objects.all():
            if d.account == a1:
                total_groups += 1
        
        self.assertEqual(nums["total_groups"], total_groups)

        # total_tags 
        total_tags = 0
        for d in Tag.objects.all():
            if d.account == a1:
                total_tags += 1

        self.assertEqual(nums["total_tags"], total_tags)

        # total_taggeditems
        total_taggeditems = 0
        for d in TaggedItem.objects.all():
            if d.account == a1:
                total_taggeditems += 1

        self.assertEqual(nums["total_taggeditems"], total_taggeditems)
Ejemplo n.º 10
0
 def test_avg_donation(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.avg_donation, float(a.total_donations) / a.num_donations_denominator)
Ejemplo n.º 11
0
 def test_total_donations(self):
     a = Factory.create_demo_site("test", quick=True)
     total = 0
     for d in Donation.objects_by_account(a).all():
         total += d.amount
     self.assertEqual(a.total_donations, total)
Ejemplo n.º 12
0
 def test_num_donations_denominator(self):
     a = Factory.create_demo_site("test", quick=True)
     if Donation.objects_by_account(a).count() > 0:
         self.assertEqual(a.num_donations_denominator, Donation.objects_by_account(a).count())
     else:
         self.assertEqual(a.num_donations_denominator,1)
Ejemplo n.º 13
0
 def test_num_donations(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.num_donations, Donation.objects_by_account(a).count())
Ejemplo n.º 14
0
 def test_num_people_denominator(self):
     a = Factory.create_demo_site("test", quick=True)
     if Person.objects_by_account(a).count() > 0:
         self.assertEqual(a.num_people, Person.objects_by_account(a).count())
     else:
         self.assertEqual(a.num_people,1)
Ejemplo n.º 15
0
 def test_num_people(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.num_people, Person.objects_by_account(a).count())
Ejemplo n.º 16
0
 def test_avg_vol_hours_per_person(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.avg_vol_hours_per_person, float(a.num_volunteer_hours) /a.num_people_denominator)
Ejemplo n.º 17
0
 def test_primary_useraccount_chooses_the_right_account(self):
     a1 = Factory.create_demo_site("test1", quick=True)
     admin_accesslevel = AccessLevel.objects.get(name__iexact="Admin")     
     admin_account = UserAccount.objects.get(account=a1, access_level=admin_accesslevel)
     assert a1.primary_useraccount == admin_account
Ejemplo n.º 18
0
 def test_num_taggeditems(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.num_taggeditems, TaggedItem.objects_by_account(a).count())
Ejemplo n.º 19
0
 def setUp(self):
     self.a1 = Factory.create_demo_site("test1", quick=True, mostly_empty=True)
Ejemplo n.º 20
0
 def test_avg_tags_per_person(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.avg_tags_per_person, float(a.num_taggeditems) / a.num_people_denominator)
Ejemplo n.º 21
0
 def setUp(self):
     self.a1 = Factory.create_demo_site("test1", quick=True)
     self.factory = RequestFactory()
Ejemplo n.º 22
0
 def test_num_groups(self):
     a = Factory.create_demo_site("test", quick=True)
     self.assertEqual(a.num_groups, Group.objects_by_account(a).count())
Ejemplo n.º 23
0
 def setUp(self):
     self.a1 = Factory.create_demo_site("test1", verbose=False, quick=True)
     self.a2 = Factory.create_demo_site("test2", with_demo_flag=False, verbose=False, quick=True)
Ejemplo n.º 24
0
 def setUp(self):
     self.a1 = Factory.create_demo_site("test1", quick=True)
     pass