def check_payment_history(comment, amount): yandex_money_token = get_config_var('YandexMoneyToken') if not yandex_money_token: return False wallet = Wallet(yandex_money_token) options = { "type": "deposition", "details": "true" } for operation in wallet.operation_history(options)['operations']: try: if operation['message'] == comment and operation['amount'] >= amount: return True except KeyError: continue return False
class WalletTestSuite(unittest.TestCase): def setUp(self): super(WalletTestSuite, self).setUp() self.api = Wallet(ACCESS_TOKEN) def assert_auth_header_present(self): pass def testAccountInfo(self): response = self.api.account_info() self.assert_auth_header_present() def testGetAuxToken(self): token = "some_aux_token" response = self.api.get_aux_token(["account-info", "operation-history"]) self.assertIn('aux_token', response) def testOperationHistory(self): options = {"records": 3} response = self.api.operation_history(options) def testOperationDetails(self): pass def testRequestPayment(self): options = { "pattern_id": "p2p", "to": "410011161616877", "amount_due": "0.02", "comment": "test payment comment from yandex-money-python", "message": "test payment message from yandex-money-python", "label": "testPayment", "test_payment": True, "test_result": "success" } response = self.api.request_payment(options) self.assertEqual(response['status'], 'success') def testResponsePayment(self): options = { "request_id": "test-p2p", "test_payment": True, "test_result": "success" } response = self.api.process_payment(options) self.assertEqual(response['status'], 'success') def testIncomingTransferAccept(self): #self.addResponse("incoming-transfer-accept", {"status": "success"}) operation_id = "some id" protection_code = "some code" # TODO: test when it's None response = self.api.incoming_transfer_accept( operation_id=operation_id, protection_code=protection_code ) self.assertEqual(response['status'], "refused") def testIncomingTransferReject(self): #self.addResponse("incoming-transfer-reject", {"status": "success"}) operation_id = "some operatoin id" response = self.api.incoming_transfer_reject( operation_id=operation_id, ) def testObtainTokenUrl(self): client_id = "client-id" url = Wallet.build_obtain_token_url( "client-id", "http://localhost/redirect", ["account-info", "operation_history"] ) # TODO: check url def testGetAccessToken(self): options = { "code": "code", "client_id": "client_id", "grant_type": "authorization_code", "redirect_uri": "redirect_uri", "client_secret": "client_secret" } response = Wallet.get_access_token( code=options["code"], client_id=options["client_id"], redirect_uri=options["redirect_uri"], client_secret=options["client_secret"] ) self.assertEqual(response['error'], 'unauthorized_client')
class WalletTestSuite(unittest.TestCase): def setUp(self): super(WalletTestSuite, self).setUp() self.api = Wallet(ACCESS_TOKEN) def assert_auth_header_present(self): pass def testAccountInfo(self): self.api.account_info() self.assert_auth_header_present() def testGetAuxToken(self): response = self.api.get_aux_token( ["account-info", "operation-history"]) self.assertIn('aux_token', response) def testOperationHistory(self): options = {"records": 3} self.api.operation_history(options) def testOperationDetails(self): self.api.operation_details("some-invalid-id") def testRequestPayment(self): options = { "pattern_id": "p2p", "to": "410011161616877", "amount_due": "0.02", "comment": "test payment comment from yandex-money-python", "message": "test payment message from yandex-money-python", "label": "testPayment", "test_payment": True, "test_result": "success" } response = self.api.request_payment(options) self.assertEqual(response['status'], 'success') def testResponsePayment(self): options = { "request_id": "test-p2p", "test_payment": True, "test_result": "success" } response = self.api.process_payment(options) self.assertEqual(response['status'], 'success') def testIncomingTransferAccept(self): operation_id = "some id" protection_code = "some code" # TODO: test when it's None response = self.api.incoming_transfer_accept( operation_id=operation_id, protection_code=protection_code) self.assertEqual(response['status'], "refused") def testIncomingTransferReject(self): operation_id = "some operatoin id" self.api.incoming_transfer_reject(operation_id=operation_id, ) def testObtainTokenUrl(self): Wallet.build_obtain_token_url("client-id", "http://localhost/redirect", ["account-info", "operation_history"]) # TODO: check url def testGetAccessToken(self): options = { "code": "code", "client_id": "client_id", "grant_type": "authorization_code", "redirect_uri": "redirect_uri", "client_secret": "client_secret" } response = Wallet.get_access_token( code=options["code"], client_id=options["client_id"], redirect_uri=options["redirect_uri"], client_secret=options["client_secret"]) self.assertEqual(response['error'], 'unauthorized_client')
class WalletTestSuite(ResponseMockTestCase): def setUp(self): super(WalletTestSuite, self).setUp() self.api = Wallet("TEST TOKEN") def assert_auth_header_present(self): self.assertEqual("Bearer TEST TOKEN", responses.calls[0].request.headers['Authorization'], ) def testAccountInfo(self): self.addResponse("account-info", {"status": "success"} ) response = self.api.account_info() self.assertEqual(response['status'], "success") self.assert_auth_header_present() def testGetAuxToken(self): token = "some_aux_token" self.addResponse("token-aux", {"aux_token": token}) response = self.api.get_aux_token(["account-info", "operation-history"]) self.assertEqual(response['aux_token'], token) self.assertEqual(responses.calls[0].request.body, "scope=account-info+operation-history") def testOperationHistory(self): options = {"foo": "bar", "foo2": "bar2"} self.addResponse("operation-history", []) response = self.api.operation_history(options) self.assertEqual(response, []) self.assertEqual(responses.calls[0].request.body, urlencode(options) ) def testRequestPayment(self): self.addResponse("request-payment", {"status": "success"}) options = { "foo": "bar", "foo2": "bar2", } response = self.api.request_payment(options) self.assertEqual(response, {"status": "success"}) self.assertEqual(responses.calls[0].request.body, urlencode(options) ) def testResponsePayment(self): self.addResponse("process-payment", {"status": "success"}) options = { "foo": "bar", "foo2": "bar2", } response = self.api.process_payment(options) self.assertEqual(response, {"status": "success"}) self.assertEqual(responses.calls[0].request.body, urlencode(options) ) def testIncomingTransferAccept(self): self.addResponse("incoming-transfer-accept", {"status": "success"}) options = { "foo": "bar", "foo2": "bar2", } operation_id = "some id" protection_code = "some code" # TODO: test when it's None response = self.api.incoming_transfer_accept( operation_id=operation_id, protection_code=protection_code ) self.assertEqual(response, {"status": "success"}) self.assertEqual( responses.calls[0].request.body, urlencode({ "operation_id": operation_id, "protection_code": protection_code }) ) def testIncomingTransferReject(self): self.addResponse("incoming-transfer-reject", {"status": "success"}) operation_id = "some id" response = self.api.incoming_transfer_reject( operation_id=operation_id, ) self.assertEqual(response, {"status": "success"}) self.assertEqual( responses.calls[0].request.body, urlencode({ "operation_id": operation_id, }) ) def testObtainTokenUrl(self): client_id = "client-id" url = Wallet.build_obtain_token_url( "client-id", "http://localhost/redirect", ["account-info", "operation_history"] ) # TODO: check url def testGetAccessToken(self): self.addResponse(Wallet.SP_MONEY_URL + "/oauth/token", {"status": "success"}, is_api_url=False ) options = { "code": "code", "client_id": "client_id", "grant_type": "authorization_code", "redirect_uri": "redirect_uri", "client_secret": "client_secret" } response = Wallet.get_access_token( code=options["code"], client_id=options["client_id"], redirect_uri=options["redirect_uri"], client_secret=options["client_secret"] ) self.assertEqual(response, {"status": "success"}) self.assertEqual( responses.calls[0].request.body, urlencode(options) ) def testRevokeToken(self): self.addResponse("revoke", {"status": "success"}) Wallet.revoke_token("TEST TOKEN") self.assert_auth_header_present()