Exemple #1
0
class GroupTestCase(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_group_flow(self):
        group = Group()
        group.setName("Splitwise_test_case")
        # Create Group
        group, error = self.sObj.createGroup(group)
        self.assertIsNotNone(group.getId())
        # Delete Group
        self.sObj.deleteGroup(group.getId())

    def test_group_invalidkeys_fail(self):
        sObj = Splitwise('consumerkey', 'consumersecret', {
            "oauth_token": "sdsd",
            "oauth_token_secret": "sdsdd"
        })
        group = Group()
        with self.assertRaises(SplitwiseUnauthorizedException):
            sObj.createGroup(group)
class DeleteGroupTestCase(unittest.TestCase):
    def setUp(self):
        self.sObj = Splitwise('consumerkey', 'consumersecret')

    def test_deleteGroup_success(self, mockMakeRequest):
        mockMakeRequest.return_value = '{"success":true}'  # noqa: E501
        success, errors = self.sObj.deleteGroup(19481273)
        mockMakeRequest.assert_called_with(
            "https://secure.splitwise.com/api/v3.0/delete_group/19481273",
            "POST")
        self.assertTrue(success)
        self.assertIsNone(errors)

    def test_deleteGroup_error(self, mockMakeRequest):
        mockMakeRequest.return_value = '{"success":false, "errors": {"base": ["some error occured"]}}'  # noqa: E501
        success, errors = self.sObj.deleteGroup(19481273)
        mockMakeRequest.assert_called_with(
            "https://secure.splitwise.com/api/v3.0/delete_group/19481273",
            "POST")
        self.assertFalse(success)
        self.assertIsNotNone(errors)

    def test_deleteGroup_notallowed_exception(self, mockMakeRequest):
        mockMakeRequest.side_effect = SplitwiseNotAllowedException("message")

        with self.assertRaises(SplitwiseNotAllowedException):
            self.sObj.deleteGroup(19481273)

        mockMakeRequest.assert_called_with(
            "https://secure.splitwise.com/api/v3.0/delete_group/19481273",
            "POST")

    def test_deleteGroup_notfound_exception(self, mockMakeRequest):
        mockMakeRequest.side_effect = SplitwiseNotFoundException("message")

        with self.assertRaises(SplitwiseNotFoundException):
            self.sObj.deleteGroup(19481273)

        mockMakeRequest.assert_called_with(
            "https://secure.splitwise.com/api/v3.0/delete_group/19481273",
            "POST")