def setUp(self): self.browser = GoPayMock({ 'clientId': 'userId', 'clientSecret': 'pass', 'scope': 'irrelevant scope', 'isProductionMode': False }) self.oauth = OAuth2(self.browser)
def setUp(self): self.browser = GoPayMock({ 'language': 'default', 'goid': 'id', }) self.auth = AuthStub() self.payments = Payments(self.browser, self.auth)
class PaymentsTest(unittest.TestCase): def setUp(self): self.browser = GoPayMock({"language": "default", "goid": "id"}) self.auth = AuthStub() self.payments = Payments(self.browser, self.auth) endpoints = lambda: ( ( lambda p: p.create_payment({"payment": "", "lang": "", "target": ""}), "", JSON, {"payment": "", "lang": "", "target": ""}, ), ( lambda p: p.create_payment({"payment": ""}), "", JSON, {"payment": "", "target": {"type": "ACCOUNT", "goid": "id"}, "lang": "default"}, ), (lambda p: p.get_status(3), "/3", FORM, None), (lambda p: p.refund_payment(3, 100), "/3/refund", FORM, {"amount": 100}), (lambda p: p.create_recurrence(3, {"payment": ""}), "/3/create-recurrence", JSON, {"payment": ""}), (lambda p: p.void_recurrence(3), "/3/void-recurrence", FORM, {}), (lambda p: p.capture_authorization(3), "/3/capture", FORM, {}), (lambda p: p.void_authorization(3), "/3/void-authorization", FORM, {}), ) @data_provider(endpoints) def test_should_build_request(self, call_api, url, content_type, expected_body): self.auth.when_auth_succeed() call_api(self.payments) self.browser.should_be_called_with( "payments/payment" + url, content_type, "Bearer irrelevant token", expected_body ) def test_should_call_api_when_auth_succeed(self): self.auth.when_auth_succeed() response = self.payments.create_payment({}) assert_that(response, is_(self.browser.response)) def test_should_return_token_response_when_auth_failed(self): self.auth.when_auth_failed() response = self.payments.create_payment({}) assert_that(response, is_(self.auth.token.response)) def test_should_return_embedjs(self): assert_that(self.payments.url_to_embedjs(), is_("gp-gw/js/embed.js"))
class OAuth2Test(unittest.TestCase): def setUp(self): self.browser = GoPayMock({ 'clientId': 'userId', 'clientSecret': 'pass', 'scope': 'irrelevant scope', 'isProductionMode': False }) self.oauth = OAuth2(self.browser) def test_should_call_api_with_basic_authorization(self): self.browser.given_response() self.authorize() def test_should_return_expired_token_when_api_failed(self): self.browser.given_response(False) token = self.authorize() assert_that(token.token, is_(None)) assert_that(token.is_expired(), is_(True)) def test_should_return_extract_token_from_response(self): self.browser.given_response(True, { 'access_token': 'irrelevant token', 'expires_in': 1800 }) token = self.authorize() assert_that(token.is_expired(), is_(False)) assert_that(token.token, is_('irrelevant token')) assert_that(token.expiration_date, is_not(None)) def test_should_uniquely_identify_current_client(self): assert_that(self.oauth.get_client(), is_('userId-0-irrelevant scope')) def authorize(self): return self.oauth.authorize()
class OAuth2Test(unittest.TestCase): def setUp(self): self.browser = GoPayMock({ 'clientId': 'userId', 'clientSecret': 'pass', 'scope': 'irrelevant scope', 'isProductionMode': False }) self.oauth = OAuth2(self.browser) def test_should_call_api_with_basic_authorization(self): self.browser.given_response() self.authorize() self.browser.should_be_called_with( 'oauth2/token', FORM, 'Basic dXNlcklkOnBhc3M=', { 'grant_type': 'client_credentials', 'scope': 'irrelevant scope' } ) def test_should_return_expired_token_when_api_failed(self): self.browser.given_response(False) token = self.authorize() assert_that(token.token, is_(None)) assert_that(token.is_expired(), is_(True)) def test_should_return_extract_token_from_response(self): self.browser.given_response(True, {'access_token': 'irrelevant token', 'expires_in': 1800}) token = self.authorize() assert_that(token.is_expired(), is_(False)) assert_that(token.token, is_('irrelevant token')) assert_that(token.expiration_date, is_not(None)) def test_should_uniquely_identify_current_client(self): assert_that(self.oauth.get_client(), is_('userId-0-irrelevant scope')) def authorize(self): return self.oauth.authorize()
def setUp(self): self.browser = GoPayMock({"language": "default", "goid": "id"}) self.auth = AuthStub() self.payments = Payments(self.browser, self.auth)