Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
Added Account api
Browse files Browse the repository at this point in the history
  • Loading branch information
avbel committed Nov 7, 2016
1 parent a31aeb8 commit 26e222f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = spaces
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
6 changes: 2 additions & 4 deletions bandwidth/catapult/account.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class AccountMixin:
def get_account(self):
data, _, _ = self._make_request('get', '/users/%s/account' % self.user_id)
return data
return self._make_request('get', '/users/%s/account' % self.user_id)[0]

def get_account_transactions(self, query=None):
data, _, _ = self._make_request('get', '/users/%s/transactions' % self.user_id, params=query)
return data
return self._make_request('get', '/users/%s/account/transactions' % self.user_id, params=query)[0]
2 changes: 2 additions & 0 deletions tests/catapult/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ def create_response(status_code = 200, content = '', content_type = 'application
response.headers['content-type'] = content_type
response._content = content
return response

AUTH = ('apiToken', 'apiSecret')
37 changes: 37 additions & 0 deletions tests/catapult/test_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import unittest
import six
import requests
import helpers
if six.PY3:
from unittest.mock import patch
else:
from mock import patch

from bandwidth.catapult import Client

class AccountTests(unittest.TestCase):
def test_get_account(self):
"""
get_account() should return account data
"""
estimated_json="""
{"balance": "538.37250","accountType":"pre-pay"}
"""
with patch('requests.request', return_value = helpers.create_response(200, estimated_json)) as p:
client = helpers.get_client()
data = client.get_account()
p.assert_called_with('get', 'https://api.catapult.inetwork.com/v1/users/userId/account', auth=helpers.AUTH)
self.assertEqual('pre-pay', data['accountType'])

def test_get_account_transactions(self):
"""
get_account_transactions() should return account transactions
"""
estimated_json="""
[{"id": "transactionId1", "time": "2013-02-21T13:39:09Z","amount": "0.00750","type": "charge","units": "1","productType": "sms-out","number": "1234567890"}]
"""
with patch('requests.request', return_value = helpers.create_response(200, estimated_json)) as p:
client = helpers.get_client()
data = client.get_account_transactions()
p.assert_called_with('get', 'https://api.catapult.inetwork.com/v1/users/userId/account/transactions', auth=helpers.AUTH, params=None)
self.assertEqual('transactionId1', data[0]['id'])

0 comments on commit 26e222f

Please sign in to comment.