Merge branch 'jkace' of github.com:Gluejar/regluit into fps

Also fixed things so that regluit.test.campaigntest.support_campaign runs for Amazon without error -- though I still need to confirm that the status of transactions properly handled
Next up:  see whether this works for PayPal too.

Conflicts:
	frontend/views.py
pull/1/head
Raymond Yee 2012-04-25 13:10:53 -07:00
commit 061f656e63
3 changed files with 42 additions and 40 deletions

View File

@ -49,7 +49,8 @@ from regluit.frontend.forms import EbookForm, CustomPremiumForm, EditManagersFor
from regluit.payment.manager import PaymentManager
from regluit.payment.models import Transaction
from regluit.payment.parameters import TARGET_TYPE_CAMPAIGN, TARGET_TYPE_DONATION, PAYMENT_TYPE_AUTHORIZATION
from regluit.payment.paypal import Preapproval, IPN_PAY_STATUS_NONE, IPN_PREAPPROVAL_STATUS_ACTIVE, IPN_PAY_STATUS_INCOMPLETE, IPN_PAY_STATUS_COMPLETED, IPN_PREAPPROVAL_STATUS_CANCELED, IPN_TYPE_PREAPPROVAL
from regluit.payment.parameters import TRANSACTION_STATUS_ACTIVE, TRANSACTION_STATUS_COMPLETE_PRIMARY, TRANSACTION_STATUS_CANCELED, TRANSACTION_STATUS_ERROR, TRANSACTION_STATUS_FAILED
from regluit.payment.paypal import Preapproval
from regluit.core import goodreads
from tastypie.models import ApiKey
from regluit.payment.models import Transaction
@ -500,14 +501,11 @@ class PledgeModifyView(FormView):
# which combination of campaign and transaction status required?
# Campaign must be ACTIVE
assert campaign.status == 'ACTIVE'
# PayPal
#transactions = campaign.transactions().filter(user=user, status=IPN_PREAPPROVAL_STATUS_ACTIVE)
# Amazon
transactions = campaign.transactions().filter(user=user, status=IPN_PREAPPROVAL_STATUS_ACTIVE)
transactions = campaign.transactions().filter(user=user, status=TRANSACTION_STATUS_ACTIVE)
assert transactions.count() == 1
transaction = transactions[0]
assert transaction.type == PAYMENT_TYPE_AUTHORIZATION and transaction.status == IPN_PREAPPROVAL_STATUS_ACTIVE
assert transaction.type == PAYMENT_TYPE_AUTHORIZATION and transaction.status == TRANSACTION_STATUS_ACTIVE
except Exception, e:
raise e
@ -570,10 +568,10 @@ class PledgeModifyView(FormView):
except models.Premium.DoesNotExist, e:
premium = None
transactions = campaign.transactions().filter(user=user, status=IPN_PREAPPROVAL_STATUS_ACTIVE)
transactions = campaign.transactions().filter(user=user, status=TRANSACTION_STATUS_ACTIVE)
assert transactions.count() == 1
transaction = transactions[0]
assert transaction.type == PAYMENT_TYPE_AUTHORIZATION and transaction.status == IPN_PREAPPROVAL_STATUS_ACTIVE
assert transaction.type == PAYMENT_TYPE_AUTHORIZATION and transaction.status == TRANSACTION_STATUS_ACTIVE
p = PaymentManager(embedded=self.embedded)
status, url = p.modify_transaction(transaction=transaction, amount=preapproval_amount, premium=premium)
@ -889,22 +887,21 @@ def campaign_admin(request):
# pull out Campaigns with Transactions that are ACTIVE -- and hence can be executed
# Campaign.objects.filter(transaction__status='ACTIVE')
campaigns_with_active_transactions = models.Campaign.objects.filter(transaction__status=IPN_PREAPPROVAL_STATUS_ACTIVE)
campaigns_with_active_transactions = models.Campaign.objects.filter(transaction__status=TRANSACTION_STATUS_ACTIVE)
# pull out Campaigns with Transactions that are INCOMPLETE
campaigns_with_incomplete_transactions = models.Campaign.objects.filter(transaction__status=IPN_PAY_STATUS_INCOMPLETE)
campaigns_with_incomplete_transactions = models.Campaign.objects.filter(transaction__status=TRANSACTION_STATUS_INCOMPLETE)
# show all Campaigns with Transactions that are COMPLETED
campaigns_with_completed_transactions = models.Campaign.objects.filter(transaction__status=IPN_PAY_STATUS_COMPLETED)
campaigns_with_completed_transactions = models.Campaign.objects.filter(transaction__status=TRANSACTION_STATUS_COMPLETE_PRIMARY)
# show Campaigns with Transactions that are CANCELED
campaigns_with_canceled_transactions = models.Campaign.objects.filter(transaction__status=IPN_PREAPPROVAL_STATUS_CANCELED)
campaigns_with_canceled_transactions = models.Campaign.objects.filter(transaction__status=TRANSACTION_STATUS_CANCELED)
return (campaigns_with_active_transactions, campaigns_with_incomplete_transactions, campaigns_with_completed_transactions,
campaigns_with_canceled_transactions)
return (campaigns_with_active_transactions, campaigns_with_incomplete_transactions, campaigns_with_completed_transactions, campaigns_with_canceled_transactions)
form = CampaignAdminForm()
pm = PaymentManager()

View File

@ -123,6 +123,29 @@ def paySandbox(test, selenium, url, authorize=False, already_at_url=False, sleep
print "Tranasction Complete"
def payAmazonSandbox(sel):
login_email = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#ap_email"))
login_email.click()
login_email.clear()
login_email.send_keys('supporter1@raymondyee.net')
login_password = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#ap_password"))
login_password.click()
login_password.clear()
login_password.send_keys('testpw__')
submit_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#signInSubmit"))
submit_button.click()
time.sleep(2)
# sel.find_element_by_css_selector("input[type='image']")
print "looking for credit_card_confirm", sel.current_url
credit_card_confirm = WebDriverWait(sel,20).until(lambda d: d.find_elements_by_css_selector("input[type='image']"))
credit_card_confirm[0].click()
print "looking for payment_confirm", sel.current_url
payment_confirm = WebDriverWait(sel,20).until(lambda d: d.find_elements_by_css_selector("input[type='image']"))
time.sleep(1)
payment_confirm[-1].click()
class PledgeTest(TestCase):
def setUp(self):

View File

@ -166,7 +166,7 @@ def support_campaign(unglue_it_url = settings.LIVE_SERVER_TEST_URL, do_local=Tru
PASSWORD = settings.UNGLUEIT_TEST_PASSWORD
# PayPal developer sandbox
from regluit.payment.tests import loginSandbox, paySandbox
from regluit.payment.tests import loginSandbox, paySandbox, payAmazonSandbox
setup_selenium()
@ -246,27 +246,8 @@ def support_campaign(unglue_it_url = settings.LIVE_SERVER_TEST_URL, do_local=Tru
print "Now trying to pay PayPal", sel.current_url
paySandbox(None, sel, sel.current_url, authorize=True, already_at_url=True, sleep_time=5)
elif backend == 'amazon':
login_email = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#ap_email"))
login_email.click()
login_email.clear()
login_email.send_keys('supporter1@raymondyee.net')
login_password = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#ap_password"))
login_password.click()
login_password.clear()
login_password.send_keys('testpw__')
submit_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#signInSubmit"))
submit_button.click()
time.sleep(2)
# sel.find_element_by_css_selector("input[type='image']")
print "looking for credit_card_confirm", sel.current_url
credit_card_confirm = WebDriverWait(sel,20).until(lambda d: d.find_elements_by_css_selector("input[type='image']"))
credit_card_confirm[0].click()
print "looking for payment_confirm", sel.current_url
payment_confirm = WebDriverWait(sel,20).until(lambda d: d.find_elements_by_css_selector("input[type='image']"))
time.sleep(1)
payment_confirm[-1].click()
payAmazonSandbox(sel)
# should be back on a pledge complete page
print sel.current_url, re.search(r"/pledge/complete",sel.current_url)
@ -295,8 +276,6 @@ def support_campaign(unglue_it_url = settings.LIVE_SERVER_TEST_URL, do_local=Tru
change_pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Modify Pledge']"))
change_pledge_button.click()
yield sel
# enter a new pledge, which is less than the previous amount and therefore doesn't require a new PayPal transaction
print "changing pledge to $5 -- should not need to go to PayPal"
preapproval_amount_input = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input#id_preapproval_amount"))
@ -317,7 +296,10 @@ def support_campaign(unglue_it_url = settings.LIVE_SERVER_TEST_URL, do_local=Tru
preapproval_amount_input.send_keys("25")
pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Modify Pledge']"))
pledge_button.click()
paySandbox(None, sel, sel.current_url, authorize=True, already_at_url=True, sleep_time=5)
if backend == 'paypal':
paySandbox(None, sel, sel.current_url, authorize=True, already_at_url=True, sleep_time=5)
elif backend == 'amazon':
payAmazonSandbox(sel)
# wait a bit to allow PayPal sandbox to be update the status of the Transaction
time.sleep(10)