-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from ggravlingen/fix_api_return_type
Ensure consistent API return type (breaking)
- Loading branch information
Showing
11 changed files
with
100 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
https://github.com/chrysn/aiocoap/archive/0df6a1e44582de99ae944b6a7536d08e2a612e8f.zip | ||
https://github.com/chrysn/aiocoap/archive/3286f48f0b949901c8b5c04c0719dc54ab63d431.zip | ||
DTLSSocket==0.1.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pytest | ||
pytest>=3.2.3 | ||
flake8 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"""Test API utilities.""" | ||
import asyncio | ||
import functools | ||
|
||
from pytradfri.api.aiocoap_api import api_factory | ||
from pytradfri.command import Command | ||
|
||
|
||
def async_test(f): | ||
@functools.wraps(f) | ||
def wrapper(*args, **kwargs): | ||
coro = asyncio.coroutine(f) | ||
future = coro(*args, **kwargs) | ||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(future) | ||
return wrapper | ||
|
||
|
||
class MockCode: | ||
@property | ||
def is_successful(self): | ||
return True | ||
|
||
|
||
class MockResponse: | ||
@property | ||
def code(self): | ||
return MockCode() | ||
|
||
@property | ||
def payload(self): | ||
return '{}'.encode('utf-8') | ||
|
||
|
||
class MockProtocol: | ||
@asyncio.coroutine | ||
def mock_response(self): | ||
return MockResponse() | ||
|
||
@property | ||
def response(self): | ||
return self.mock_response() | ||
|
||
|
||
class MockContext: | ||
def request(self, arg): | ||
return MockProtocol() | ||
|
||
|
||
@asyncio.coroutine | ||
def mock_create_context(loop): | ||
return MockContext() | ||
|
||
|
||
@async_test | ||
def test_request_returns_single(monkeypatch): | ||
monkeypatch.setattr('aiocoap.Context.create_client_context', | ||
mock_create_context) | ||
|
||
api = yield from api_factory('127.0.0.1', 'key') | ||
|
||
command = Command('', '') | ||
|
||
response = yield from api(command) | ||
|
||
assert type(response) != list | ||
|
||
|
||
@async_test | ||
def test_request_returns_list(monkeypatch): | ||
monkeypatch.setattr('aiocoap.Context.create_client_context', | ||
mock_create_context) | ||
|
||
api = yield from api_factory('127.0.0.1', 'key') | ||
|
||
command = Command('', '') | ||
|
||
response = yield from api([command, command, command]) | ||
|
||
assert type(response) == list |