def test_store_notification_stores_notification(self): # notifications are really stored receiver = PayPalIPNReceiver() receiver.store_notification("sample-string", uuid="my-uuid") assert "my-uuid" in receiver stored = receiver["my-uuid"] assert IInstantPaymentNotification.providedBy(stored)
def test_validate_no_notification_url(self): # we require a notification URL for validation requests receiver = PayPalIPNReceiver() receiver.validation_url = None assert receiver.validate('foo') is None receiver.validation_url = '' assert receiver.validate('bar') is None
def test_validate_no_action_wo_validation_url(self): # a receiver does not perform any action w/o a validation_url set. receiver = PayPalIPNReceiver() receiver.validation_url = '' assert receiver.validate('x=1') is None receiver.validation_url = None assert receiver.validate('x=1') is None
def test_index_returns_200_Ok(self): # if we deliver normal data we will get a 200 Ok. receiver = PayPalIPNReceiver() receiver.validation_url = '' self.layer.getRootFolder()['app'] = receiver browser = Browser() browser.open('http://localhost/app/@@index') assert browser.headers.get("status") == "200 Ok"
def test_index_returns_empty_body(self): # if we deliver normal data we will return with an empty doc. receiver = PayPalIPNReceiver() receiver.validation_url = '' self.layer.getRootFolder()['app'] = receiver browser = Browser() browser.open('http://localhost/app/@@index') assert browser.contents == ''
def test_validate(self): # we can validate instant payment messages receiver = PayPalIPNReceiver() result = None with http_server(paypal_mode='valid') as server: receiver.validation_url = server.url result = receiver.validate('some-fake-data') sent_body = server.last_request_body assert result == "VERIFIED" assert sent_body == 'cmd=_notify-validate&some-fake-data'
def test_validate_invlid(self): # we get it if a payment notification is invalid receiver = PayPalIPNReceiver() result = None with http_server(paypal_mode='invalid') as server: receiver.validation_url = server.url result = receiver.validate('some-fake-data') sent_body = server.last_request_body assert result == "INVALID" assert sent_body == 'cmd=_notify-validate&some-fake-data'
def test_notify_view_validation_valid(self): # we can get successful validations with notify receiver = PayPalIPNReceiver() receiver.validation_url = self.layer.server.url root = self.layer.getRootFolder() root['app'] = receiver browser = Browser() browser.post('http://localhost/app/@@index', 'x=2') sent_body = self.layer.server.last_request_body assert browser.headers.get("status") == "200 Ok" assert sent_body == 'cmd=_notify-validate&x=2' assert len(list(receiver.keys())) == 1 notification = receiver[receiver.keys()[0]] assert notification.final_verdict == u'VERIFIED'
def test_validate_no_post_var_string(self): # if we got no post-var-string (or it is empty) we do not validate receiver = PayPalIPNReceiver() assert receiver.validate(None) is None assert receiver.validate('') is None
def test_store_notification_returns_passed_in_uuid(self): # we get back our own UUID if we pass one in receiver = PayPalIPNReceiver() uuid = receiver.store_notification("sample-string", uuid="blah") assert uuid == u"blah"
def test_store_notification_returns_uuid(self): # `store_notification` returns a UUID receiver = PayPalIPNReceiver() uuid = receiver.store_notification("sample-string") assert uuid is not None
def test_iface(self): # the ipn receiver fullfills interface contracts receiver = PayPalIPNReceiver() verifyClass(IPayPalIPNReceiver, PayPalIPNReceiver) verifyObject(IPayPalIPNReceiver, receiver)
def test_has_index_view(self): # we have an 'index' view for PayPalIPNReceivers receiver = PayPalIPNReceiver() request = TestRequest() view = getMultiAdapter((receiver, request), name='index') assert view is not None