Skip to content

Commit a4f0884

Browse files
committed
adding more tests
1 parent 99eb0b6 commit a4f0884

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/groupsplit.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def split(total, num_people):
4646
return base, extra
4747

4848
class Splitwise:
49-
def __init__(self, options, args):
50-
if os.path.isfile(options.api_client):
51-
with open(options.api_client, 'rb') as oauth_pkl:
49+
def __init__(self, api_client='oauth_client.pkl'):
50+
if os.path.isfile(api_client):
51+
with open(api_client, 'rb') as oauth_pkl:
5252
self.client = pickle.load(oauth_pkl)
5353
else:
5454
self.get_client()
@@ -129,6 +129,13 @@ def post_expense(self, uri):
129129
sys.stdout.write(".")
130130
sys.stdout.flush()
131131

132+
def delete_expense(self, expense_id):
133+
return self.api_call("https://secure.splitwise.com/api/v3.0/delete_expense/%s" % expense_id, 'POST')
134+
135+
def get_expenses(self, limit=0):
136+
resp = self.api_call("https://secure.splitwise.com/api/v3.0/get_expenses?limit=%s" % limit, 'GET')
137+
return resp['expenses']
138+
132139
class CsvSettings():
133140
def __init__(self, rows):
134141
print "These are the first two rows of your csv"
@@ -244,7 +251,7 @@ def main():
244251
parser.add_option('', '--api-client', default='oauth_client.pkl', dest='api_client', help='supply different splitwise api client (for testing mostly)')
245252
options, args = parser.parse_args()
246253
logger.setLevel(log_levels[options.verbosity])
247-
splitwise = Splitwise(options, args)
254+
splitwise = Splitwise(options.api_client)
248255
split_gen = SplitGenerator(options, args, splitwise)
249256
print "Uploading splits"
250257
for uri in split_gen:

test/testSplit.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import subprocess
44
from money import Money
55
sys.path.append("../src")
6-
from groupsplit import split
6+
from groupsplit import split, Splitwise
77

88
class UtilsTests(unittest.TestCase):
9+
def __init__(self, *args, **kwargs):
10+
super(UtilsTests, self).__init__(*args, **kwargs)
11+
self.api = Splitwise()
12+
913
def test_splits(self):
1014
cases = [
1115
{"amount": "1.00", "ppl": 2, "expect": ("0.50","0.00")},
@@ -18,13 +22,25 @@ def test_splits(self):
1822
expect = (Money(case['expect'][0], "CAD"), Money(case['expect'][1], "CAD"))
1923
self.assertEqual(expect, split(Money(case['amount'], "CAD"), case['ppl']))
2024

25+
def test_get_id(self):
26+
assertGreater(int(self.api.get_id()), 0)
27+
28+
def test_get_groups(self):
29+
self.assertGreater(len(self.api.get_groups()), 0)
30+
2131
class SystemTests(unittest.TestCase):
32+
def __del__(self):
33+
api = Splitwise()
34+
for expense in api.get_expenses():
35+
api.delete_expense(expense['id'])
36+
2237
def test_group_of_2(self):
2338
proc = subprocess.Popen(['python', '../src/groupsplit.py', 'transactions.csv', 'group_of_2',
2439
'--csv-settings=csv_settings.pkl', '--api-client=oauth_client.pkl',
2540
'-y'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
2641
stdout, stderr = proc.communicate()
2742
self.assertEqual(stderr, '')
43+
2844
def test_group_of_3(self):
2945
proc = subprocess.Popen(['python', '../src/groupsplit.py', 'transactions.csv', 'group_of_3',
3046
'--csv-settings=csv_settings.pkl', '--api-client=oauth_client.pkl',

0 commit comments

Comments
 (0)