-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from namaggarwal/ver-2.1.0
Ver 2.1.0
- Loading branch information
Showing
12 changed files
with
300 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest | ||
import os | ||
from splitwise import Splitwise | ||
from splitwise.expense import Expense | ||
from splitwise.exception import SplitwiseUnauthorizedException | ||
|
||
|
||
class ExpenseTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
consumer_key = os.environ['CONSUMER_KEY'] | ||
consumer_secret = os.environ['CONSUMER_SECRET'] | ||
oauth_token = os.environ['OAUTH_TOKEN'] | ||
oauth_token_secret = os.environ['OAUTH_TOKEN_SECRET'] | ||
|
||
self.sObj = Splitwise(consumer_key, consumer_secret) | ||
self.sObj.setAccessToken({'oauth_token': oauth_token, 'oauth_token_secret': oauth_token_secret}) | ||
|
||
def test_expense_flow(self): | ||
expense = Expense() | ||
expense.setDescription("End2EndTest") | ||
expense.setCost('10') | ||
expense.setGroupId(19571167) | ||
expense.setSplitEqually() | ||
# create expense | ||
expense, error = self.sObj.createExpense(expense) | ||
self.assertIsNone(error) | ||
self.assertIsNotNone(expense.getId()) | ||
# delete expense | ||
success, error = self.sObj.deleteExpense(expense.getId()) | ||
self.assertIsNone(error) | ||
self.assertTrue(success) | ||
|
||
def test_expense_invalidkeys_fail(self): | ||
sObj = Splitwise('consumerkey', 'consumersecret', {"oauth_token": "sdsd", "oauth_token_secret": "sdsdd"}) | ||
expense = Expense() | ||
with self.assertRaises(SplitwiseUnauthorizedException): | ||
sObj.createExpense(expense) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from splitwise import Splitwise | ||
from splitwise.exception import SplitwiseNotFoundException, SplitwiseNotAllowedException | ||
import unittest | ||
try: | ||
from unittest.mock import patch | ||
except ImportError: # Python 2 | ||
from mock import patch | ||
|
||
|
||
@patch('splitwise.Splitwise._Splitwise__makeRequest') | ||
class DeleteExpenseTestCase(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.sObj = Splitwise('consumerkey', 'consumersecret') | ||
|
||
def test_deleteExpense_success(self, mockMakeRequest): | ||
mockMakeRequest.return_value = '{"success":true}' # noqa: E501 | ||
success, errors = self.sObj.deleteExpense(19481273) | ||
mockMakeRequest.assert_called_with( | ||
"https://secure.splitwise.com/api/v3.0/delete_expense/19481273", "POST") | ||
self.assertTrue(success) | ||
self.assertIsNone(errors) | ||
|
||
def test_deleteExpense_error(self, mockMakeRequest): | ||
mockMakeRequest.return_value = '{"success":false, "errors": {"base": ["some error occured"]}}' # noqa: E501 | ||
success, errors = self.sObj.deleteExpense(19481273) | ||
mockMakeRequest.assert_called_with( | ||
"https://secure.splitwise.com/api/v3.0/delete_expense/19481273", "POST") | ||
self.assertFalse(success) | ||
self.assertIsNotNone(errors) | ||
|
||
def test_deleteExpense_notallowed_exception(self, mockMakeRequest): | ||
mockMakeRequest.side_effect = SplitwiseNotAllowedException( | ||
"message" | ||
) | ||
|
||
with self.assertRaises(SplitwiseNotAllowedException): | ||
self.sObj.deleteExpense(19481273) | ||
|
||
mockMakeRequest.assert_called_with( | ||
"https://secure.splitwise.com/api/v3.0/delete_expense/19481273", "POST") | ||
|
||
def test_deleteExpense_notfound_exception(self, mockMakeRequest): | ||
mockMakeRequest.side_effect = SplitwiseNotFoundException( | ||
"message" | ||
) | ||
|
||
with self.assertRaises(SplitwiseNotFoundException): | ||
self.sObj.deleteExpense(19481273) | ||
|
||
mockMakeRequest.assert_called_with( | ||
"https://secure.splitwise.com/api/v3.0/delete_expense/19481273", "POST") |
Oops, something went wrong.