Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
use the latest release of niteoweb.ipn.core
Browse files Browse the repository at this point in the history
  • Loading branch information
zupo committed Dec 27, 2012
1 parent 99e3299 commit 19f93ac
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 31 deletions.
1 change: 0 additions & 1 deletion buildout.d/travis.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ parts -=
instance

auto-checkout =
niteoweb.ipn.core
plone.api
21 changes: 13 additions & 8 deletions src/niteoweb/ipn/jvzoo/jvzoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,21 @@ def render(self):

# call appropriate action in niteoweb.ipn.core
ipn = getAdapter(self.context, IIPN)
ttype = data['transaction_type']
if ttype in self.TYPES_TO_ACTIONS:
action = self.TYPES_TO_ACTIONS[ttype]
trans_type = data['trans_type']
if trans_type in self.TYPES_TO_ACTIONS:
action = self.TYPES_TO_ACTIONS[trans_type]
logger.info("Calling '%s' in niteoweb.ipn.core." % action)
getattr(ipn, action)(data)
params = {
'email': data['email'],
'product_id': data['product_id'],
'trans_type': data['trans_type'],
'fullname': data.get('fullname'), # optional
'affiliate': data.get('affiliate'), # optional
}
getattr(ipn, action)(**params)
else:
raise UnknownTransactionType(
"Unknown Transaction Type '%s'." % ttype)
"Unknown Transaction Type '%s'." % trans_type)

except KeyError as ex:
msg = "POST parameter missing: %s" % ex
Expand Down Expand Up @@ -108,8 +115,6 @@ def _parse_POST(self, params):
'email': params['ccustemail'],
'fullname': u"%s" % params['ccustname'].decode("utf-8"),
'product_id': params['cproditem'],
'product_name': params['cprodtitle'],
'payment_id': params['ctransreceipt'],
'affiliate': params['ctransaffiliate'],
'transaction_type': params['ctransaction'],
'trans_type': params['ctransaction'],
}
60 changes: 38 additions & 22 deletions src/niteoweb/ipn/jvzoo/tests/test_jvzoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def setUp(self):
self.portal = self.layer['portal']
self.view = self.portal.restrictedTraverse('jvzoo')

# create test group
api.group.create(groupname='1')
group = api.group.get(groupname='1')
group.setGroupProperties(mapping={'validity': 31})

def tearDown(self):
"""Clean up after yourself."""
log.clear()
Expand Down Expand Up @@ -128,20 +133,22 @@ def test_call_with_valid_POST(self, parse_post, verify_post):
# mock post handling
verify_post.return_value = True
parse_post.return_value = dict(
email='jsmith@email.com',
transaction_type='SALE'
email='new@test.com',
product_id='1',
trans_type='SALE',
fullname='New Member',
affiliate='aff@test.com'
)

# test html
html = self.view()
self.assertEqual('Done.', html)
# test html output
self.assertEqual('Done.', self.view.render())

# test log output
self.assertEqual(len(log.records), 2)

self._assert_log_record(
'INFO',
"POST successfully parsed for 'jsmith@email.com'.",
"POST successfully parsed for 'new@test.com'.",
)

self._assert_log_record(
Expand All @@ -153,75 +160,88 @@ def test_call_with_valid_POST(self, parse_post, verify_post):
class TestTransactionTypesToActionsMapping(TestJVZoo):
"""Test how Transaction Types map to niteoweb.ipn.core actions."""

@mock.patch('niteoweb.ipn.jvzoo.jvzoo.getAdapter')
@mock.patch('niteoweb.ipn.jvzoo.jvzoo.JVZoo._verify_POST')
@mock.patch('niteoweb.ipn.jvzoo.jvzoo.JVZoo._parse_POST')
def _simulate_transaction(self, parse_post, verify_post, ttype=None):
def _simulate_transaction(
self,
parse_post,
verify_post,
getAdapter,
trans_type=None
):
"""Simulate a transaction of a certain type from JVZoo."""

# put something into self.request.form so it's not empty
self.portal.REQUEST.form = dict(value='non empty value')

# mock methods
verify_post.return_value = True
parse_post.return_value = dict(
email='jsmith@email.com',
transaction_type=ttype,
email='new@test.com',
product_id='1',
trans_type=trans_type,
)
getAdapter.return_value.enable_member.return_value = 'foo'
getAdapter.return_value.disable_member.return_value = 'bar'

html = self.view()
self.assertEqual(len(log.records), 2)
self.assertEqual('Done.', html)

# 1. post parsed, 2. action called
self.assertEqual(len(log.records), 2)

def test_SALE(self):
"""Test SALE Transaction Type."""
self._simulate_transaction(ttype='SALE')
self._simulate_transaction(trans_type='SALE')

# test log output
msg = log.records[1].getMessage()
self.assertEqual(msg, "Calling 'enable_member' in niteoweb.ipn.core.")

def test_BILL(self):
"""Test BILL Transaction Type."""
self._simulate_transaction(ttype='BILL')
self._simulate_transaction(trans_type='BILL')

# test log output
msg = log.records[1].getMessage()
self.assertEqual(msg, "Calling 'enable_member' in niteoweb.ipn.core.")

def test_RFND(self):
"""Test RFND Transaction Type."""
self._simulate_transaction(ttype='RFND')
self._simulate_transaction(trans_type='RFND')

# test log output
msg = log.records[1].getMessage()
self.assertEqual(msg, "Calling 'disable_member' in niteoweb.ipn.core.")

def test_CGBK(self):
"""Test CGBK Transaction Type."""
self._simulate_transaction(ttype='CGBK')
self._simulate_transaction(trans_type='CGBK')

# test log output
msg = log.records[1].getMessage()
self.assertEqual(msg, "Calling 'disable_member' in niteoweb.ipn.core.")

def test_INSF(self):
"""Test INSF Transaction Type."""
self._simulate_transaction(ttype='INSF')
self._simulate_transaction(trans_type='INSF')

# test log output
msg = log.records[1].getMessage()
self.assertEqual(msg, "Calling 'disable_member' in niteoweb.ipn.core.")

def test_CANCEL_REBILL(self):
"""Test CANCEL-REBILL Transaction Type."""
self._simulate_transaction(ttype='CANCEL-REBILL')
self._simulate_transaction(trans_type='CANCEL-REBILL')

# test log output
msg = log.records[1].getMessage()
self.assertEqual(msg, "Calling 'disable_member' in niteoweb.ipn.core.")

def test_UNCANCEL_REBILL(self):
"""Test UNCANCEL-REBILL Transaction Type."""
self._simulate_transaction(ttype='UNCANCEL-REBILL')
self._simulate_transaction(trans_type='UNCANCEL-REBILL')

# test log output
msg = log.records[1].getMessage()
Expand Down Expand Up @@ -253,9 +273,7 @@ def test_parse_POST(self):
post_params = dict(
ccustname='fullname',
ccustemail='email',
ctransreceipt='payment_id',
cproditem='product_id',
cprodtitle='product_name',
ctransaffiliate='affiliate',
ctransaction='SALE',
)
Expand All @@ -264,10 +282,8 @@ def test_parse_POST(self):
fullname=u'fullname',
email='email',
product_id='product_id',
product_name='product_name',
affiliate='affiliate',
payment_id='payment_id',
transaction_type='SALE',
trans_type='SALE',
)

result = self.view._parse_POST(post_params)
Expand Down

0 comments on commit 19f93ac

Please sign in to comment.