Skip to content

Commit

Permalink
Reformatted code as per CI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Oct 1, 2023
1 parent cbf171a commit 65331d5
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 68 deletions.
4 changes: 2 additions & 2 deletions ably/rest/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def push(self):
return self.__push

@optional_sync
async def request(self, method: str, path: str, version: str, params:
Optional[dict] = None, body=None, headers=None):
async def request(self, method: str, path: str, version: str, params: Optional[dict] = None,
body=None, headers=None):
if version is None:
raise AblyException("No version parameter", 400, 40000)

Expand Down
22 changes: 11 additions & 11 deletions test/ably/sync/restauth_test.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import base64
import logging
import sys
import time
import uuid
import base64

from urllib.parse import parse_qs

import mock
import pytest
import respx
from httpx import Response, AsyncClient

import ably
from ably import AblyAuthException
from ably import AblyRest
from ably import Auth
from ably import AblyAuthException
from ably.types.tokendetails import TokenDetails

from test.ably.testapp import TestApp, TestAppSync
from test.ably.testapp import TestAppSync
from test.ably.utils import VaryByProtocolTestsMetaclass, dont_vary_protocol, BaseAsyncTestCase

if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -224,21 +223,21 @@ def test_with_token_str_https(self):
token = self.ably.auth.authorize()
token = token.token
ably = TestAppSync.get_ably_rest(key=None, token=token, tls=True,
use_binary_protocol=self.use_binary_protocol)
use_binary_protocol=self.use_binary_protocol)
ably.channels.test_auth_with_token_str.publish('event', 'foo_bar')
ably.close()

def test_with_token_str_http(self):
token = self.ably.auth.authorize()
token = token.token
ably = TestAppSync.get_ably_rest(key=None, token=token, tls=False,
use_binary_protocol=self.use_binary_protocol)
use_binary_protocol=self.use_binary_protocol)
ably.channels.test_auth_with_token_str.publish('event', 'foo_bar')
ably.close()

def test_if_default_client_id_is_used(self):
ably = TestAppSync.get_ably_rest(client_id='my_client_id',
use_binary_protocol=self.use_binary_protocol)
use_binary_protocol=self.use_binary_protocol)
token = ably.auth.authorize()
assert token.client_id == 'my_client_id'
ably.close()
Expand Down Expand Up @@ -335,7 +334,7 @@ def test_with_key(self):
ably.close()

ably = TestAppSync.get_ably_rest(key=None, token_details=token_details,
use_binary_protocol=self.use_binary_protocol)
use_binary_protocol=self.use_binary_protocol)
channel = self.get_channel_name('test_request_token_with_key')

ably.channels[channel].publish('event', 'foo')
Expand Down Expand Up @@ -402,6 +401,7 @@ def call_back(request):
status_code=200,
json={'issued': 1, 'token': 'another_token_string'}
)

auth_route.side_effect = call_back
token_details = ably.auth.request_token(
token_params=token_params, auth_url=url, auth_headers=headers,
Expand Down Expand Up @@ -442,8 +442,8 @@ def test_when_auth_url_has_query_string(self):
auth_route = respx.get('http://www.example.com', params={'with': 'query', 'spam': 'eggs'}).mock(
return_value=Response(status_code=200, content='token_string', headers={"Content-Type": "text/plain"}))
ably.auth.request_token(auth_url=url,
auth_headers=headers,
auth_params={'spam': 'eggs'})
auth_headers=headers,
auth_params={'spam': 'eggs'})
assert auth_route.called
ably.close()

Expand Down
3 changes: 1 addition & 2 deletions test/ably/sync/restcapability_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ably.types.capability import Capability
from ably.util.exceptions import AblyException
from test.ably.testapp import TestAppSync

from test.ably.utils import dont_vary_protocol, BaseAsyncTestCase, VaryByProtocolTestsMetaclass


Expand All @@ -22,7 +21,7 @@ def per_protocol_setup(self, use_binary_protocol):
def test_blanket_intersection_with_key(self):
key = self.test_vars['keys'][1]
token_details = self.ably.auth.request_token(key_name=key['key_name'],
key_secret=key['key_secret'])
key_secret=key['key_secret'])
expected_capability = Capability(key["capability"])
assert token_details.token is not None, "Expected token"
assert expected_capability == token_details.capability, "Unexpected capability."
Expand Down
14 changes: 7 additions & 7 deletions test/ably/sync/restchannelhistory_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging

