From 744693f178c7df2de58906f0254e51cd10d7693a Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 19 Mar 2012 11:46:41 -0700 Subject: [PATCH] 1) Fix an error in which I wasn't checking properly that the pledge_complete page should allow only the pledging user to see the results. 2) Now tests.campaigntest.support_campaign takes us all the way through pledging for the first campaign --- frontend/views.py | 6 +++++- payment/tests.py | 16 +++++++++------- test/campaigntest.py | 9 +++++++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/frontend/views.py b/frontend/views.py index dfb6ad3f..3e2ad726 100755 --- a/frontend/views.py +++ b/frontend/views.py @@ -467,8 +467,12 @@ should briefly note next steps (e.g. if this campaign succeeds you will be email try: if user.id == transaction.user.id: correct_user = True + else: + # should be 403 -- but let's try 404 for now -- 403 exception coming in Django 1.4 + raise Http404 except Exception, e: - pass + raise Http404 + # check that the user had not already approved the transaction # do we need to first run PreapprovalDetails to check on the status diff --git a/payment/tests.py b/payment/tests.py index da9cb6e0..907b4db1 100644 --- a/payment/tests.py +++ b/payment/tests.py @@ -60,7 +60,8 @@ def loginSandbox(selenium): except: traceback.print_exc() -def paySandbox(test, selenium, url, authorize=False): +def paySandbox(test, selenium, url, authorize=False, already_at_url=False, sleep_time=20): + if authorize: print "AUTHORIZE SANDBOX" @@ -69,10 +70,11 @@ def paySandbox(test, selenium, url, authorize=False): try: # We need this sleep to make sure the JS engine is finished from the sandbox loging page - time.sleep(20) + time.sleep(sleep_time) - selenium.get(url) - print "Opened URL %s" % url + if not already_at_url: + selenium.get(url) + print "Opened URL %s" % url try: # Button is only visible if the login box is NOT open @@ -82,7 +84,7 @@ def paySandbox(test, selenium, url, authorize=False): # This sleep is needed for js to slide the buyer login into view. The elements are always in the DOM # so selenium can find them, but we need them in view to interact - time.sleep(20) + time.sleep(sleep_time) except: print "Ready for Login" @@ -98,13 +100,13 @@ def paySandbox(test, selenium, url, authorize=False): submit_button.click() # This sleep makes sure js has time to animate out the next page - time.sleep(20) + time.sleep(sleep_time) final_submit = WebDriverWait(selenium, 60).until(lambda d : d.find_element_by_id("submit.x")) final_submit.click() # This makes sure the processing of the final submit is complete - time.sleep(20) + time.sleep(sleep_time) # Don't wait too long for this, it isn't really needed. By the time JS has gotten around to # displaying this element, the redirect has usually occured diff --git a/test/campaigntest.py b/test/campaigntest.py index 77ed271d..8077909f 100644 --- a/test/campaigntest.py +++ b/test/campaigntest.py @@ -161,12 +161,12 @@ def support_campaign(): PASSWORD = settings.UNGLUEIT_TEST_PASSWORD # PayPal developer sandbox - from regluit.payment.tests import loginSandbox + from regluit.payment.tests import loginSandbox, paySandbox setup_selenium() # we can experiment with different webdrivers - # sel = webdriver.Firefox() + #sel = webdriver.Firefox() # Chrome sel = webdriver.Chrome(executable_path='/Users/raymondyee/C/src/Gluejar/regluit/test/chromedriver') @@ -224,6 +224,11 @@ def support_campaign(): pledge_button = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("input[value*='Pledge']")) pledge_button.click() + # grab the URL where sel is now? + + print "Now trying to pay PayPal", sel.current_url + paySandbox(None, sel, sel.current_url, authorize=True, already_at_url=True, sleep_time=5) + #sel.quit()