Skip to content
This repository was archived by the owner on Mar 18, 2019. It is now read-only.

Commit dff33a2

Browse files
committed
**params -> params
1 parent 9cd492a commit dff33a2

File tree

5 files changed

+21
-18
lines changed

5 files changed

+21
-18
lines changed

coreapi/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ def get(url):
4949
return session.get(url)
5050

5151

52-
def action(document, keys, **params):
52+
def action(document, keys, params=None):
5353
session = _default_session
54-
return session.action(document, keys, **params)
54+
return session.action(document, keys, params)
5555

5656

5757
def load(bytestring, content_type=None):

coreapi/commandline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def coerce_key_types(doc, keys):
3030
try:
3131
active = active[key]
3232
except (KeyError, IndexError, ValueError, TypeError):
33-
ret += keys[idx+1:]
33+
ret += keys[idx + 1:]
3434
break
3535

3636
return ret

coreapi/sessions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,13 @@ def get(self, url):
112112
link = Link(url, action='get')
113113
return transport.transition(link, session=self)
114114

115-
def action(self, document, keys, **params):
115+
def action(self, document, keys, params=None):
116116
if isinstance(keys, string_types):
117117
keys = [keys]
118118

119+
if params is None:
120+
params = {}
121+
119122
# Validate the keys and link parameters.
120123
link, link_ancestors = validate_keys_to_link(document, keys)
121124
validate_parameters(link, params)

tests/test_commandline.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from coreapi import Document, Link
2-
from coreapi.commandline import dotted_path_to_list
2+
from coreapi.commandline import coerce_key_types
33

44

55
# Test dotted path notation maps to list of keys correctly.
66

77
def test_dotted_path_notation():
88
doc = Document({'rows': [Document({'edit': Link()})]})
9-
keys = dotted_path_to_list(doc, 'rows.0.edit')
9+
keys = coerce_key_types(doc, ['rows', 0, 'edit'])
1010
assert keys == ['rows', 0, 'edit']
1111

1212

1313
def test_dotted_path_notation_with_invalid_array_lookup():
1414
doc = Document({'rows': [Document({'edit': Link()})]})
15-
keys = dotted_path_to_list(doc, 'rows.zero.edit')
15+
keys = coerce_key_types(doc, ['rows', 'zero', 'edit'])
1616
assert keys == ['rows', 'zero', 'edit']
1717

1818

1919
def test_dotted_path_notation_with_invalid_key():
2020
doc = Document({'rows': [Document({'edit': Link()})]})
21-
keys = dotted_path_to_list(doc, 'dummy.0.edit')
21+
keys = coerce_key_types(doc, ['dummy', '0', 'edit'])
2222
assert keys == ['dummy', '0', 'edit']

tests/test_transitions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def transition(self, link, params=None, session=None, link_ancestors=None):
1010
if link.action == 'get':
1111
document = Document(title='new', content={'new': 123})
1212
elif link.action in ('put', 'post'):
13-
document = Document(title='new', content={'new': 123, 'param': params.get('param')})
13+
document = Document(title='new', content={'new': 123, 'foo': params.get('foo')})
1414
else:
1515
document = None
1616

@@ -25,9 +25,9 @@ def doc():
2525
return Document(title='original', content={
2626
'nested': Document(content={
2727
'follow': Link(url='mock://example.com', action='get'),
28-
'action': Link(url='mock://example.com', action='post', transition='inline', fields=['param']),
29-
'create': Link(url='mock://example.com', action='post', fields=['param']),
30-
'update': Link(url='mock://example.com', action='put', fields=['param']),
28+
'action': Link(url='mock://example.com', action='post', transition='inline', fields=['foo']),
29+
'create': Link(url='mock://example.com', action='post', fields=['foo']),
30+
'update': Link(url='mock://example.com', action='put', fields=['foo']),
3131
'delete': Link(url='mock://example.com', action='delete')
3232
})
3333
})
@@ -42,20 +42,20 @@ def test_get(doc):
4242

4343

4444
def test_inline_post(doc):
45-
new = session.action(doc, ['nested', 'action'], param=123)
46-
assert new == {'nested': {'new': 123, 'param': 123}}
45+
new = session.action(doc, ['nested', 'action'], params={'foo': 123})
46+
assert new == {'nested': {'new': 123, 'foo': 123}}
4747
assert new.title == 'original'
4848

4949

5050
def test_post(doc):
51-
new = session.action(doc, ['nested', 'create'], param=456)
52-
assert new == {'new': 123, 'param': 456}
51+
new = session.action(doc, ['nested', 'create'], params={'foo': 456})
52+
assert new == {'new': 123, 'foo': 456}
5353
assert new.title == 'new'
5454

5555

5656
def test_put(doc):
57-
new = session.action(doc, ['nested', 'update'], param=789)
58-
assert new == {'nested': {'new': 123, 'param': 789}}
57+
new = session.action(doc, ['nested', 'update'], params={'foo': 789})
58+
assert new == {'nested': {'new': 123, 'foo': 789}}
5959
assert new.title == 'original'
6060

6161

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy