|
1
|
|
|
"""Script defined to test the Plan class.""" |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
import unittest |
|
5
|
|
|
import httpretty |
|
6
|
|
|
import mock |
|
7
|
|
|
|
|
8
|
|
|
from paystackapi.plan import Plan |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class TestPlan(unittest.TestCase): |
|
12
|
|
|
"""Class to test Plans.""" |
|
13
|
|
|
|
|
14
|
|
|
@httpretty.activate |
|
15
|
|
|
def test_create(self): |
|
16
|
|
|
"""Method defined to test plan creation.""" |
|
17
|
|
|
httpretty.register_uri( |
|
18
|
|
|
httpretty.POST, |
|
19
|
|
|
"https://api.paystack.co/plan", |
|
20
|
|
|
content_type='text/json', |
|
21
|
|
|
body='{"status": true, "contributors": true}', |
|
22
|
|
|
status=201, |
|
23
|
|
|
) |
|
24
|
|
|
|
|
25
|
|
|
response = Plan.create( |
|
26
|
|
|
name="John Doe", description="Payment plan for awesome people contributions", |
|
27
|
|
|
amount=50000, interval="daily", send_invoices=True, ) |
|
28
|
|
|
self.assertTrue(response['status']) |
|
29
|
|
|
|
|
30
|
|
|
@httpretty.activate |
|
31
|
|
|
def test_get(self): |
|
32
|
|
|
"""Function defined to test Plan get method.""" |
|
33
|
|
|
httpretty.register_uri( |
|
34
|
|
|
httpretty.GET, |
|
35
|
|
|
"https://api.paystack.co/plan/78", |
|
36
|
|
|
content_type='text/json', |
|
37
|
|
|
body='{"status": true, "contributors": true}', |
|
38
|
|
|
status=201, |
|
39
|
|
|
) |
|
40
|
|
|
|
|
41
|
|
|
response = Plan.get(plan_id=78) |
|
42
|
|
|
self.assertEqual(response['status'], True) |
|
43
|
|
|
|
|
44
|
|
|
@httpretty.activate |
|
45
|
|
|
def test_list(self): |
|
46
|
|
|
"""Function defined to test paystackapi plan list method.""" |
|
47
|
|
|
httpretty.register_uri( |
|
48
|
|
|
httpretty.GET, |
|
49
|
|
|
"https://api.paystack.co/plan", |
|
50
|
|
|
content_type='text/json', |
|
51
|
|
|
body='{"status": true, "contributors": true}', |
|
52
|
|
|
status=201, |
|
53
|
|
|
) |
|
54
|
|
|
|
|
55
|
|
|
response = Plan.list() |
|
56
|
|
|
self.assertEqual(response['status'], True) |
|
57
|
|
|
|
|
58
|
|
|
@httpretty.activate |
|
59
|
|
|
def test_update(self): |
|
60
|
|
|
"""Function defined to test paystackapi plan update.""" |
|
61
|
|
|
httpretty.register_uri( |
|
62
|
|
|
httpretty.PUT, |
|
63
|
|
|
"https://api.paystack.co/plan/78", |
|
64
|
|
|
content_type='text/json', |
|
65
|
|
|
body='{"status": true, "contributors": true}', |
|
66
|
|
|
status=201, |
|
67
|
|
|
) |
|
68
|
|
|
|
|
69
|
|
|
response = Plan.update(plan_id=78, interval="monthly", amount=70000) |
|
70
|
|
|
self.assertEqual(response['status'], True) |
|
71
|
|
|
|
|
72
|
|
|
if __name__ == '__main__': |
|
73
|
|
|
unittest.main(verbosity=2) |
|
74
|
|
|
|