This commit is not complete but I want to do so as a stepping stone.

pull/1/head
Raymond Yee 2011-10-04 15:12:59 -07:00
parent 021fb51b24
commit 88f9fc6a1d
11 changed files with 272 additions and 26 deletions

2
.gitignore vendored
View File

@ -2,5 +2,5 @@
*.pyc *.pyc
*.log *.log
settings/me.* settings/me.*
payment/local_parameters.*
*.dot *.dot
reports

View File

@ -56,3 +56,13 @@ In Snow Leopard, this may be /usr/local/bin/virtualenvwrapper.sh
Configure Terminal to automatically notice this at startup: Configure Terminal to automatically notice this at startup:
Terminal > Preferences > Settings > Shell Terminal > Preferences > Settings > Shell
Click "run command"; add `source ~/.bashrc` Click "run command"; add `source ~/.bashrc`
Selenium Install
---------------
Download the selenium server:
http://selenium.googlecode.com/files/selenium-server-standalone-2.5.0.jar
Start the selenium server:
'java -jar selenium-server-standalone-2.5.0.jar'

View File

@ -86,7 +86,7 @@ class Wishlist(models.Model):
works = models.ManyToManyField('Work', related_name='wishlists') works = models.ManyToManyField('Work', related_name='wishlists')
class UserProfile(models.Model): class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True) user = models.OneToOneField(User)
tagline = models.CharField(max_length=140, blank=True) tagline = models.CharField(max_length=140, blank=True)
from regluit.core import signals from regluit.core import signals

View File

@ -1,3 +1,4 @@
from regluit.settings.me import *
PAYMENT_TYPE_NONE = 0 PAYMENT_TYPE_NONE = 0
PAYMENT_TYPE_INSTANT = 1 PAYMENT_TYPE_INSTANT = 1
@ -7,22 +8,9 @@ TARGET_TYPE_NONE = 0
TARGET_TYPE_CAMPAIGN = 1 TARGET_TYPE_CAMPAIGN = 1
TARGET_TYPE_LIST = 2 TARGET_TYPE_LIST = 2
PAYPAL_USERNAME = 'jakace_1309677337_biz_api1.gmail.com'
PAYPAL_PASSWORD = '1309677386'
PAYPAL_SIGNATURE = 'A543DNCPfye3PpgUquUAuyfN2wNQAt.h8FJqHIro2U3-Z886XQvIdWSy'
PAYPAL_APPID = 'APP-80W284485P519543T'
PAYPAL_ENDPOINT = 'svcs.sandbox.paypal.com' # sandbox
PAYPAL_PAYMENT_HOST = 'http://www.sandbox.paypal.com' # sandbox
BASE_URL = 'http://76.28.117.198/'
COMPLETE_URL = 'paymentcomplete' COMPLETE_URL = 'paymentcomplete'
CANCEL_URL = 'paymentcancel' CANCEL_URL = 'paymentcancel'
PREAPPROVAL_PERIOD = 365 # days to ask for in a preapproval PREAPPROVAL_PERIOD = 365 # days to ask for in a preapproval
PAYPAL_COMMISSION = 0.10 PAYPAL_COMMISSION = 0.10
try:
from local_parameters import *
except ImportError:
pass

View File

