forked from glim/rest-api-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_test.py
More file actions
61 lines (48 loc) · 2.18 KB
/
api_test.py
File metadata and controls
61 lines (48 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from test_helper import unittest, client_id, client_secret, paypal
from mock import patch
import logging
logging.basicConfig(filename='eg.log',level=logging.DEBUG)
class Api(unittest.TestCase):
api = paypal.Api(
client_id= client_id,
client_secret= client_secret )
def test_endpoint(self):
new_api = paypal.Api(mode="live")
self.assertEqual(new_api.endpoint, "https://api.paypal.com")
self.assertEqual(new_api.token_endpoint, "https://api.paypal.com")
new_api = paypal.Api(mode="sandbox")
self.assertEqual(new_api.endpoint, "https://api.sandbox.paypal.com")
self.assertEqual(new_api.token_endpoint, "https://api.sandbox.paypal.com")
new_api = paypal.Api(endpoint="https://custom-endpoint.paypal.com")
self.assertEqual(new_api.endpoint, "https://custom-endpoint.paypal.com")
self.assertEqual(new_api.token_endpoint, "https://custom-endpoint.paypal.com")
def test_get(self):
payment_history = self.api.get("/v1/payments/payment?count=1")
logging.warning('payment_history')
self.assertEqual(payment_history['count'], 1)
def test_post(self):
credit_card = self.api.post("v1/vault/credit-card", {
"type": "visa",
"number": "4417119669820331",
"expire_month": "11",
"expire_year": "2018",
"cvv2": "874",
"first_name": "Joe",
"last_name": "Shopper" })
self.assertEqual(credit_card.get('error'), None)
self.assertNotEqual(credit_card.get('id'), None)
def test_bad_request(self):
credit_card = self.api.post("v1/vault/credit-card", {})
self.assertNotEqual(credit_card.get('error'), None)
def test_expired_token(self):
self.assertNotEqual(self.api.get_token(), None)
self.api.token_hash["access_token"] = "ExpiredToken"
self.assertEqual(self.api.get_token(), "ExpiredToken")
payment_history = self.api.get("/v1/payments/payment?count=1")
self.assertEqual(payment_history['count'], 1)
def test_expired_time(self):
old_token = self.api.get_token()
self.api.token_hash["expires_in"] = 0
self.assertNotEqual(self.api.get_token(), old_token)
def test_not_found(self):
self.assertRaises(paypal.ResourceNotFound, self.api.get, ("/v1/payments/payment/PAY-1234"))