def check_refund(self): """Check that we have the refund permission.""" test_id = 'refund' msg = loc('You have not setup permissions for us to check this ' 'paypal account.') if not self.addon: # If there's no addon there's not even any point checking. return premium = self.addon.premium if not premium: self.state['permissions'] = False self.failure(test_id, msg) return token = premium.paypal_permissions_token if not token: self.state['permissions'] = False self.failure(test_id, msg) return try: status = paypal.check_permission(token, ['REFUND']) if not status: self.state['permissions'] = False self.failure(test_id, loc('No permission to do refunds.')) else: self.pass_(test_id) except paypal.PaypalError: self.state['permissions'] = False self.failure(test_id, msg) log.info('Refund permission check returned an error ' 'for %s' % id, exc_info=True)
def test_check_permission_fail(self, _call): """ `check_paypal_refund_permission` returns False if PayPal doesn't put 'REFUND' in the permissions response. """ _call.return_value = {'scope(0)': 'HAM_SANDWICH'} assert not paypal.check_permission('foo', ['REFUND'])
def test_check_permission_fail(self, _call): """ `check_paypal_refund_permission` returns False if PayPal doesn't put 'REFUND' in the permissions response. """ _call.return_value = {"scope(0)": "HAM_SANDWICH"} assert not paypal.check_permission(good_token, ["REFUND"])
def test_check_permission(self, _call): """ `check_paypal_refund_permission` returns True if PayPal puts 'REFUND' in the permissions response. """ _call.return_value = {"scope(0)": "REFUND"} eq_(paypal.check_permission(good_token, ["REFUND"]), True)
def test_check_permission(self, _call): """ `check_paypal_refund_permission` returns True if PayPal puts 'REFUND' in the permissions response. """ _call.return_value = {'scope(0)': 'REFUND'} eq_(paypal.check_permission(good_token, ['REFUND']), True)
def test_check_permission(self, _call): """ `check_paypal_refund_permission` returns True if PayPal puts 'REFUND' in the permissions response. """ _call.return_value = {'scope(0)': 'REFUND'} eq_(paypal.check_permission('foo', ['REFUND']), True)
def test_check_permission_fail(self, _call): """ `check_paypal_refund_permission` returns False if PayPal doesn't put 'REFUND' in the permissions response. """ _call.return_value = {'scope(0)': 'HAM_SANDWICH'} assert not paypal.check_permission(good_token, ['REFUND'])
def has_valid_permissions_token(self): """ Have we got a valid permissions token by pinging PayPal. If you've got 'should_ignore_paypal', then it will just happily return True. """ if paypal.should_ignore_paypal(): return True if not self.paypal_permissions_token: return False return paypal.check_permission(self.paypal_permissions_token, ["REFUND"])
def has_valid_permissions_token(self): """ Have we got a valid permissions token by pinging PayPal. If you've got 'should_ignore_paypal', then it will just happily return True. """ if paypal.should_ignore_paypal(): return True if not self.paypal_permissions_token: return False return paypal.check_permission(self.paypal_permissions_token, ['REFUND'])
def test_check_permission_error(self, _call): _call.side_effect = paypal.PaypalError assert not paypal.check_permission(good_token, ['REFUND'])
def test_get_permissions_subset(self, _call): _call.return_value = {"scope(0)": "REFUND", "scope(1)": "HAM"} eq_(paypal.check_permission(good_token, ["REFUND", "HAM"]), True) eq_(paypal.check_permission(good_token, ["REFUND", "JAM"]), False) eq_(paypal.check_permission(good_token, ["REFUND"]), True)
def test_check_permission_settings(self, _call): settings.PAYPAL_PERMISSIONS_URL = "" assert not paypal.check_permission(good_token, ["REFUND"])
def test_check_permission_error(self, _call): _call.side_effect = paypal.PaypalError assert not paypal.check_permission(good_token, ["REFUND"])
def test_get_permissions_subset(self, _call): _call.return_value = {'scope(0)': 'REFUND', 'scope(1)': 'HAM'} eq_(paypal.check_permission(good_token, ['REFUND', 'HAM']), True) eq_(paypal.check_permission(good_token, ['REFUND', 'JAM']), False) eq_(paypal.check_permission(good_token, ['REFUND']), True)
def test_check_permission_settings(self, _call): settings.PAYPAL_PERMISSIONS_URL = '' assert not paypal.check_permission(good_token, ['REFUND'])
def test_check_permission_settings(self, _call): settings.PAYPAL_PERMISSIONS_URL = '' assert not paypal.check_permission('oh-noes', ['REFUND'])
def test_check_permission_error(self, _call): _call.side_effect = paypal.PaypalError assert not paypal.check_permission('oh-noes', ['REFUND'])