This repository has been archived by the owner on Jan 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
200 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ lib | |
parts | ||
var | ||
src/niteoweb.ipn.core/ | ||
src/plone.api/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ parts -= | |
omelette | ||
instance | ||
|
||
auto-checkout = niteoweb.ipn.core | ||
auto-checkout = | ||
niteoweb.ipn.core | ||
plone.api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<layers> | ||
<layer | ||
name="niteoweb.ipn.jvzoo" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?xml version="1.0"?> | ||
<metadata> | ||
<version>0100</version> | ||
<dependencies> | ||
<!-- <dependency>profile-niteoweb.ipn.core:default</dependency> --> | ||
<dependency>profile-plone.app.registry:default</dependency> | ||
<dependency>profile-niteoweb.ipn.core:default</dependency> | ||
</dependencies> | ||
</metadata> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Test all aspects of the @@jvzoo view.""" | ||
|
||
from niteoweb.ipn.jvzoo.testing import IntegrationTestCase | ||
from plone import api | ||
from zope.testing.loggingsupport import InstalledHandler | ||
|
||
import mock | ||
|
||
log = InstalledHandler('niteoweb.ipn.jvzoo') | ||
|
||
KEY_RECORD = 'niteoweb.ipn.jvzoo.interfaces.IJVZooSettings.secretkey' | ||
|
||
|
||
class TestJVZoo(IntegrationTestCase): | ||
"""Test all aspects of @@jvzoo.""" | ||
|
||
def setUp(self): | ||
"""Prepare testing environment.""" | ||
self.portal = self.layer['portal'] | ||
self.view = self.portal.restrictedTraverse('jvzoo') | ||
|
||
def tearDown(self): | ||
"""Clean up after yourself.""" | ||
log.clear() | ||
|
||
def test_call_with_no_POST(self): | ||
"""Test @@jvzoo's response when POST is empty.""" | ||
html = self.view() | ||
self.failUnless('No POST request.' in html) | ||
|
||
def test_call_with_missing_parameter(self): | ||
"""Test @@jvzoo's response when POST is missing a parameter.""" | ||
|
||
# put something into self.request.form so it's not empty | ||
self.portal.REQUEST.form = dict(foo='bar') | ||
|
||
# set secretkey | ||
api.portal.set_registry_record(KEY_RECORD, u'secret') | ||
|
||
# test html | ||
html = self.view() | ||
self.assertEqual(html, "POST parameter missing: 'cverify'") | ||
|
||
# test log output | ||
self.assertEqual(len(log.records), 1) | ||
self.assertEqual(log.records[0].name, 'niteoweb.ipn.jvzoo') | ||
self.assertEqual(log.records[0].levelname, 'WARNING') | ||
self.assertEqual( | ||
log.records[0].getMessage(), | ||
"POST parameter missing: 'cverify'", | ||
) | ||
|
||
def test_call_with_missing_secret_key(self): | ||
"""Test @@jvzoo's response when JVZoo secret-key is not set.""" | ||
|
||
# put something into self.request.form so it's not empty | ||
self.portal.REQUEST.form = dict(foo='bar') | ||
|
||
# test html | ||
html = self.view() | ||
self.assertEqual( | ||
html, "POST handling failed: JVZoo secret-key is not set.") | ||
|
||
# test log output | ||
self.assertEqual(len(log.records), 1) | ||
self.assertEqual(log.records[0].name, 'niteoweb.ipn.jvzoo') | ||
self.assertEqual(log.records[0].levelname, 'WARNING') | ||
self.assertEqual( | ||
log.records[0].getMessage(), | ||
"POST handling failed: JVZoo secret-key is not set.", | ||
) | ||
|
||
@mock.patch('niteoweb.ipn.jvzoo.browser.jvzoo.JVZoo._verify_POST') | ||
def test_call_with_invalid_checksum(self, verify_post): | ||
"""Test @@jvzoo's response when checksum cannot be verified.""" | ||
|
||
# put something into self.request.form so it's not empty | ||
self.portal.REQUEST.form = dict(foo='bar') | ||
|
||
# mock return from _verify_POST | ||
verify_post.side_effect = AssertionError | ||
|
||
# test html | ||
html = self.view() | ||
self.assertEqual(html, 'Checksum verification failed.') | ||
|
||
# test log output | ||
self.assertEqual(len(log.records), 1) | ||
self.assertEqual(log.records[0].name, 'niteoweb.ipn.jvzoo') | ||
self.assertEqual(log.records[0].levelname, 'WARNING') | ||
self.assertEqual( | ||
log.records[0].getMessage(), | ||
"Checksum verification failed.", | ||
) | ||
|
||
@mock.patch('niteoweb.ipn.jvzoo.browser.jvzoo.JVZoo._verify_POST') | ||
def test_call_with_internal_exception(self, verify_post): | ||
"""Test @@jvzoo's response when there is an internal problem.""" | ||
|
||
# put something into self.request.form so it's not empty | ||
self.portal.REQUEST.form = dict(foo='bar') | ||
|
||
# mock return from _verify_POST | ||
verify_post.side_effect = Exception('Internal foo.') | ||
|
||
# test html | ||
html = self.view() | ||
self.assertEqual(html, 'POST handling failed: Internal foo.') | ||
|
||
# test log output | ||
self.assertEqual(len(log.records), 1) | ||
self.assertEqual(log.records[0].name, 'niteoweb.ipn.jvzoo') | ||
self.assertEqual(log.records[0].levelname, 'WARNING') | ||
self.assertEqual( | ||
log.records[0].getMessage(), | ||
"POST handling failed: Internal foo.", | ||
) | ||
|
||
@mock.patch('niteoweb.ipn.jvzoo.browser.jvzoo.JVZoo._verify_POST') | ||
@mock.patch('niteoweb.ipn.jvzoo.browser.jvzoo.JVZoo._parse_POST') | ||
def test_call_with_valid_POST(self, parse_post, verify_post): | ||
"""Test @@jvzoo's response when POST is valid.""" | ||
|
||
# put something into self.request.form so it's not empty | ||
self.portal.REQUEST.form = dict(value='non empty value') | ||
|
||
# mock post handling | ||
verify_post.return_value = True | ||
parse_post.return_value = dict( | ||
email='jsmith@email.com', | ||
transaction_type='SALE' | ||
) | ||
|
||
# test html | ||
html = self.view() | ||
self.assertIn('Done.', html) | ||
|
||
# test log output | ||
self.assertEqual(len(log.records), 1) | ||
self.assertEqual(log.records[0].name, 'niteoweb.ipn.jvzoo') | ||
self.assertEqual(log.records[0].levelname, 'INFO') | ||
self.assertEqual( | ||
log.records[0].getMessage(), | ||
"POST successfully parsed for 'jsmith@email.com'", | ||
) | ||
|
||
def test_verify_POST(self): | ||
"""Test POST verification process.""" | ||
params = dict( | ||
secretkey='secret', | ||
ccustname='fullname', | ||
cverify='38CFCDED', | ||
) | ||
self.view._verify_POST(params) | ||
self.assertTrue(True) | ||
|
||
def test_parse_POST(self): | ||
"""Test that POST parameters are correctly mirrored into member | ||
fields. | ||
""" | ||
post_params = dict( | ||
ccustname='fullname', | ||
ccustemail='email', | ||
ctransreceipt='payment_id', | ||
cproditem='product_id', | ||
cprodtitle='product_name', | ||
ctransaffiliate='affiliate', | ||
ctransaction='SALE', | ||
) | ||
|
||
expected = dict( | ||
fullname=u'fullname', | ||
email='email', | ||
product_id='product_id', | ||
product_name='product_name', | ||
affiliate='affiliate', | ||
payment_id='payment_id', | ||
transaction_type='SALE', | ||
) | ||
|
||
result = self.view._parse_POST(post_params) | ||
self.assertEqual(result, expected) |