forked from konomae/zaimpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzaim_test.py
executable file
·141 lines (112 loc) · 4.51 KB
/
zaim_test.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import
import os
import sys
import codecs
import unittest
from datetime import datetime
from datetime import timedelta
from pprint import pprint
from zaimapi import Zaim
sys.stdin = codecs.getreader('utf8')(sys.stdin)
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
consumer_key = unicode(os.environ.get("ZAIM_CONSUMER_KEY", ""))
consumer_secret = unicode(os.environ.get("ZAIM_CONSUMER_SECRET", ""))
access_token_key = unicode(os.environ.get("ZAIM_ACCESS_TOKEN_KEY", ""))
access_token_secret = unicode(os.environ.get("ZAIM_ACCESS_TOKEN_SECRET", ""))
assert consumer_key, 'Please set "ZAIM_CONSUMER_KEY".'
assert consumer_secret, 'Please set "ZAIM_CONSUMER_SECRET".'
assert access_token_key, 'Please set "ZAIM_ACCESS_TOKEN_KEY".'
assert access_token_secret, 'Please set "ZAIM_ACCESS_TOKEN_SECRET".'
zaim = Zaim(consumer_key, consumer_secret, access_token_key, access_token_secret)
class ZaimClassTestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_get_genres(self):
self.assertTrue(zaim.get_genres(self))
def test_get_genres_by_name(self):
genre = zaim.get_genre_by_name(u"食料品")
genre_org = {
u'active': 1,
u'category_id': 101,
u'created': u'2000-01-01 00:00:00',
u'id': 10101,
u'modified': u'2000-01-01 00:00:00',
u'name': u'\u98df\u6599\u54c1',
u'parent_genre_id': 10101,
u'sort': 1
}
self.assertEqual(genre,genre_org)
def test_get_genres_by_name_not_exist(self):
with self.assertRaises(ValueError) as e:
zaim.get_genre_by_name(u"not exist")
def test_get_genre_id_by_name(self):
self.assertTrue(zaim.get_genre_id_by_name(u"食料品"))
def test_get_categories(self):
self.assertTrue(zaim.get_categories(self))
def test_get_category_by_name(self):
category = zaim.get_category_by_name(u"食費")
category_org = {
u'active': 1,
u'budget': 30000,
u'calc': u'variable',
u'color': u'#3a9625',
u'created': u'2000-01-01 00:00:00',
u'id': 101,
u'image': u'restaurant',
u'mode': u'payment',
u'modified': u'2000-01-01 00:00:00',
u'name': u'\u98df\u8cbb',
u'parent_category_id': 101,
u'sort': 1
}
self.assertEqual(category,category_org)
def test_get_category_by_name_not_exist(self):
with self.assertRaises(ValueError) as e:
zaim.get_category_by_name(u"not exist")
def test_get_category_id_by_name(self):
self.assertTrue(zaim.get_category_id_by_name(u"食費"))
def test_get_user(self):
self.assertTrue(zaim.get_user())
def test_get_user_id(self):
self.assertTrue(zaim.get_user_id())
def test_get_accounts(self):
self.assertTrue(zaim.get_accounts())
def test_get_account_by_name(self):
self.assertTrue(zaim.get_account_by_name(u"お財布"))
def test_get_account_by_name_not_exist(self):
with self.assertRaises(ValueError) as e:
zaim.get_account_by_name(u"not exist")
def test_get_currencies(self):
self.assertTrue(zaim.get_currencies())
def test_get_money_records(self):
self.assertTrue(zaim.get_money_records())
def test_get_money_record_by_id_not_exist(self):
with self.assertRaises(ValueError) as e:
zaim.get_money_record_by_id(u"0")
def test_create_delete_pay(self):
date = datetime.today() + timedelta(days=31)
param = {
'category_id': zaim.get_category_id_by_name(u"食費"),
'genre_id': zaim.get_genre_id_by_name(u"食料品"),
'amount': '200,000',
'date': date,
'comment': 'API: Test',
'from_account_id': zaim.get_user_id(),
}
ret = zaim.create_pay(**param)
self.assertTrue(ret["money"]["id"])
record = zaim.get_money_record_by_id(ret["money"]["id"])
self.assertTrue(record)
self.assertEqual(record["amount"],200000)
last_money_id = ret["money"]["id"]
ret = zaim.delete_pay(last_money_id)
self.assertTrue(ret["money"]["id"])
def test_delete_pay_not_exist(self):
with self.assertRaises(ValueError) as e:
zaim.delete_pay(u"1")
if __name__ == '__main__':
unittest.main()