@ -6,11 +6,213 @@ Replace this with more appropriate tests for your application.
""" """
from django.test import TestCase from django.test import TestCase
from regluit.payment.manager import PaymentManager
from regluit.payment.paypal import IPN, IPN_PAY_STATUS_ACTIVE, IPN_PAY_STATUS_COMPLETED, IPN_TXN_STATUS_COMPLETED
from noseselenium.cases import SeleniumTestCaseMixin
from regluit.payment.models import Transaction
from regluit.core.models import Campaign, Wishlist
from django.contrib.auth.models import User
from regluit.payment.parameters import *
import traceback
from django.core.validators import URLValidator
from django.core.exceptions import ValidationError
import time
from selenium import selenium, webdriver
def loginSandbox(test, selenium):
print "LOGIN SANDBOX"
try:
selenium.open('https://developer.paypal.com/')
time.sleep(5)
test.failUnless(selenium.is_text_present('Member Log In'))
selenium.type('login_email', PAYPAL_SANDBOX_LOGIN)
selenium.type('login_password', PAYPAL_SANDBOX_PASSWORD)
time.sleep(2)
selenium.click('css=input[class=\"formBtnOrange\"]')
time.sleep(5)
test.failUnless(selenium.is_text_present('Test Accounts'))
except:
traceback.print_exc()
def authorizeSandbox(test, selenium, url):
print "AUTHORIZE SANDBOX"
try:
selenium.open(url)
time.sleep(5)
test.failUnless(selenium.is_text_present('Your preapproved payment summary'))
selenium.click('loadLogin')
time.sleep(5)
selenium.type('id=login_email', PAYPAL_BUYER_LOGIN)
selenium.type('id=login_password', PAYPAL_BUYER_PASSWORD)
time.sleep(2)
selenium.click('submitLogin')
time.sleep(5)
test.failUnless(selenium.is_text_present('Review your information'))
selenium.click('submit.x')
time.sleep(10)
selenium.click('returnToMerchant')
time.sleep(15)
except:
traceback.print_exc()
def paySandbox(test, selenium, url):
print "PAY SANDBOX"
try:
selenium.open(url)
time.sleep(5)
test.failUnless(selenium.is_text_present('Your payment summary'))
selenium.click('loadLogin')
time.sleep(5)
selenium.type('id=login_email', PAYPAL_BUYER_LOGIN)
selenium.type('id=login_password', PAYPAL_BUYER_PASSWORD)
time.sleep(2)
selenium.click('submitLogin')
time.sleep(5)
test.failUnless(selenium.is_text_present('Review your information'))
selenium.click('submit.x')
time.sleep(10)
selenium.click('returnToMerchant')
time.sleep(15)
except:
traceback.print_exc()
class PledgeTest(TestCase):
def setUp(self):
self.verificationErrors = []
# This is an empty array where we will store any verification errors
# we find in our tests
self.selenium = selenium("localhost", 4444, "*firefox",
"http://www.google.com/")
self.selenium.start()
def validateRedirect(self, t, url, count):
self.assertNotEqual(url, None)
self.assertNotEqual(t, None)
self.assertEqual(t.receiver_set.all().count(), count)
self.assertEqual(t.receiver_set.all()[0].amount, t.amount)
self.assertEqual(t.receiver_set.all()[0].currency, t.currency)
self.assertNotEqual(t.reference, None)
self.assertEqual(t.error, None)
self.assertEqual(t.status, 'NONE')
valid = URLValidator(verify_exists=True)
try:
valid(url)
except ValidationError, e:
print e
def test_pledge_single_receiver(self):
try:
p = PaymentManager()
# Note, set this to 1-5 different receivers with absolute amounts for each
receiver_list = [{'email':'jakace_1309677337_biz@gmail.com', 'amount':20.00}]
t, url = p.pledge('USD', TARGET_TYPE_NONE, receiver_list, campaign=None, list=None, user=None)
self.validateRedirect(t, url, 1)
loginSandbox(self, self.selenium)
paySandbox(self, self.selenium, url)
t = Transaction.objects.get(id=t.id)
# by now we should have received the IPN
self.assertEqual(t.status, IPN_PAY_STATUS_COMPLETED)
self.assertEqual(t.receiver_set.all()[0].status, IPN_TXN_STATUS_COMPLETED)
except:
traceback.print_exc()
def test_pledge_mutiple_receiver(self):
p = PaymentManager()
# Note, set this to 1-5 different receivers with absolute amounts for each
receiver_list = [{'email':'jakace_1309677337_biz@gmail.com', 'amount':20.00},
{'email':'seller_1317463643_biz@gmail.com', 'amount':10.00}]
t, url = p.pledge('USD', TARGET_TYPE_NONE, receiver_list, campaign=None, list=None, user=None)
self.validateRedirect(t, url, 2)
loginSandbox(self, self.selenium)
paySandbox(self, self.selenium, url)
t = Transaction.objects.get(id=t.id)
# by now we should have received the IPN
self.assertEqual(t.status, IPN_PAY_STATUS_COMPLETED)
self.assertEqual(t.receiver_set.all()[0].status, IPN_TXN_STATUS_COMPLETED)
self.assertEqual(t.receiver_set.all()[1].status, IPN_TXN_STATUS_COMPLETED)
def test_pledge_too_much(self):
p = PaymentManager()
# Note, set this to 1-5 different receivers with absolute amounts for each
receiver_list = [{'email':'jakace_1309677337_biz@gmail.com', 'amount':50000.00}]
t, url = p.pledge('USD', TARGET_TYPE_NONE, receiver_list, campaign=None, list=None, user=None)
self.validateRedirect(t, url, 1)
class AuthorizeTest(TestCase):
def setUp(self):
self.verificationErrors = []
# This is an empty array where we will store any verification errors
# we find in our tests
self.selenium = selenium("localhost", 4444, "*firefox",
"http://www.google.com/")
self.selenium.start()
def validateRedirect(self, t, url):
self.assertNotEqual(url, None)
self.assertNotEqual(t, None)
self.assertNotEqual(t.reference, None)
self.assertEqual(t.error, None)
self.assertEqual(t.status, 'NONE')
valid = URLValidator(verify_exists=True)
try:
valid(url)
except ValidationError, e:
print e
def test_authorize(self):
print "RUNNING TEST: test_authorize"
p = PaymentManager()
# Note, set this to 1-5 different receivers with absolute amounts for each
t, url = p.authorize('USD', TARGET_TYPE_NONE, 100.0, campaign=None, list=None, user=None)
self.validateRedirect(t, url)
loginSandbox(self, self.selenium)
authorizeSandbox(self, self.selenium, url)
t = Transaction.objects.get(id=t.id)
self.assertEqual(t.status, IPN_PAY_STATUS_ACTIVE)
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)

