Skip to content

Commit

Permalink
Merge branch 'v0.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Feb 26, 2018
2 parents 0ddeba9 + 5bfbd2c commit 095f504
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions amazon_dash/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
{"pattern": "PATCH|patch"},
]
},
"headers": {
"type": "object",
},
"content-type": {
"type": "string"
},
Expand Down
4 changes: 2 additions & 2 deletions amazon_dash/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def execute(self, root_allowed=False):
:param bool root_allowed: Only used for ExecuteCmd
:return:
"""
kwargs = {}
kwargs = {'headers': self.data.get('headers', {})}
if self.data.get('content-type'):
kwargs['headers'] = {'content-type': self.data['content-type']}
kwargs['headers']['content-type'] = self.data['content-type']
if self.data.get('body'):
kwargs['data'] = self.data['body']
try:
Expand Down
1 change: 1 addition & 0 deletions amazon_dash/install/amazon-dash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ devices:
# name: Kit Kat
# url: 'http://domain.com/path/to/webhook' # Url to execute
# method: post # HTTP method. By default GET
# headers: {"authorization": "key"}
# content-type: json # Only available if Body is defined
# body: '{"mac": "AC:63:BE:67:B2:F1", "action": "toggleLight"}' # Request payload. Remember the quotes

Expand Down
12 changes: 12 additions & 0 deletions amazon_dash/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ def test_execute(self):
execute_url.execute()
self.assertTrue(self.get_mock.called_once)

def test_execute_headers(self):
self.session_mock.post(self.url, request_headers={'authorization': 'foo'})
execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post',
**{'headers': {'authorization': 'foo'}}))
execute_url.validate()
execute_url.execute()
execute_url2 = ExecuteUrl('key', dict(self.get_default_data(), method='post',
**{'headers': {'authorization': 'bar'}}))
execute_url2.validate()
with self.assertRaises(NoMockAddress):
execute_url2.execute()

def test_execute_content_type(self):
self.session_mock.post(self.url, request_headers={'content-type': 'foo'})
execute_url = ExecuteUrl('key', dict(self.get_default_data(), method='post',
Expand Down
1 change: 1 addition & 0 deletions docs/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Call url
When the **url execution method** is used, the following options are available.

* **method**: HTTP method. By default GET.
* **headers**: Headers to send to server. Content-Type will be overwritten if it is defined later.
* **content-type** (*): HTTP Content-Type Header. Only available if Body is defined. If body is defined, default is form.
* **body**: Request payload. Only if the method is POST/PUT/PATCH. In json or form mode, the content must be a valid json. It is recommended to use single quotes before and after content in json.

Expand Down

0 comments on commit 095f504

Please sign in to comment.