Skip to content

Commit ca445bb

Browse files
author
Balanced Marshall
committed
merge master
2 parents 1b14767 + abdc04d commit ca445bb

File tree

13 files changed

+50
-33
lines changed

13 files changed

+50
-33
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: python
22
python:
3+
- 2.6
34
- 2.7
45
install:
56
- python setup.py develop

balanced/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.9.12'
1+
__version__ = '0.10.0'
22
from collections import defaultdict
33
import contextlib
44

balanced/http_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def handle_exception(response):
3434
response.deserialized = deserialized
3535
extra = deserialized.get('additional') or ''
3636
if extra:
37-
extra = ' -- {}.'.format(extra)
37+
extra = ' -- {0}.'.format(extra)
3838
error_msg = '{name}: {code}: {msg} {extra}'.format(
3939
name=deserialized['status'],
4040
code=deserialized['status_code'],
@@ -175,7 +175,7 @@ def deserialize(self, resp):
175175
try:
176176
return deserializers[resp.headers['Content-Type']](resp.content)
177177
except KeyError:
178-
raise exc.BalancedError('Invalid content type "{}": {}'.format(
178+
raise exc.BalancedError('Invalid content type "{0}": {1}'.format(
179179
resp.headers['Content-Type'], resp.content,
180180
))
181181

balanced/resources.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def from_response(cls, uri, **kwargs):
154154

155155
def __repr__(self):
156156
_resource = _RESOURCES.from_uri(self.uri)
157-
return '<Page{}{}>'.format(_resource, self.qs)
157+
return '<Page{0}{1}>'.format(_resource, self.qs)
158158

159159
def all(self):
160160
return list(self)
@@ -164,7 +164,7 @@ def one(self):
164164

165165
if len(ret) == 1:
166166
return ret[0]
167-
elif len(ret) == 0:
167+
elif not len(ret):
168168
raise NoResultFound(
169169
'Nothing found for one(). Make sure balanced.configure() '
170170
'is invoked with your API key secret')
@@ -241,18 +241,18 @@ def filter(self, *args, **kwargs):
241241
query_arguments = {}
242242
for expression in args:
243243
if not isinstance(expression, FilterExpression):
244-
raise ValueError('"{}" is not a FilterExpression'.format(
244+
raise ValueError('"{0}" is not a FilterExpression'.format(
245245
expression))
246246
if expression.op == '=':
247-
f = '{}'.format(expression.field.name)
247+
f = '{0}'.format(expression.field.name)
248248
else:
249-
f = '{}[{}]'.format(expression.field.name, expression.op)
249+
f = '{0}[{1}]'.format(expression.field.name, expression.op)
250250
values = expression.value
251251
if not isinstance(values, (list, tuple)):
252252
values = [values]
253253
query_arguments[f] = ','.join(str(v) for v in values)
254254
for k, values in kwargs.iteritems():
255-
f = '{}'.format(k)
255+
f = '{0}'.format(k)
256256
if not isinstance(values, (list, tuple)):
257257
values = [values]
258258
v = ','.join(str(v) for v in values)
@@ -265,9 +265,9 @@ def sort(self, *args):
265265
sorts = []
266266
for expression in args:
267267
if not isinstance(expression, SortExpression):
268-
raise ValueError('"{}" is not a SortExpression'.format(
268+
raise ValueError('"{0}" is not a SortExpression'.format(
269269
expression))
270-
v = '{},{}'.format(
270+
v = '{0},{1}'.format(
271271
expression.field.name,
272272
'asc' if expression.ascending else 'desc')
273273
sorts.append(v)
@@ -326,7 +326,7 @@ def delete(self):
326326
def uri_discovery(resource):
327327
uri = resource.RESOURCE['collection']
328328
if resource.RESOURCE['resides_under_marketplace']:
329-
uri = '{}/{}'.format(
329+
uri = '{0}/{1}'.format(
330330
Marketplace.my_marketplace.uri,
331331
resource.RESOURCE['collection']
332332
)
@@ -434,7 +434,7 @@ def __init__(self, name):
434434
self.name = name
435435

436436
def __getattr__(self, name):
437-
return _ResourceField('{}.{}'.format(self.name, name))
437+
return _ResourceField('{0}.{1}'.format(self.name, name))
438438

439439
def asc(self):
440440
return SortExpression(self, ascending=True)
@@ -1172,11 +1172,11 @@ def __init__(self, field, op, value, inv_op):
11721172

11731173
def __invert__(self):
11741174
if self.inv_op is None:
1175-
raise TypeError('"{}" cannot be inverted', self)
1175+
raise TypeError('"{0}" cannot be inverted', self)
11761176
return FilterExpression(self.field, self.inv_op, self.value, self.op)
11771177

11781178
def __str__(self):
1179-
return '{} {} {}'.format(
1179+
return '{0} {1} {2}'.format(
11801180
self.field.name, self.field.op, self.field.values)
11811181

11821182

examples/examples.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
# what's my marketplace?
3131
if not balanced.Marketplace.my_marketplace:
3232
raise Exception("Marketplace.my_marketplace should not be nil")
33-
print "what's my marketplace?, easy: Marketplace.my_marketplace: {}".format(
33+
print "what's my marketplace?, easy: Marketplace.my_marketplace: {0}".format(
3434
balanced.Marketplace.my_marketplace
3535
)
3636

37-
print "My marketplace's name is: {}".format(marketplace.name)
37+
print "My marketplace's name is: {0}".format(marketplace.name)
3838
print "Changing it to TestFooey"
3939
marketplace.name = "TestFooey"
4040
marketplace.save()
41-
print "My marketplace name is now: {}".format(marketplace.name)
41+
print "My marketplace name is now: {0}".format(marketplace.name)
4242
if marketplace.name != 'TestFooey':
4343
raise Exception("Marketplace name is NOT TestFooey!")
4444

@@ -65,7 +65,7 @@
6565
marketplace = balanced.Marketplace.my_marketplace
6666
if marketplace.in_escrow != 1500:
6767
raise Exception("1500 is not in escrow! this is wrong")
68-
print "i have {} in escrow!".format(marketplace.in_escrow)
68+
print "i have {0} in escrow!".format(marketplace.in_escrow)
6969

7070
print "cool. now let me refund the full amount"
7171
refund = debit.refund() # the full amount!
@@ -115,4 +115,19 @@
115115
print "invalidating a bank account"
116116
bank_account.delete()
117117

118+
# a little filtering
119+
merchants = balanced.Account.query.filter(roles='merchant')
120+
buyers = balanced.Account.query.filter(roles='buyer')
121+
print (
122+
'we have {0} accounts, {1} with the role "buyer", '
123+
'and {2} with the role "merchant"'.format(
124+
balanced.Account.query.count(),
125+
buyers.count(),
126+
merchants.count(),
127+
)
128+
)
129+
130+
print 'here are our merchants: {0}'.format([a.name for a in merchants])
131+
print 'here are our buyers: {0}'.format([a.name for a in buyers])
132+
118133
print "and there you have it :)"

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ nose==1.1.2
22
bottle==0.10.9
33
nose-setenv
44
mock==0.8.0
5+
unittest2

tests/_responses/marketplaces.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def index(limit=10, offset=0, num=1, pages=1):
5757
items = []
5858
for _ in xrange(num):
5959
rand = int(random.random() * 10000)
60-
mp_uri = '/v1/marketplaces/TEST-MP-123-456-{}'.format(rand)
60+
mp_uri = '/v1/marketplaces/TEST-MP-123-456-{0}'.format(rand)
6161
rand = int(random.random() * 10000)
62-
ac_uri = mp_uri + '/accounts/AC123-456-{}'.format(rand)
62+
ac_uri = mp_uri + '/accounts/AC123-456-{0}'.format(rand)
6363

6464
items.append({
6565
'uri': mp_uri,

tests/acceptance_suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import balanced
77
import copy
88
import requests
9-
import unittest
9+
import unittest2 as unittest
1010

1111
from fixtures import cards, merchants, bank_accounts
1212

tests/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import mock
55
import warnings
66
import re
7-
import unittest
87

8+
import unittest2 as unittest
99
import requests
1010

1111
import balanced

tests/test_balanced.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unittest
1+
import unittest2 as unittest
22

33

44
class TestBalancedImportStar(unittest.TestCase):

0 commit comments

Comments
 (0)