def test_request_token_with_specified_key(self): key = RestSetup.get_test_vars()["keys"][1] token_details = self.ably.auth.request_token( key_name=key["key_name"], key_secret=key["key_secret"]) assert token_details.token is not None, "Expected token" assert key.get( "capability") == token_details.capability, "Unexpected capability"
def test_request_token_with_specified_key(self): key = RestSetup.get_test_vars()["keys"][1] token_details = self.ably.auth.request_token( key_name=key["key_name"], key_secret=key["key_secret"]) self.assertIsNotNone(token_details.token, msg="Expected token") self.assertEqual(key.get("capability"), token_details.capability, msg="Unexpected capability")
def setUpClass(cls): RestSetup._RestSetup__test_vars = None test_vars = RestSetup.get_test_vars() cls.ably = AblyRest(key=test_vars["keys"][0]["key_str"], rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"]) cls.ably_text = AblyRest(key=test_vars["keys"][0]["key_str"], rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"], use_binary_protocol=False) cls.last_year = datetime.now().year - 1 cls.previous_year = datetime.now().year - 2 cls.last_interval = datetime(cls.last_year, 2, 3, 15, 5) cls.previous_interval = datetime(cls.previous_year, 2, 3, 15, 5) previous_year_stats = 120 stats = [ { 'intervalId': Stats.to_interval_id(cls.last_interval - timedelta(minutes=2), 'minute'), 'inbound': {'realtime': {'messages': {'count': 50, 'data': 5000}}}, 'outbound': {'realtime': {'messages': {'count': 20, 'data': 2000}}} }, { 'intervalId': Stats.to_interval_id(cls.last_interval - timedelta(minutes=1), 'minute'), 'inbound': {'realtime': {'messages': {'count': 60, 'data': 6000}}}, 'outbound': {'realtime': {'messages': {'count': 10, 'data': 1000}}} }, { 'intervalId': Stats.to_interval_id(cls.last_interval, 'minute'), 'inbound': {'realtime': {'messages': {'count': 70, 'data': 7000}}}, 'outbound': {'realtime': {'messages': {'count': 40, 'data': 4000}}}, 'persisted': {'presence': {'count': 20, 'data': 2000}}, 'connections': {'tls': {'peak': 20, 'opened': 10}}, 'channels': {'peak': 50, 'opened': 30}, 'apiRequests': {'succeeded': 50, 'failed': 10}, 'tokenRequests': {'succeeded': 60, 'failed': 20}, } ] previous_stats = [] for i in range(previous_year_stats): previous_stats.append( { 'intervalId': Stats.to_interval_id(cls.previous_interval - timedelta(minutes=i), 'minute'), 'inbound': {'realtime': {'messages': {'count': i}}} } ) cls.ably.http.post('/stats', native_data=stats + previous_stats)
from __future__ import absolute_import from datetime import datetime, timedelta import pytest import six import responses from ably.http.paginatedresult import PaginatedResult from ably.types.presence import PresenceMessage from test.ably.utils import dont_vary_protocol, VaryByProtocolTestsMetaclass, BaseTestCase from test.ably.restsetup import RestSetup test_vars = RestSetup.get_test_vars() @six.add_metaclass(VaryByProtocolTestsMetaclass) class TestPresence(BaseTestCase): @classmethod def setUpClass(cls): cls.ably = RestSetup.get_ably_rest() cls.channel = cls.ably.channels.get('persisted:presence_fixtures') @classmethod def tearDownClass(cls): cls.ably.channels.release('persisted:presence_fixtures') def setUp(self): self.ably.options.use_binary_protocol = True
import six import msgpack import responses from ably import AblyRest from ably.http.paginatedresult import PaginatedResult from ably.types.presence import (PresenceMessage, make_encrypted_presence_response_handler) from ably import ChannelOptions from ably.util.crypto import get_default_params from test.ably.utils import dont_vary_protocol, VaryByProtocolTestsMetaclass, BaseTestCase from test.ably.restsetup import RestSetup test_vars = RestSetup.get_test_vars() @six.add_metaclass(VaryByProtocolTestsMetaclass) class TestPresence(BaseTestCase): def setUp(self): self.ably = AblyRest(test_vars["keys"][0]["key_str"], rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"]) self.per_protocol_setup(True) def per_protocol_setup(self, use_binary_protocol): # This will be called every test that vary by protocol for each protocol
def setUpClass(cls): RestSetup._RestSetup__test_vars = None test_vars = RestSetup.get_test_vars() cls.ably = AblyRest(key=test_vars["keys"][0]["key_str"], rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"]) cls.ably_text = AblyRest(key=test_vars["keys"][0]["key_str"], rest_host=test_vars["host"], port=test_vars["port"], tls_port=test_vars["tls_port"], tls=test_vars["tls"], use_binary_protocol=False) cls.last_year = datetime.now().year - 1 cls.previous_year = datetime.now().year - 2 cls.last_interval = datetime(cls.last_year, 2, 3, 15, 5) cls.previous_interval = datetime(cls.previous_year, 2, 3, 15, 5) previous_year_stats = 120 stats = [{ 'intervalId': Stats.to_interval_id(cls.last_interval - timedelta(minutes=2), 'minute'), 'inbound': { 'realtime': { 'messages': { 'count': 50, 'data': 5000 } } }, 'outbound': { 'realtime': { 'messages': { 'count': 20, 'data': 2000 } } } }, { 'intervalId': Stats.to_interval_id(cls.last_interval - timedelta(minutes=1), 'minute'), 'inbound': { 'realtime': { 'messages': { 'count': 60, 'data': 6000 } } }, 'outbound': { 'realtime': { 'messages': { 'count': 10, 'data': 1000 } } } }, { 'intervalId': Stats.to_interval_id(cls.last_interval, 'minute'), 'inbound': { 'realtime': { 'messages': { 'count': 70, 'data': 7000 } } }, 'outbound': { 'realtime': { 'messages': { 'count': 40, 'data': 4000 } } }, 'persisted': { 'presence': { 'count': 20, 'data': 2000 } }, 'connections': { 'tls': { 'peak': 20, 'opened': 10 } }, 'channels': { 'peak': 50, 'opened': 30 }, 'apiRequests': { 'succeeded': 50, 'failed': 10 }, 'tokenRequests': { 'succeeded': 60, 'failed': 20 }, }] previous_stats = [] for i in range(previous_year_stats): previous_stats.append({ 'intervalId': Stats.to_interval_id( cls.previous_interval - timedelta(minutes=i), 'minute'), 'inbound': { 'realtime': { 'messages': { 'count': i } } } }) cls.ably.http.post('/stats', native_data=stats + previous_stats)
def setup_package(): RestSetup.get_test_vars()
def event_loop(): loop = asyncio.get_event_loop_policy().new_event_loop() loop.run_until_complete(RestSetup.get_test_vars()) yield loop loop.run_until_complete(RestSetup.clear_test_vars())
def setup(): RestSetup.get_test_vars() yield RestSetup.clear_test_vars()
def setup_package(): RestSetup.get_test_vars()
def test_request_token_with_specified_key(self): key = RestSetup.get_test_vars()["keys"][1] token_details = self.ably.auth.request_token( key_name=key["key_name"], key_secret=key["key_secret"]) assert token_details.token is not None, "Expected token" assert key.get("capability") == token_details.capability, "Unexpected capability"