import pytest
import respx

from ably import AblyException
from ably.http.paginatedresult import PaginatedResult

from test.ably.testapp import TestAppSync
from test.ably.utils import VaryByProtocolTestsMetaclass, dont_vary_protocol, BaseAsyncTestCase

Expand Down Expand Up @@ -39,13 +39,13 @@ def test_channel_history_types(self):

message_contents = {m.name: m for m in messages}
assert "This is a string message payload" == message_contents["history0"].data, \
"Expect history0 to be expected String)"
"Expect history0 to be expected String)"
assert b"This is a byte[] message payload" == message_contents["history1"].data, \
"Expect history1 to be expected byte[]"
"Expect history1 to be expected byte[]"
assert {"test": "This is a JSONObject message payload"} == message_contents["history2"].data, \
"Expect history2 to be expected JSONObject"
"Expect history2 to be expected JSONObject"
assert ["This is a JSONArray message payload"] == message_contents["history3"].data, \
"Expect history3 to be expected JSONObject"
"Expect history3 to be expected JSONObject"

expected_message_history = [
message_contents['history3'],
Expand Down Expand Up @@ -176,7 +176,7 @@ def test_channel_history_time_forwards(self):
history0.publish('history%d' % i, str(i))

history = history0.history(direction='forwards', start=interval_start,
end=interval_end)
end=interval_end)

messages = history.items
assert 20 == len(messages)
Expand All @@ -202,7 +202,7 @@ def test_channel_history_time_backwards(self):
history0.publish('history%d' % i, str(i))

history = history0.history(direction='backwards', start=interval_start,
end=interval_end)
end=interval_end)

messages = history.items
assert 20 == len(messages)
Expand Down
9 changes: 4 additions & 5 deletions test/ably/sync/restchannelpublish_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import msgpack
import pytest

from ably import api_version
from ably import AblyException, IncompatibleClientIdException
from ably import api_version
from ably.rest.auth import Auth
from ably.types.message import Message
from ably.types.tokendetails import TokenDetails
from ably.util import case

from test.ably.testapp import TestApp, TestAppSync
from test.ably.testapp import TestAppSync
from test.ably.utils import VaryByProtocolTestsMetaclass, dont_vary_protocol, BaseAsyncTestCase

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -298,8 +297,8 @@ def test_publish_message_with_client_id_on_identified_client(self):
def test_publish_message_with_wrong_client_id_on_implicit_identified_client(self):
new_token = self.ably.auth.authorize(token_params={'client_id': uuid.uuid4().hex})
new_ably = TestAppSync.get_ably_rest(key=None,
token=new_token.token,
use_binary_protocol=self.use_binary_protocol)
token=new_token.token,
use_binary_protocol=self.use_binary_protocol)

channel = new_ably.channels[
self.get_channel_name('persisted:wrong_client_id_implicit_client')]
Expand Down
1 change: 0 additions & 1 deletion test/ably/sync/restchannels_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from ably import AblyException
from ably.rest.channel import Channel, Channels, Presence
from ably.util.crypto import generate_random_key

from test.ably.testapp import TestAppSync
from test.ably.utils import BaseAsyncTestCase

