-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
0 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
Empty file.
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,34 @@ | ||
import logging | ||
from ably.rest.auth import Auth | ||
from ably.types.options import Options | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
class AblyRealtime: | ||
"""Ably Realtime Client""" | ||
|
||
def __init__(self, key=None, **kwargs): | ||
"""Create an AblyRealtime instance. | ||
:Parameters: | ||
**Credentials** | ||
- `key`: a valid ably key string | ||
""" | ||
|
||
if key is not None: | ||
options = Options(key=key, **kwargs) | ||
else: | ||
options = Options(**kwargs) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
self.__auth = Auth(self, options) | ||
|
||
self.__options = options | ||
|
||
@property | ||
def auth(self): | ||
return self.__auth | ||
|
||
@property | ||
def options(self): | ||
return self.__options |
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,21 @@ | ||
import pytest | ||
from ably import Auth, AblyRealtime | ||
from ably.util.exceptions import AblyAuthException | ||
from test.ably.utils import BaseAsyncTestCase | ||
|
||
|
||
class TestRealtimeAuth(BaseAsyncTestCase): | ||
async def setUp(self): | ||
self.invalid_key = "some key" | ||
self.valid_key_format = "Vjhddw.owt:R97sjjbdERJdjwer" | ||
|
||
def test_auth_with_correct_key_format(self): | ||
key = self.valid_key_format.split(":") | ||
ably = AblyRealtime(self.valid_key_format) | ||
assert Auth.Method.BASIC == ably.auth.auth_mechanism, "Unexpected Auth method mismatch" | ||
assert ably.auth.auth_options.key_name == key[0] | ||
assert ably.auth.auth_options.key_secret == key[1] | ||
|
||
def test_auth_incorrect_key_format(self): | ||
with pytest.raises(AblyAuthException): | ||
ably = AblyRealtime(self.invalid_key) |
Should raise an error if key isn't provided since we only support basic auth at the moment