Skip to content

Commit 9d13e4c

Browse files
committed
fix merge conflicts
2 parents 18541c1 + c5e192f commit 9d13e4c

File tree

71 files changed

+185
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+185
-9
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Online Marketplace Payments
44

55
[![Build Status](https://secure.travis-ci.org/balanced/balanced-python.png?branch=master)](http://travis-ci.org/balanced/balanced-python)
66

7+
**v1.x requires Balanced API 1.1. Use [v0.x](https://github.com/balanced/balanced-python/tree/rev0) for Balanced API 1.0.**
8+
79
## Installation
810

911
pip install balanced

balanced/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import unicode_literals
22

3-
__version__ = '1.beta3'
3+
__version__ = '1.0.1'
44

55
from balanced.config import configure
66
from balanced import resources

balanced/exc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77

88
class BalancedError(Exception):
9-
pass
9+
10+
def __str__(self):
11+
attrs = ', '.join([
12+
'{0}={1}'.format(k, repr(v))
13+
for k, v in self.__dict__.iteritems()
14+
])
15+
return '{0}({1})'.format(self.__class__.__name__, attrs)
1016

1117

1218
class ResourceError(BalancedError):

balanced/resources.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def items(self):
132132
# there is no resources key in the response from server
133133
# if the list is empty, so when we try to get something like
134134
# `debits`, an AttributeError will be raised. Not sure is this
135-
# behavior a bug of server, but anyway, this is just a workaround here
136-
# for solving the problem. The issue was posted here
135+
# behavior a bug of server, but anyway, this is just a workaround
136+
# here for solving the problem. The issue was posted here
137137
# https://github.com/balanced/balanced-python/issues/93
138138
return []
139139

@@ -186,7 +186,8 @@ def __getattr__(self, item):
186186
if suffix not in item:
187187
href = getattr(self, item + suffix, None)
188188
if href:
189-
setattr(self, item, Resource.get(href))
189+
item_type = Resource.registry.get(item + 's', Resource)
190+
setattr(self, item, item_type.get(href))
190191
return getattr(self, item)
191192
raise AttributeError(
192193
"'{0}' has no attribute '{1}'".format(

examples/bank_account_debits.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,15 @@ def main():
3535

3636
print 'PROTIP: for TEST bank accounts the valid amount is always 1 and 1'
3737
try:
38-
verification.confirm(amount_1=1, amount_2=1)
38+
verification.confirm(amount_1=1, amount_2=2)
3939
except balanced.exc.BankAccountVerificationFailure as ex:
4040
print 'Authentication error , %s' % ex.message
4141

42+
# reload
43+
verification = balanced.BankAccount.fetch(
44+
bank_account.href
45+
).bank_account_verification
46+
4247
if verification.confirm(1, 1).verification_status != 'succeeded':
4348
raise Exception('unpossible')
4449
debit = bank_account.debit(100)

render_scenarios.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
import glob2
22
import os
33
import json
4+
import balanced
5+
import pprint
6+
from pprint import PrettyPrinter
47
from mako.template import Template
58
from mako.lookup import TemplateLookup
69

10+
def construct_response(scenario_name):
11+
# load up response data
12+
data = json.load(open('scenario.cache','r'))
13+
lookup = TemplateLookup(directories=['./scenarios'])
14+
15+
for path in glob2.glob('./scenarios/**/request.mako'):
16+
if path != scenario_name:
17+
continue
18+
event_name = path.split('/')[-2]
19+
template = Template("${response}")
20+
try:
21+
response = data[event_name].get('response', {})
22+
text = template.render(response=response).strip()
23+
response = json.loads(text)
24+
del response["links"]
25+
for key, value in response.items():
26+
response = value[0]
27+
type = key
28+
resource = balanced.Resource()
29+
object_type = resource.registry[type]
30+
object_instance = object_type()
31+
for key, value in response.items():
32+
setattr(object_instance, key, value)
33+
text = template.render(response=object_instance)
34+
except KeyError:
35+
text = ''
36+
return text
37+
738
def render_executables():
839
# load up scenario data
940
data = json.load(open('scenario.cache','r'))
1041
lookup = TemplateLookup(directories=['./scenarios'])
11-
42+
1243
for path in glob2.glob('./scenarios/**/request.mako'):
1344
event_name = path.split('/')[-2]
1445
template = Template(filename=path, lookup=lookup,)
@@ -31,8 +62,10 @@ def render_mako():
3162
with open(os.path.join(dir, 'python.mako'), 'w+b') as wfile:
3263
definition = open(os.path.join(dir, 'definition.mako'),'r').read()
3364
request = open(os.path.join(dir, 'executable.py'),'r').read()
65+
response = construct_response(path)
3466
body = "% if mode == 'definition':\n{}".format(definition) + "\n" \
35-
"% elif mode == 'request':\n" + request + "\n% endif"
67+
"% elif mode == 'request':\n" + request + "\n" \
68+
"% elif mode == 'response':\n" + response + "\n% endif"
3669
wfile.write(body)
3770

3871
def issue_no_mako_warnings():

scenarios/_mj/_template/_create/python.mako

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ balanced.RESOURCE
33

44
% elif mode == 'request':
55

6+
% elif mode == 'response':
7+
68
% endif

scenarios/_mj/_template/_delete/python.mako

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
% elif mode == 'request':
44

5+
% elif mode == 'response':
6+
57
% endif

scenarios/_mj/_template/_list/python.mako

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
% elif mode == 'request':
44

5+
% elif mode == 'response':
6+
57
% endif

scenarios/_mj/_template/_retrieve/python.mako

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
% elif mode == 'request':
44

5+
% elif mode == 'response':
6+
57
% endif

0 commit comments

Comments
 (0)