def groups(): if 'access_token' not in session: return redirect(url_for("home")) sObj = Splitwise(Config.consumer_key, Config.consumer_secret) sObj.setAccessToken(session['access_token']) groups = sObj.getGroups() #Get a list of grpups object group_list = [] #group list bal_list = [] #Balance list for group in groups: group_list.append(group.getName()) print(group.getName()) group_bal = [] for debt in group.getSimplifiedDebts(): group_bal.append( (debt.getFromUser(), debt.getToUser(), debt.getAmount())) print(debt.getFromUser(), debt.getToUser(), debt.getAmount()) bal_list.append(group_bal) output = {'groups': group_list, 'balances': bal_list} return jsonify(output)
def addUser(first,last,email): sObj = Splitwise(consumer_key, secret_key) sObj.setAccessToken(session['access_token']) user = createUser(first,last,email) groups = sObj.getGroups() for group in groups: if group.getName() == 'The Room': group.setMembers(group.getMembers().extend([user]))
def groupMembersString(groupName): sObj = Splitwise(consumer_key, secret_key) sObj.setAccessToken(session['access_token']) friends = None for group in sObj.getGroups(): if group.getName() == groupName: friends = group return [friend.getFirstName() + ' ' + friend.getLastName() for friend in friends.getMembers()]
def analyzer(): if 'access_token' not in session: return redirect(url_for("home")) sObj = Splitwise(Config.consumer_key, Config.consumer_secret) sObj.setAccessToken(session['access_token']) groups = sObj.getGroups() group = [x for x in groups if x.name == "88 Chemin 2018"][0] group.members.sort(key=wallstreet.get_index_for_dude) expenses = sObj.getExpenses(group_id=group.id, limit=10000, dated_after=datetime.datetime(2017, 5, 1)) matrix = payment_matrix(expenses) wallstreet.print_matrix(matrix) simplified_matrix = simplify_matrix(deepcopy(matrix)) wallstreet.print_matrix(simplified_matrix) return render_template("payment_matrix.html", users=group.members, matrix=matrix, simplified_matrix=simplified_matrix)
def transaction(Description, Group, Payer, Price, Contributors): # price, date, description, group ID or this particular groups name, members sObj = Splitwise(consumer_key, secret_key) sObj.setAccessToken(session['access_token']) user = sObj.getCurrentUser() groups = sObj.getGroups() group_dict = {group.getName(): group for group in groups} importedData = {'Date': datetime.datetime.now(), 'Description': Description, 'Group': Group, 'Payer': Payer, 'Debit': Price} expense = Expense() price = float(importedData['Debit'] or 0) expense.setCost(price) expense.setDate(importedData['Date']) expense.setDescription(importedData['Description']) expense.setGroupId(group_dict[importedData['Group']].getId()) members = group_dict[importedData['Group']].getMembers() users = [] contributors = Contributors for member in members: if member.getFirstName() in contributors: user = ExpenseUser() user.setId(member.getId()) if member.getFirstName() == importedData['Payer']: user.setPaidShare(price) else: user.setPaidShare(0) users.append(user) paid = 0 share = round(price/len(users), 2) for user in users: user.setOwedShare(share) paid = paid + share diff = price - paid if diff != 0: user = random.choice(users) user.setOwedShare(share + diff) expense.setUsers(users) expense = sObj.createExpense(expense)
class SplitwiseImporter: def __init__(self, Secrets): self.ynab_budget_id = Secrets.getSecret( 'splitwise.ynab_budget_id').strip() self.ynab_splitwise_account_id = Secrets.getSecret( 'splitwise.ynab_splitwise_account_id').strip() self.splitwise_group_names = Secrets.getSecret( 'splitwise.splitwise_group_names') self.dated_after = Secrets.getSecret( 'splitwise.import_dated_after') or None consumer_key = Secrets.getSecret('splitwise.consumer_key').strip() consumer_secret = Secrets.getSecret( 'splitwise.consumer_secret').strip() oauth_token = Secrets.getSecret('splitwise.oauth_token').strip() oauth_token_secret = Secrets.getSecret( 'splitwise.oauth_token_secret').strip() self.logger = logging.getLogger('splitwise') self.splitwise = Splitwise(consumer_key, consumer_secret) access_token = { 'oauth_token': oauth_token, 'oauth_token_secret': oauth_token_secret } self.splitwise.setAccessToken(access_token) self.currentUserId = self.splitwise.getCurrentUser().getId() self.spltiwise_group_double_map = {} groups = self.splitwise.getGroups() for g in groups: self.spltiwise_group_double_map[g.getId()] = g.getName() self.spltiwise_group_double_map[g.getName()] = g.getId() self.ynab_token = Secrets.getSecret("ynab_token").strip() self.ynabClient = YNAB(self.ynab_token) def generate_ynab_transaction(self, e): user = None for u in e.getUsers(): if u.getId() == self.currentUserId: user = u if not user: return {} memo_parts = [e.getDescription()] if e.getGroupId(): memo_parts.append( "splitwise-" + slugify(self.spltiwise_group_double_map[e.getGroupId()])) return TransactionRequest( self.ynab_splitwise_account_id, e.getDate(), int(float(user.getNetBalance()) * 1000), payee_name=(e.getDescription() if float(user.getNetBalance()) < 0 else "Splitwise Contribution"), memo=" ,".join(memo_parts), cleared="cleared", approved=False, import_id=e.getId()) def run(self): # expenses = self.splitwise.getExpenses(group_id=self.splitwise_group_id) transactions = [] if not len(self.splitwise_group_names): # None will get all groups self.splitwise_group_names = [None] for g in self.splitwise_group_names: # change group name to id if g: g = self.spltiwise_group_double_map[g] expenses = self.splitwise.getExpenses(dated_after=self.dated_after, group_id=g, limit=0) delta = 0 for e in expenses: if e.getDeletedAt(): continue transaction = self.generate_ynab_transaction(e) if transaction == {}: # self.logger.info("Got empty transaction for " + # e.getDescription()) continue transactions.append(transaction) delta += float(transaction.amount) if len(transactions): try: self.ynabClient.transactions.create_transactions( self.ynab_budget_id, transactions) self.logger.info("splitwise done") except Exception as e: self.logger.error( "Exception when calling ynab->create_transactions: %s\n" % e)
class GetGroupsTestCase(unittest.TestCase): def setUp(self): self.sObj = Splitwise('consumerkey', 'consumersecret') def test_getGroups_success(self, mockMakeRequest): mockMakeRequest.return_value = '{"groups":[{"id":0,"name":"Non-group expenses","created_at":"2012-08-21T16:11:14Z","updated_at":"2020-06-22T16:27:14Z","members":[{"id":79774,"first_name":"Naman","last_name":"Aggarwal","picture":{"small":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/small_mypic.jpg","medium":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/medium_mypic.jpg","large":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/large_mypic.jpg"},"custom_picture":true,"email":"*****@*****.**","registration_status":"confirmed","balance":[{"amount":"115000.0","currency_code":"INR"},{"amount":"2162.82","currency_code":"SGD"}]}],"simplify_by_default":false,"original_debts":[{"to":79774,"from":18145926,"amount":"115000.0","currency_code":"INR"},{"to":79774,"from":784241,"amount":"2162.82","currency_code":"SGD"}],"simplified_debts":[{"to":79774,"from":18145926,"amount":"115000.0","currency_code":"INR"},{"to":79774,"from":784241,"amount":"2162.82","currency_code":"SGD"}],"avatar":{"original":null,"xxlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-1000px.png","xlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-500px.png","large":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-200px.png","medium":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-100px.png","small":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-50px.png"},"custom_avatar":false,"cover_photo":{"xxlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_cover_photos/coverphoto-nongroup-1000px.png","xlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_cover_photos/coverphoto-nongroup-500px.png"}},{"id":10843533,"name":"Flatmates Again","created_at":"2019-01-01T06:01:57Z","updated_at":"2020-06-22T07:17:54Z","members":[{"id":79774,"first_name":"Naman","last_name":"Aggarwal","picture":{"small":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/small_mypic.jpg","medium":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/medium_mypic.jpg","large":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/large_mypic.jpg"},"custom_picture":true,"email":"*****@*****.**","registration_status":"confirmed","balance":[{"currency_code":"SGD","amount":"-20.13"}]},{"id":281236,"first_name":"Siddharth","last_name":"Goel","picture":{"small":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/small_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg","medium":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/medium_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg","large":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/large_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg"},"custom_picture":true,"email":"*****@*****.**","registration_status":"confirmed","balance":[{"currency_code":"SGD","amount":"978.02"}]},{"id":643871,"first_name":"Shantanu","last_name":"Alshi","picture":{"small":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-blue19-50px.png","medium":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-blue19-100px.png","large":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-blue19-200px.png"},"custom_picture":false,"email":"*****@*****.**","registration_status":"confirmed","balance":[{"currency_code":"SGD","amount":"-957.89"}]},{"id":784241,"first_name":"ruks","last_name":null,"picture":{"small":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-50px.png","medium":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-100px.png","large":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-200px.png"},"custom_picture":false,"email":"*****@*****.**","registration_status":"confirmed","balance":[{"currency_code":"SGD","amount":"0.0"}]}],"simplify_by_default":true,"original_debts":[{"from":281236,"to":79774,"amount":"2304.26","currency_code":"SGD"},{"currency_code":"SGD","from":79774,"to":643871,"amount":"2314.73"},{"currency_code":"SGD","from":79774,"to":784241,"amount":"9.66"},{"from":643871,"to":281236,"amount":"2520.67","currency_code":"SGD"},{"from":784241,"to":281236,"amount":"761.61","currency_code":"SGD"},{"currency_code":"SGD","from":643871,"to":784241,"amount":"751.95"}],"simplified_debts":[{"from":79774,"to":281236,"amount":"20.13","currency_code":"SGD"},{"from":643871,"to":281236,"amount":"957.89","currency_code":"SGD"}],"whiteboard":null,"group_type":"apartment","invite_link":"https://www.splitwise.com/join/d7bsHriQF5A+1pjy","avatar":{"original":"https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg","xxlarge":"https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/xxlarge_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg","xlarge":"https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/xlarge_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg","large":"https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/large_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg","medium":"https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/medium_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg","small":"https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/small_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg"},"custom_avatar":true,"cover_photo":{"xxlarge":"https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/xxlarge_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg","xlarge":"https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/xlarge_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg"}}]}' # noqa: E501 groups = self.sObj.getGroups() mockMakeRequest.assert_called_with( "https://secure.splitwise.com/api/v3.0/get_groups") self.assertEqual(len(groups), 2) self.assertEqual(groups[0].getId(), 0) self.assertEqual(groups[0].getName(), "Non-group expenses") self.assertEqual(groups[0].getUpdatedAt(), "2020-06-22T16:27:14Z") self.assertEqual(len(groups[0].getMembers()), 1) self.assertEqual(groups[0].getMembers()[0].getId(), 79774) self.assertEqual(groups[0].getMembers()[0].getFirstName(), "Naman") self.assertEqual(groups[0].getMembers()[0].getLastName(), "Aggarwal") self.assertEqual( groups[0].getMembers()[0].getPicture().getSmall(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/small_mypic.jpg" ) self.assertEqual( groups[0].getMembers()[0].getPicture().getMedium(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/medium_mypic.jpg" ) self.assertEqual( groups[0].getMembers()[0].getPicture().getLarge(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/large_mypic.jpg" ) self.assertEqual(groups[0].getMembers()[0].getEmail(), "*****@*****.**") self.assertEqual(groups[0].getMembers()[0].getRegistrationStatus(), "confirmed") self.assertEqual(len(groups[0].getMembers()[0].getBalances()), 2) self.assertEqual( groups[0].getMembers()[0].getBalances()[0].getAmount(), "115000.0") self.assertEqual( groups[0].getMembers()[0].getBalances()[0].getCurrencyCode(), "INR") self.assertEqual( groups[0].getMembers()[0].getBalances()[1].getAmount(), "2162.82") self.assertEqual( groups[0].getMembers()[0].getBalances()[1].getCurrencyCode(), "SGD") self.assertEqual(len(groups[0].getOriginalDebts()), 2) self.assertEqual(groups[0].getOriginalDebts()[0].getToUser(), 79774) self.assertEqual(groups[0].getOriginalDebts()[0].getFromUser(), 18145926) self.assertEqual(groups[0].getOriginalDebts()[0].getAmount(), "115000.0") self.assertEqual(groups[0].getOriginalDebts()[0].getCurrencyCode(), "INR") self.assertEqual(groups[0].getOriginalDebts()[1].getToUser(), 79774) self.assertEqual(groups[0].getOriginalDebts()[1].getFromUser(), 784241) self.assertEqual(groups[0].getOriginalDebts()[1].getAmount(), "2162.82") self.assertEqual(groups[0].getOriginalDebts()[1].getCurrencyCode(), "SGD") self.assertEqual(len(groups[0].getSimplifiedDebts()), 2) self.assertEqual(groups[0].getSimplifiedDebts()[0].getToUser(), 79774) self.assertEqual(groups[0].getSimplifiedDebts()[0].getFromUser(), 18145926) self.assertEqual(groups[0].getSimplifiedDebts()[0].getAmount(), "115000.0") self.assertEqual(groups[0].getSimplifiedDebts()[0].getCurrencyCode(), "INR") self.assertEqual(groups[0].getSimplifiedDebts()[1].getToUser(), 79774) self.assertEqual(groups[0].getSimplifiedDebts()[1].getFromUser(), 784241) self.assertEqual(groups[0].getSimplifiedDebts()[1].getAmount(), "2162.82") self.assertEqual(groups[0].getSimplifiedDebts()[1].getCurrencyCode(), "SGD") # self.assertEqual(groups[0].getAvatar().getOriginal(), None) # self.assertEqual(groups[0].getAvatar().getXxlarge(), # "https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-1000px.png") # self.assertEqual(groups[0].getAvatar().getXlarge(), # "https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-500px.png") # self.assertEqual(groups[0].getAvatar().getLarge(), # "https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-200px.png") # self.assertEqual(groups[0].getAvatar().getMedium(), # "https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-100px.png") # self.assertEqual(groups[0].getAvatar().getSmall(), # "https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-nongroup-50px.png") # self.assertEqual(groups[0].getCoverPhoto().getXxlarge( # ), "https://s3.amazonaws.com/splitwise/uploads/group/default_cover_photos/coverphoto-nongroup-1000px.png") # self.assertEqual(groups[0].getCoverPhoto().getXlarge( # ), "https://s3.amazonaws.com/splitwise/uploads/group/default_cover_photos/coverphoto-nongroup-500px.png") self.assertEqual(groups[1].getId(), 10843533) self.assertEqual(groups[1].getName(), "Flatmates Again") self.assertEqual(groups[1].getUpdatedAt(), "2020-06-22T07:17:54Z") self.assertEqual(len(groups[1].getMembers()), 4) self.assertEqual(groups[1].getMembers()[0].getId(), 79774) self.assertEqual(groups[1].getMembers()[0].getFirstName(), "Naman") self.assertEqual(groups[1].getMembers()[0].getLastName(), "Aggarwal") self.assertEqual( groups[1].getMembers()[0].getPicture().getSmall(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/small_mypic.jpg" ) self.assertEqual( groups[1].getMembers()[0].getPicture().getMedium(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/medium_mypic.jpg" ) self.assertEqual( groups[1].getMembers()[0].getPicture().getLarge(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/large_mypic.jpg" ) self.assertEqual(groups[1].getMembers()[0].getEmail(), "*****@*****.**") self.assertEqual(groups[1].getMembers()[0].getRegistrationStatus(), "confirmed") self.assertEqual(len(groups[1].getMembers()[0].getBalances()), 1) self.assertEqual( groups[1].getMembers()[0].getBalances()[0].getCurrencyCode(), "SGD") self.assertEqual( groups[1].getMembers()[0].getBalances()[0].getAmount(), "-20.13") self.assertEqual(groups[1].getMembers()[1].getId(), 281236) self.assertEqual(groups[1].getMembers()[1].getFirstName(), "Siddharth") self.assertEqual(groups[1].getMembers()[1].getLastName(), "Goel") self.assertEqual( groups[1].getMembers()[1].getPicture().getSmall(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/small_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg" ) self.assertEqual( groups[1].getMembers()[1].getPicture().getMedium(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/medium_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg" ) self.assertEqual( groups[1].getMembers()[1].getPicture().getLarge(), "https://splitwise.s3.amazonaws.com/uploads/user/avatar/281236/large_f5fccc37-0a88-4519-9398-59c8c19b92aa.jpeg" ) self.assertEqual(groups[1].getMembers()[1].getEmail(), "*****@*****.**") self.assertEqual(groups[1].getMembers()[1].getRegistrationStatus(), "confirmed") self.assertEqual(len(groups[1].getMembers()[1].getBalances()), 1) self.assertEqual( groups[1].getMembers()[1].getBalances()[0].getCurrencyCode(), "SGD") self.assertEqual( groups[1].getMembers()[1].getBalances()[0].getAmount(), "978.02") self.assertEqual(groups[1].getMembers()[2].getId(), 643871) self.assertEqual(groups[1].getMembers()[2].getFirstName(), "Shantanu") self.assertEqual(groups[1].getMembers()[2].getLastName(), "Alshi") self.assertEqual( groups[1].getMembers()[2].getPicture().getSmall(), "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-blue19-50px.png" ) self.assertEqual( groups[1].getMembers()[2].getPicture().getMedium(), "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-blue19-100px.png" ) self.assertEqual( groups[1].getMembers()[2].getPicture().getLarge(), "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-blue19-200px.png" ) self.assertEqual(groups[1].getMembers()[2].getEmail(), "*****@*****.**") self.assertEqual(groups[1].getMembers()[2].getRegistrationStatus(), "confirmed") self.assertEqual(len(groups[1].getMembers()[2].getBalances()), 1) self.assertEqual( groups[1].getMembers()[2].getBalances()[0].getCurrencyCode(), "SGD") self.assertEqual( groups[1].getMembers()[2].getBalances()[0].getAmount(), "-957.89") self.assertEqual(groups[1].getMembers()[3].getId(), 784241) self.assertEqual(groups[1].getMembers()[3].getFirstName(), "ruks") self.assertEqual(groups[1].getMembers()[3].getLastName(), None) self.assertEqual( groups[1].getMembers()[3].getPicture().getSmall(), "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-50px.png" ) self.assertEqual( groups[1].getMembers()[3].getPicture().getMedium(), "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-100px.png" ) self.assertEqual( groups[1].getMembers()[3].getPicture().getLarge(), "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-200px.png" ) self.assertEqual(groups[1].getMembers()[3].getEmail(), "*****@*****.**") self.assertEqual(groups[1].getMembers()[3].getRegistrationStatus(), "confirmed") self.assertEqual(len(groups[1].getMembers()[3].getBalances()), 1) self.assertEqual( groups[1].getMembers()[3].getBalances()[0].getCurrencyCode(), "SGD") self.assertEqual( groups[1].getMembers()[3].getBalances()[0].getAmount(), "0.0") self.assertEqual(len(groups[1].getOriginalDebts()), 6) self.assertEqual(groups[1].getOriginalDebts()[0].getFromUser(), 281236) self.assertEqual(groups[1].getOriginalDebts()[0].getToUser(), 79774) self.assertEqual(groups[1].getOriginalDebts()[0].getAmount(), "2304.26") self.assertEqual(groups[1].getOriginalDebts()[0].getCurrencyCode(), "SGD") self.assertEqual(groups[1].getOriginalDebts()[1].getCurrencyCode(), "SGD") self.assertEqual(groups[1].getOriginalDebts()[1].getFromUser(), 79774) self.assertEqual(groups[1].getOriginalDebts()[1].getToUser(), 643871) self.assertEqual(groups[1].getOriginalDebts()[1].getAmount(), "2314.73") self.assertEqual(groups[1].getOriginalDebts()[2].getCurrencyCode(), "SGD") self.assertEqual(groups[1].getOriginalDebts()[2].getFromUser(), 79774) self.assertEqual(groups[1].getOriginalDebts()[2].getToUser(), 784241) self.assertEqual(groups[1].getOriginalDebts()[2].getAmount(), "9.66") self.assertEqual(groups[1].getOriginalDebts()[3].getFromUser(), 643871) self.assertEqual(groups[1].getOriginalDebts()[3].getToUser(), 281236) self.assertEqual(groups[1].getOriginalDebts()[3].getAmount(), "2520.67") self.assertEqual(groups[1].getOriginalDebts()[3].getCurrencyCode(), "SGD") self.assertEqual(groups[1].getOriginalDebts()[4].getFromUser(), 784241) self.assertEqual(groups[1].getOriginalDebts()[4].getToUser(), 281236) self.assertEqual(groups[1].getOriginalDebts()[4].getAmount(), "761.61") self.assertEqual(groups[1].getOriginalDebts()[4].getCurrencyCode(), "SGD") self.assertEqual(groups[1].getOriginalDebts()[5].getCurrencyCode(), "SGD") self.assertEqual(groups[1].getOriginalDebts()[5].getFromUser(), 643871) self.assertEqual(groups[1].getOriginalDebts()[5].getToUser(), 784241) self.assertEqual(groups[1].getOriginalDebts()[5].getAmount(), "751.95") self.assertEqual(len(groups[1].getSimplifiedDebts()), 2) self.assertEqual(groups[1].getSimplifiedDebts()[0].getFromUser(), 79774) self.assertEqual(groups[1].getSimplifiedDebts()[0].getToUser(), 281236) self.assertEqual(groups[1].getSimplifiedDebts()[0].getAmount(), "20.13") self.assertEqual(groups[1].getSimplifiedDebts()[0].getCurrencyCode(), "SGD") self.assertEqual(groups[1].getSimplifiedDebts()[1].getFromUser(), 643871) self.assertEqual(groups[1].getSimplifiedDebts()[1].getToUser(), 281236) self.assertEqual(groups[1].getSimplifiedDebts()[1].getAmount(), "957.89") self.assertEqual(groups[1].getSimplifiedDebts()[1].getCurrencyCode(), "SGD") self.assertEqual(groups[1].getWhiteBoard(), None) self.assertEqual(groups[1].getType(), "apartment") self.assertEqual(groups[1].getInviteLink(), "https://www.splitwise.com/join/d7bsHriQF5A+1pjy") # self.assertEqual(groups[1].getAvatar().getOriginal( # ), # "https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg") # self.assertEqual(groups[1].getAvatar().getXxlarge( # ), # "https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/xxlarge_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg") # self.assertEqual(groups[1].getAvatar().getXlarge( # ), # "https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/xlarge_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg") # self.assertEqual(groups[1].getAvatar().getLarge( # ), # "https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/large_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg") # self.assertEqual(groups[1].getAvatar().getMedium( # ), # "https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/medium_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg") # self.assertEqual(groups[1].getAvatar().getSmall( # ), # "https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/small_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg") # self.assertEqual(groups[1].getCoverPhoto().getXxlarge( # ), # "https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/xxlarge_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg") # self.assertEqual(groups[1].getCoverPhoto().getXlarge( # ), # "https://splitwise.s3.amazonaws.com/uploads/group/avatar/10843533/xlarge_a3734b4d-817e-42f4-9763-8001b12e33b8.jpeg") def test_getGroups_exception(self, mockMakeRequest): mockMakeRequest.side_effect = Exception( "Invalid response %s. Please check your consumer key and secret." % 404) with self.assertRaises(Exception): self.sObj.getGroups() mockMakeRequest.assert_called_with( "https://secure.splitwise.com/api/v3.0/get_groups")