Expand Down
24 changes: 12 additions & 12 deletions test/ably/sync/restchannelstatus_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ def test_channel_status(self):
assert channel_status is not None, "Expected non-None channel_status"
assert channel_name == channel_status.channel_id, "Expected channel name to match"
assert channel_status.status.is_active is True, "Expected is_active to be True"
assert isinstance(channel_status.status.occupancy.metrics.publishers, int) and\
channel_status.status.occupancy.metrics.publishers >= 0,\
assert isinstance(channel_status.status.occupancy.metrics.publishers, int) and \
channel_status.status.occupancy.metrics.publishers >= 0, \
"Expected publishers to be a non-negative int"
assert isinstance(channel_status.status.occupancy.metrics.connections, int) and\
channel_status.status.occupancy.metrics.connections >= 0,\
assert isinstance(channel_status.status.occupancy.metrics.connections, int) and \
channel_status.status.occupancy.metrics.connections >= 0, \
"Expected connections to be a non-negative int"
assert isinstance(channel_status.status.occupancy.metrics.subscribers, int) and\
channel_status.status.occupancy.metrics.subscribers >= 0,\
assert isinstance(channel_status.status.occupancy.metrics.subscribers, int) and \
channel_status.status.occupancy.metrics.subscribers >= 0, \
"Expected subscribers to be a non-negative int"
assert isinstance(channel_status.status.occupancy.metrics.presence_members, int) and\
channel_status.status.occupancy.metrics.presence_members >= 0,\
assert isinstance(channel_status.status.occupancy.metrics.presence_members, int) and \
channel_status.status.occupancy.metrics.presence_members >= 0, \
"Expected presence_members to be a non-negative int"
assert isinstance(channel_status.status.occupancy.metrics.presence_connections, int) and\
channel_status.status.occupancy.metrics.presence_connections >= 0,\
assert isinstance(channel_status.status.occupancy.metrics.presence_connections, int) and \
channel_status.status.occupancy.metrics.presence_connections >= 0, \
"Expected presence_connections to be a non-negative int"
assert isinstance(channel_status.status.occupancy.metrics.presence_subscribers, int) and\
channel_status.status.occupancy.metrics.presence_subscribers >= 0,\
assert isinstance(channel_status.status.occupancy.metrics.presence_subscribers, int) and \
channel_status.status.occupancy.metrics.presence_subscribers >= 0, \
"Expected presence_subscribers to be a non-negative int"
3 changes: 1 addition & 2 deletions test/ably/sync/resthttp_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import base64
import re
import time
from urllib.parse import urljoin

import httpx
import mock
import pytest
from urllib.parse import urljoin

import respx
from httpx import Response

Expand Down
3 changes: 1 addition & 2 deletions test/ably/sync/restpresence_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

from ably.http.paginatedresult import PaginatedResult
from ably.types.presence import PresenceMessage

from test.ably.utils import dont_vary_protocol, VaryByProtocolTestsMetaclass, BaseAsyncTestCase
from test.ably.testapp import TestAppSync
from test.ably.utils import dont_vary_protocol, VaryByProtocolTestsMetaclass, BaseAsyncTestCase


class TestPresence(BaseAsyncTestCase, metaclass=VaryByProtocolTestsMetaclass):
Expand Down
12 changes: 6 additions & 6 deletions test/ably/sync/restrequest_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ def test_get(self):
assert item['name'] == 'event0'
assert item['data'] == 'lorem ipsum 0'

assert result.status_code == 200 # HP4
assert result.success is True # HP5
assert result.error_code is None # HP6
assert result.status_code == 200 # HP4
assert result.success is True # HP5
assert result.error_code is None # HP6
assert result.error_message is None # HP7
assert isinstance(result.headers, list) # HP7
assert isinstance(result.headers, list) # HP7

@dont_vary_protocol
def test_not_found(self):
result = self.ably.request('GET', '/not-found', version=Defaults.protocol_version)
assert isinstance(result, HttpPaginatedResponse) # RSC19d
assert result.status_code == 404 # HP4
assert result.success is False # HP5
assert result.status_code == 404 # HP4
assert result.success is False # HP5

@dont_vary_protocol
def test_error(self):
Expand Down
7 changes: 3 additions & 4 deletions test/ably/sync/reststats_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import logging
from datetime import datetime
from datetime import timedelta
import logging

import pytest

from ably.http.paginatedresult import PaginatedResult
from ably.types.stats import Stats
from ably.util.exceptions import AblyException
from ably.http.paginatedresult import PaginatedResult

from test.ably.testapp import TestApp, TestAppSync
from test.ably.testapp import TestAppSync
from test.ably.utils import VaryByProtocolTestsMetaclass, dont_vary_protocol, BaseAsyncTestCase

log = logging.getLogger(__name__)
Expand Down
1 change: 0 additions & 1 deletion test/ably/sync/resttime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import pytest

from ably import AblyException

from test.ably.testapp import TestAppSync
from test.ably.utils import VaryByProtocolTestsMetaclass, dont_vary_protocol, BaseAsyncTestCase

Expand Down
23 changes: 11 additions & 12 deletions test/ably/sync/resttoken_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
import json
import logging

