test/campaigntests.py has a BasicGuiTest.testFrontPage, which tests whether the Learn More link will toggle the description panel.
paypal/tests.py: made loginSandbox drop the test parameter and callable from outside of paypal/tests.py -- now, for example, from test/campaigntests.py settings/dev.py: added LIVE_SERVER_TEST_URL, UNGLUEIT_TEST_USER, UNGLUEIT_TEST_PASSWORD -- parameters useful for selenium-based live server testing the beginnings of test/campaigntests.support_campaign() -- a selenium script to drive automated pledging to campaign for testing purposespull/1/head
parent
b1ccf6832b
commit
9199f78606
|
@ -40,7 +40,7 @@ def set_test_logging():
|
|||
sel = logging.getLogger("selenium")
|
||||
sel.setLevel(logging.INFO)
|
||||
|
||||
def loginSandbox(test, selenium):
|
||||
def loginSandbox(selenium):
|
||||
|
||||
print "LOGIN SANDBOX"
|
||||
|
||||
|
@ -159,7 +159,7 @@ class PledgeTest(TestCase):
|
|||
|
||||
self.validateRedirect(t, url, 1)
|
||||
|
||||
loginSandbox(self, self.selenium)
|
||||
loginSandbox(self.selenium)
|
||||
paySandbox(self, self.selenium, url)
|
||||
|
||||
# sleep to make sure the transaction has time to complete
|
||||
|
@ -189,7 +189,7 @@ class PledgeTest(TestCase):
|
|||
|
||||
self.validateRedirect(t, url, 2)
|
||||
|
||||
loginSandbox(self, self.selenium)
|
||||
loginSandbox(self.selenium)
|
||||
paySandbox(self, self.selenium, url)
|
||||
|
||||
# by now we should have received the IPN
|
||||
|
@ -253,7 +253,7 @@ class AuthorizeTest(TestCase):
|
|||
|
||||
self.validateRedirect(t, url)
|
||||
|
||||
loginSandbox(self, self.selenium)
|
||||
loginSandbox(self.selenium)
|
||||
paySandbox(self, self.selenium, url, authorize=True)
|
||||
|
||||
# stick in a getStatus to update statuses in the absence of IPNs
|
||||
|
@ -295,6 +295,33 @@ class TransactionTest(TestCase):
|
|||
self.assertEqual(results[0].amount, D('12.34'))
|
||||
self.assertEqual(c.left,c.target-D('12.34'))
|
||||
|
||||
class BasicGuiTest(TestCase):
|
||||
def setUp(self):
|
||||
self.verificationErrors = []
|
||||
# This is an empty array where we will store any verification errors
|
||||
# we find in our tests
|
||||
|
||||
setup_selenium()
|
||||
self.TEST_SERVER_URL = "http://ry-dev.dyndns.org"
|
||||
self.selenium = webdriver.Firefox()
|
||||
set_test_logging()
|
||||
def testFrontPage(self):
|
||||
sel = self.selenium
|
||||
sel.get(self.TEST_SERVER_URL)
|
||||
# if we click on the learn more, does the panel expand?
|
||||
# click on a id=readon -- or the Learn More span
|
||||
sel.find_elements_by_css_selector('a#readon')[0].click()
|
||||
time.sleep(2.0)
|
||||
# the learn more panel should be displayed
|
||||
self.assertTrue(sel.find_elements_by_css_selector('div#user-block-hide')[0].is_displayed())
|
||||
# click on the panel again -- and panel should not be displayed
|
||||
sel.find_elements_by_css_selector('a#readon')[0].click()
|
||||
time.sleep(2.0)
|
||||
self.assertFalse(sel.find_elements_by_css_selector('div#user-block-hide')[0].is_displayed())
|
||||
def tearDown(self):
|
||||
self.selenium.quit()
|
||||
|
||||
|
||||
def suite():
|
||||
|
||||
#testcases = [PledgeTest, AuthorizeTest, TransactionTest]
|
||||
|
|
|
@ -121,4 +121,14 @@ CELERYD_LOG_LEVEL = "INFO"
|
|||
|
||||
LOCALDATETIME_NOW = None
|
||||
|
||||
# selenium-related testing parameters
|
||||
# in Django 1.4, we'll get a URL for LiveServerTestCase https://docs.djangoproject.com/en/dev/topics/testing/#django.test.LiveServerTestCase
|
||||
# but for now, we would have to manually configure our own test server.
|
||||
LIVE_SERVER_TEST_URL = "http://127.0.0.1:8000"
|
||||
|
||||
# username, password to pass to LIVE_SERVER_TEST_URL
|
||||
|
||||
UNGLUEIT_TEST_USER = None
|
||||
UNGLUEIT_TEST_PASSWORD = None
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,13 @@ from regluit.payment.models import Transaction, PaymentResponse, Receiver
|
|||
from regluit.payment.manager import PaymentManager
|
||||
from regluit.payment.paypal import IPN_PAY_STATUS_ACTIVE, IPN_PAY_STATUS_INCOMPLETE, IPN_PAY_STATUS_COMPLETED
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from selenium import selenium, webdriver
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
import unittest, time, re
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
@ -23,6 +30,34 @@ def set_test_logging():
|
|||
sel.setLevel(logging.INFO)
|
||||
|
||||
|
||||
|
||||
class GoogleWebDriverTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
setup_selenium()
|
||||
self.verificationErrors = []
|
||||
# This is an empty array where we will store any verification errors
|
||||
# we find in our tests
|
||||
|
||||
self.selenium = webdriver.Firefox()
|
||||
set_test_logging()
|
||||
|
||||
def test_google_rc(self):
|
||||
sel = self.selenium
|
||||
sel.get("https://www.google.com/")
|
||||
search_box = sel.find_elements_by_xpath("//input[@type='text']")
|
||||
search_box[0].send_keys("Bach")
|
||||
search_box[0].submit()
|
||||
time.sleep(3)
|
||||
try:
|
||||
sel.find_element_by_xpath("//a[contains(@href,'wikipedia')]")
|
||||
except NoSuchElementException, e:
|
||||
self.verificationErrors.append(str(e))
|
||||
|
||||
def tearDown(self):
|
||||
self.selenium.quit()
|
||||
self.assertEqual([], self.verificationErrors)
|
||||
|
||||
def run_google_rc():
|
||||
"""
|
||||
"""
|
||||
|
@ -57,38 +92,6 @@ def run_google_wd():
|
|||
"""
|
||||
A google example using WebDriver
|
||||
"""
|
||||
|
||||
|
||||
from selenium import selenium, webdriver
|
||||
from selenium.common.exceptions import NoSuchElementException
|
||||
import unittest, time, re
|
||||
|
||||
class GoogleWebDriverTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
setup_selenium()
|
||||
self.verificationErrors = []
|
||||
# This is an empty array where we will store any verification errors
|
||||
# we find in our tests
|
||||
|
||||
self.selenium = webdriver.Firefox()
|
||||
set_test_logging()
|
||||
|
||||
def test_google_rc(self):
|
||||
sel = self.selenium
|
||||
sel.get("https://www.google.com/")
|
||||
search_box = sel.find_elements_by_xpath("//input[@type='text']")
|
||||
search_box[0].send_keys("Bach")
|
||||
search_box[0].submit()
|
||||
time.sleep(3)
|
||||
try:
|
||||
sel.find_element_by_xpath("//a[contains(@href,'wikipedia')]")
|
||||
except NoSuchElementException, e:
|
||||
self.verificationErrors.append(str(e))
|
||||
|
||||
def tearDown(self):
|
||||
self.selenium.quit()
|
||||
self.assertEqual([], self.verificationErrors)
|
||||
|
||||
testcases = [GoogleWebDriverTest]
|
||||
suites = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(testcase) for testcase in testcases])
|
||||
|
@ -99,6 +102,8 @@ def run_google_wd():
|
|||
# driver = webdriver.Remote(desired_capabilities=webdriver.DesiredCapabilities.HTMLUNITWITHJS)
|
||||
# driver.get("http://google.com")
|
||||
|
||||
|
||||
|
||||
pm = PaymentManager()
|
||||
|
||||
def campaign_display():
|
||||
|
@ -146,3 +151,53 @@ def recipient_status(clist):
|
|||
|
||||
# res = [pm.finish_campaign(c) for c in campaigns_incomplete()]
|
||||
|
||||
def support_campaign():
|
||||
"""
|
||||
programatically fire up selenium to make a Pledge
|
||||
"""
|
||||
UNGLUE_IT_URL = settings.LIVE_SERVER_TEST_URL
|
||||
# unglue.it login
|
||||
USER = settings.UNGLUEIT_TEST_USER
|
||||
PASSWORD = settings.UNGLUEIT_TEST_PASSWORD
|
||||
|
||||
# PayPal developer sandbox
|
||||
from regluit.payment.tests import loginSandbox
|
||||
|
||||
setup_selenium()
|
||||
sel = webdriver.Firefox()
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
# find a campaign to pledge to
|
||||
loginSandbox(sel)
|
||||
|
||||
time.sleep(2)
|
||||
print "now opening unglue.it"
|
||||
|
||||
#sel.get("http://www.google.com")
|
||||
sel.get(UNGLUE_IT_URL)
|
||||
|
||||
# long wait because sel is slow after PayPal
|
||||
sign_in_link = WebDriverWait(sel, 100).until(lambda d : d.find_element_by_xpath("//span[contains(text(),'Sign In')]/.."))
|
||||
sign_in_link.click()
|
||||
|
||||
# enter login
|
||||
input_username = WebDriverWait(sel,20).until(lambda d : d.find_element_by_css_selector("input#id_username"))
|
||||
input_username.send_keys(USER)
|
||||
sel.find_element_by_css_selector("input#id_password").send_keys(PASSWORD)
|
||||
sel.find_element_by_css_selector("input[value*='sign in']").click()
|
||||
|
||||
# click on biggest campaign list
|
||||
biggest_campaign_link = WebDriverWait(sel,20).until(lambda d: d.find_element_by_css_selector("a[href*='/campaigns/pledged']"))
|
||||
biggest_campaign_link.click()
|
||||
|
||||
# pull up one of the campaigns to pledge to
|
||||
|
||||
sel.quit()
|
||||
|
||||
|
||||
def suites():
|
||||
testcases = [GoogleWebDriverTest]
|
||||
suites = unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(testcase) for testcase in testcases])
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue