forked from glim/rest-api-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_test.py
More file actions
81 lines (72 loc) · 2.68 KB
/
resource_test.py
File metadata and controls
81 lines (72 loc) · 2.68 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from test_helper import unittest
from paypalrestsdk.resource import Resource
class TestResource(unittest.TestCase):
def test_getter(self):
data = {
'name': 'testing',
'amount': 10.0,
'transaction': { 'description': 'testing' },
'items': [ { 'name': 'testing' } ] }
resource = Resource(data)
self.assertEqual(resource.name, 'testing')
self.assertEqual(resource['name'], 'testing')
self.assertEqual(resource.amount, 10.0)
self.assertEqual(resource.items[0].__class__, Resource)
self.assertEqual(resource.items[0].name, 'testing')
self.assertEqual(resource.items[0]['name'], 'testing')
self.assertEqual(resource.unknown, None)
self.assertRaises(KeyError, lambda: resource['unknown'])
def test_setter(self):
data = { 'name': 'testing' }
resource = Resource(data)
self.assertEqual(resource.name, 'testing' )
resource.name = 'changed'
self.assertEqual(resource.name, 'changed' )
resource['name'] = 'again-changed'
self.assertEqual(resource.name, 'again-changed' )
resource.transaction = { 'description': 'testing' }
self.assertEqual(resource.transaction.__class__, Resource)
self.assertEqual(resource.transaction.description, 'testing')
def test_to_dict(self):
data = {
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [{
"credit_card": {
"type": "visa",
"number": "4417119669820331",
"expire_month": "11",
"expire_year": "2018",
"cvv2": "874",
"first_name": "Joe",
"last_name": "Shopper" }}]},
"transactions": [{
"item_list": {
"items": [{
"name": "item",
"sku": "item",
"price": "1.00",
"currency": "USD",
"quantity": 1 }]},
"amount": {
"total": "1.00",
"currency": "USD" },
"description": "This is the payment transaction description." }]}
resource = Resource(data)
self.assertEqual(resource.to_dict(), data)
def test_request_id(self):
data = {
'name': 'testing',
'request_id': 1234 }
resource = Resource(data)
self.assertEqual(resource.to_dict(), {'name': 'testing'})
self.assertEqual(resource.request_id, 1234)
self.assertEqual(resource.http_headers(), {'PayPal-Request-Id': 1234})
def test_http_headers(self):
data = {
'name': 'testing',
'header': { 'My-Header': 'testing' } }
resource = Resource(data)
self.assertEqual(resource.header, {'My-Header': 'testing'})
self.assertEqual(resource.http_headers(), {'PayPal-Request-Id': resource.request_id, 'My-Header': 'testing'})