Skip to content

Commit

Permalink
Support for plugin only request
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Lei committed Nov 10, 2016
1 parent 5a8a2cd commit 2196850
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions skygear/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _request_url(self, action_name):
def _payload(self, action_name, params):
payload = params.copy() if isinstance(params, dict) else {}
payload['action'] = action_name
payload['_from_plugin'] = True
if self.access_token:
payload['access_token'] = self.access_token
if self.api_key:
Expand Down
2 changes: 2 additions & 0 deletions skygear/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
UndefinedOperation = 117
PluginUnavailable = 118
PluginTimeout = 119
RecordQueryInvalid = 120
PluginInitializing = 121

UnexpectedError = 10000

Expand Down
5 changes: 5 additions & 0 deletions skygear/tests/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,27 @@ class TestContainer():
def test_payload_include_action(self):
c = SkygearContainer(endpoint='endpoint', access_token='access-token')
payload = c._payload('action:work', {'data': 'hello world'})
assert payload['_from_plugin']
assert payload['action'] == 'action:work'
assert payload['data'] == 'hello world'

def test_payload_include_api_key(self):
c = SkygearContainer(endpoint='endpoint', api_key='api-key')
payload = c._payload('action:work', {})
assert payload['_from_plugin']
assert payload['api_key'] == 'api-key'

def test_payload_include_user_id(self):
c = SkygearContainer(endpoint='endpoint', api_key='api-key',
user_id='user-id')
payload = c._payload('action:work', {})
assert payload['_user_id'] == 'user-id'
assert payload['_from_plugin']

def test_payload_include_access_token(self):
c = SkygearContainer(endpoint='endpoint', access_token='access-token')
payload = c._payload('action:work', {})
assert payload['_from_plugin']
assert payload['access_token'] == 'access-token'

def test_payload_include_all_credentials(self):
Expand All @@ -78,3 +82,4 @@ def test_payload_include_all_credentials(self):
assert payload['access_token'] == 'access-token'
assert payload['api_key'] == 'api-key'
assert payload['_user_id'] == 'user-id'
assert payload['_from_plugin']

0 comments on commit 2196850

Please sign in to comment.