comparison donations/tests.py @ 619:00c14431e911

Created a donations side block for BB issue 21.
author Brian Neal <bgneal@gmail.com>
date Wed, 26 Sep 2012 19:33:26 -0500
parents ee87ea74d46b
children 85880b0df024
comparison
equal deleted inserted replaced
618:8c901a03b2e3 619:00c14431e911
6 import datetime 6 import datetime
7 7
8 from django.contrib.auth.models import User 8 from django.contrib.auth.models import User
9 from django.test import TestCase 9 from django.test import TestCase
10 from django.core.urlresolvers import reverse 10 from django.core.urlresolvers import reverse
11 from django.conf import settings
11 12
12 from donations.models import Donation 13 from donations.models import Donation
13 import bio.badges 14 import bio.badges
14 15
15 16
25 # Data from a user that wanted to remain anonymous 26 # Data from a user that wanted to remain anonymous
26 TEST_POST_DATA_2 = """\ 27 TEST_POST_DATA_2 = """\
27 mc_gross=100.00&protection_eligibility=Ineligible&payer_id=FAKEPAYERID02&tax=0.00&payment_date=05:40:33 Jan 16, 2011 PST&payment_status=Completed&charset=windows-1252&first_name=John&option_selection1=No&mc_fee=3.20&notify_version=3.0&custom=test_user&payer_status=unverified&business=brian@surfguitar101.com&quantity=1&verify_sign=AIkKNFAKE-DATA-NOT-REALpqCSxA-E7Tm4rMGlUpNy6ym0.exBzfiyI&payer_email=test_user@example.com&option_name1=List your name?&txn_id=TESTTXNIDK548343A&payment_type=instant&last_name=Doe&receiver_email=brian@surfguitar101.com&payment_fee=3.20&receiver_id=FAKERECEIVERU&txn_type=web_accept&item_name=Donation for www.surfguitar101.com&mc_currency=USD&item_number=501&residence_country=US&handling_amount=0.00&transaction_subject=test_user&payment_gross=100.00&shipping=0.00""" 28 mc_gross=100.00&protection_eligibility=Ineligible&payer_id=FAKEPAYERID02&tax=0.00&payment_date=05:40:33 Jan 16, 2011 PST&payment_status=Completed&charset=windows-1252&first_name=John&option_selection1=No&mc_fee=3.20&notify_version=3.0&custom=test_user&payer_status=unverified&business=brian@surfguitar101.com&quantity=1&verify_sign=AIkKNFAKE-DATA-NOT-REALpqCSxA-E7Tm4rMGlUpNy6ym0.exBzfiyI&payer_email=test_user@example.com&option_name1=List your name?&txn_id=TESTTXNIDK548343A&payment_type=instant&last_name=Doe&receiver_email=brian@surfguitar101.com&payment_fee=3.20&receiver_id=FAKERECEIVERU&txn_type=web_accept&item_name=Donation for www.surfguitar101.com&mc_currency=USD&item_number=501&residence_country=US&handling_amount=0.00&transaction_subject=test_user&payment_gross=100.00&shipping=0.00"""
28 29
29 30
30 class DonationsTest(TestCase): 31 class DonationsIpnTestCase(TestCase):
31 fixtures = ['badges'] 32 fixtures = ['badges']
32 33
33 def test_ipn_post_1(self): 34 def test_ipn_post_1(self):
34 """ 35 """
35 Test a simulated IPN post 36 Test a simulated IPN post
106 datetime.datetime(2011, 1, 16, 5, 40, 33)) 107 datetime.datetime(2011, 1, 16, 5, 40, 33))
107 108
108 # user should not have got a badge for donating 109 # user should not have got a badge for donating
109 p = user.get_profile() 110 p = user.get_profile()
110 self.assertEqual(p.badges.count(), 0) 111 self.assertEqual(p.badges.count(), 0)
112
113
114 class DonationsManagerTestCase(TestCase):
115 fixtures = ['donations_test']
116
117 def test_monthly_goal_pct(self):
118
119 self.assertEqual(settings.DONATIONS_GOAL, Decimal('100.00'))
120 pct = Donation.objects.monthly_goal_pct(year=2012, month=9)
121 self.assertEqual(pct, 23)
122
123 def test_monthly_goal_pct2(self):
124
125 # Ensure we get 0 when there are no records
126
127 Donation.objects.all().delete()
128 pct = Donation.objects.monthly_goal_pct(year=2012, month=9)
129 self.assertEqual(pct, 0)
130
131 def test_monthly_stats(self):
132
133 gross, net, donations = Donation.objects.monthly_stats(year=2012, month=9)
134 self.assertEqual(gross, Decimal('25.00'))
135 self.assertEqual(net, Decimal('23.47'))
136 self.assertEqual(len(donations), 2)
137
138 def test_monthly_stats2(self):
139
140 # Ensure we get 0 when there are no records
141
142 Donation.objects.all().delete()
143
144 gross, net, donations = Donation.objects.monthly_stats(year=2012, month=9)
145 self.assertEqual(gross, Decimal('0.00'))
146 self.assertEqual(net, Decimal('0.00'))
147 self.assertEqual(len(donations), 0)