View File

@ -7,5 +7,6 @@ urlpatterns = patterns(
url(r"^testexecute", "testExecute"), url(r"^testexecute", "testExecute"),
url(r"^testcancel", "testCancel"), url(r"^testcancel", "testCancel"),
url(r"^querycampaign", "queryCampaign"), url(r"^querycampaign", "queryCampaign"),
url(r"^paypalipn", "paypalIPN") url(r"^paypalipn", "paypalIPN"),
url(r"^runtests", "runTests")
) )

View File

@ -6,6 +6,9 @@ from django.contrib.auth.models import User
from regluit.payment.parameters import * from regluit.payment.parameters import *
from django.http import HttpResponse, HttpRequest, HttpResponseRedirect from django.http import HttpResponse, HttpRequest, HttpResponseRedirect
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.test.utils import setup_test_environment
from unittest import TestResult
from regluit.payment.tests import PledgeTest, AuthorizeTest
import traceback import traceback
''' '''
@ -159,6 +162,33 @@ def testPledge(request):
print "testPledge: Error " + str(t.reference) print "testPledge: Error " + str(t.reference)
return HttpResponse(response) return HttpResponse(response)
def runTests(request):
try:
# Setup the test environement. We need to run these tests on a live server
# so our code can receive IPN notifications from paypal
setup_test_environment()
result = TestResult()
# Run the authorize test
test = AuthorizeTest('test_authorize')
test.run(result)
# Run the pledge test
test = PledgeTest('test_pledge_single_receiver')
test.run(result)
# Run the pledge failure test
test = PledgeTest('test_pledge_too_much')
test.run(result)
output = "Tests Run: " + str(result.testsRun) + str(result.errors) + str(result.failures)
print output
return HttpResponse(output)
except:
traceback.print_exc()
@csrf_exempt @csrf_exempt
def paypalIPN(request): def paypalIPN(request):

View File

@ -5,4 +5,4 @@ https://github.com/toastdriven/django-tastypie/tarball/master
requests requests
https://bitbucket.org/ubernostrum/django-registration/get/tip.tar.gz https://bitbucket.org/ubernostrum/django-registration/get/tip.tar.gz
django-social-auth django-social-auth
django-profiles selenium

View File

@ -107,7 +107,6 @@ INSTALLED_APPS = (
'registration', 'registration',
'social_auth', 'social_auth',
'tastypie', 'tastypie',
'profiles',
) )
# A sample logging configuration. The only tangible logging # A sample logging configuration. The only tangible logging

View File

@ -57,3 +57,19 @@ GOOGLE_DISPLAY_NAME = 'unglue it!'
# you'll need to register a GoogleBooks API key # you'll need to register a GoogleBooks API key
# https://code.google.com/apis/console # https://code.google.com/apis/console
GOOGLE_BOOKS_API_KEY = '' GOOGLE_BOOKS_API_KEY = ''
PAYPAL_USERNAME = ''
PAYPAL_PASSWORD = ''
PAYPAL_SIGNATURE = ''
PAYPAL_APPID = ''
PAYPAL_ENDPOINT = 'svcs.sandbox.paypal.com' # sandbox
PAYPAL_PAYMENT_HOST = 'http://www.sandbox.paypal.com' # sandbox
PAYPAL_SANDBOX_LOGIN = ''
PAYPAL_SANDBOX_PASSWORD = ''
PAYPAL_BUYER_LOGIN =''
PAYPAL_BUYER_PASSWORD = ''
BASE_URL = 'http://0.0.0.0/'

Binary file not shown.