from mock import patch
import pytest
from mock import patch

from ably import AblyException
from ably import AblyRest
from ably import Capability
from ably.types.tokendetails import TokenDetails
from ably.types.tokenrequest import TokenRequest

from test.ably.testapp import TestApp, TestAppSync
from test.ably.testapp import TestAppSync
from test.ably.utils import VaryByProtocolTestsMetaclass, dont_vary_protocol, BaseAsyncTestCase

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -123,7 +122,7 @@ def test_token_generation_with_invalid_ttl(self):

def test_token_generation_with_local_time(self):
timestamp = self.ably.auth._timestamp
with patch('ably.rest.rest.AblyRest.time', wraps=self.ably.time) as server_time,\
with patch('ably.rest.rest.AblyRest.time', wraps=self.ably.time) as server_time, \
patch('ably.rest.auth.Auth._timestamp', wraps=timestamp) as local_time:
self.ably.auth.request_token()
assert local_time.called
Expand All @@ -132,7 +131,7 @@ def test_token_generation_with_local_time(self):
# RSA10k
def test_token_generation_with_server_time(self):
timestamp = self.ably.auth._timestamp
with patch('ably.rest.rest.AblyRest.time', wraps=self.ably.time) as server_time,\
with patch('ably.rest.rest.AblyRest.time', wraps=self.ably.time) as server_time, \
patch('ably.rest.auth.Auth._timestamp', wraps=timestamp) as local_time:
self.ably.auth.request_token(query_time=True)
assert local_time.call_count == 1
Expand Down Expand Up @@ -185,7 +184,7 @@ def test_key_name_and_secret_are_required(self):
@dont_vary_protocol
def test_with_local_time(self):
timestamp = self.ably.auth._timestamp
with patch('ably.rest.rest.AblyRest.time', wraps=self.ably.time) as server_time,\
with patch('ably.rest.rest.AblyRest.time', wraps=self.ably.time) as server_time, \
patch('ably.rest.auth.Auth._timestamp', wraps=timestamp) as local_time:
self.ably.auth.create_token_request(
key_name=self.key_name, key_secret=self.key_secret, query_time=False)
Expand All @@ -196,7 +195,7 @@ def test_with_local_time(self):
@dont_vary_protocol
def test_with_server_time(self):
timestamp = self.ably.auth._timestamp
with patch('ably.rest.rest.AblyRest.time', wraps=self.ably.time) as server_time,\
with patch('ably.rest.rest.AblyRest.time', wraps=self.ably.time) as server_time, \
patch('ably.rest.auth.Auth._timestamp', wraps=timestamp) as local_time:
self.ably.auth.create_token_request(
key_name=self.key_name, key_secret=self.key_secret, query_time=True)
Expand All @@ -216,8 +215,8 @@ def auth_callback(token_params):
return token_request

ably = TestAppSync.get_ably_rest(key=None,
auth_callback=auth_callback,
use_binary_protocol=self.use_binary_protocol)
auth_callback=auth_callback,
use_binary_protocol=self.use_binary_protocol)

token = ably.auth.authorize()
assert isinstance(token, TokenDetails)
Expand All @@ -232,8 +231,8 @@ def auth_callback(token_params):
return token_request.to_dict()

ably = TestAppSync.get_ably_rest(key=None,
auth_callback=auth_callback,
use_binary_protocol=self.use_binary_protocol)
auth_callback=auth_callback,
use_binary_protocol=self.use_binary_protocol)

token = ably.auth.authorize()
assert isinstance(token, TokenDetails)
Expand Down Expand Up @@ -308,7 +307,7 @@ def auth_callback(token_params):
return token_request

ably = TestAppSync.get_ably_rest(key=None, auth_callback=auth_callback,
use_binary_protocol=self.use_binary_protocol)
use_binary_protocol=self.use_binary_protocol)

token = ably.auth.authorize()

Expand Down
2 changes: 1 addition & 1 deletion test/ably/testapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import logging

from ably.executer.decorator import optional_sync, force_sync
from ably.executer.decorator import force_sync
from ably.rest.rest import AblyRest
from ably.types.capability import Capability
from ably.types.options import Options
Expand Down

0 comments on commit 65331d5

Please sign in to comment.