-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use endpoint as default connection option (ADR-119) #590
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -76,12 +76,12 @@ def test_rest_host_and_environment(self): | |||||||||||||||||||||||||||||||
# environment: production | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='foo', environment="production") | ||||||||||||||||||||||||||||||||
host = ably.options.get_rest_host() | ||||||||||||||||||||||||||||||||
assert "rest.ably.io" == host, "Unexpected host mismatch %s" % host | ||||||||||||||||||||||||||||||||
assert "main.realtime.ably.net" == host, "Unexpected host mismatch %s" % host | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# environment: other | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='foo', environment="sandbox") | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='foo', environment="nonprod:sandbox") | ||||||||||||||||||||||||||||||||
host = ably.options.get_rest_host() | ||||||||||||||||||||||||||||||||
assert "sandbox-rest.ably.io" == host, "Unexpected host mismatch %s" % host | ||||||||||||||||||||||||||||||||
assert "sandbox.realtime.ably-nonprod.net" == host, "Unexpected host mismatch %s" % host | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# both, as per #TO3k2 | ||||||||||||||||||||||||||||||||
with pytest.raises(ValueError): | ||||||||||||||||||||||||||||||||
|
@@ -103,13 +103,13 @@ def test_fallback_hosts(self): | |||||||||||||||||||||||||||||||
assert sorted(aux) == sorted(ably.options.get_fallback_rest_hosts()) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# Specify environment (RSC15g2) | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='foo', environment='sandbox', http_max_retry_count=10) | ||||||||||||||||||||||||||||||||
assert sorted(Defaults.get_environment_fallback_hosts('sandbox')) == sorted( | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='foo', environment='nonprod:sandbox', http_max_retry_count=10) | ||||||||||||||||||||||||||||||||
assert sorted(Defaults.get_fallback_hosts('nonprod:sandbox')) == sorted( | ||||||||||||||||||||||||||||||||
ably.options.get_fallback_rest_hosts()) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# Fallback hosts and environment not specified (RSC15g3) | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='foo', http_max_retry_count=10) | ||||||||||||||||||||||||||||||||
assert sorted(Defaults.fallback_hosts) == sorted(ably.options.get_fallback_rest_hosts()) | ||||||||||||||||||||||||||||||||
assert sorted(Defaults.get_fallback_hosts()) == sorted(ably.options.get_fallback_rest_hosts()) | ||||||||||||||||||||||||||||||||
Comment on lines
+106
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Update environment to endpoint in fallback hosts test. For consistency with ADR-119, update the test to use endpoint instead of environment. - ably = AblyRest(token='foo', environment='nonprod:sandbox', http_max_retry_count=10)
+ ably = AblyRest(token='foo', endpoint='nonprod:sandbox', http_max_retry_count=10)
assert sorted(Defaults.get_fallback_hosts('nonprod:sandbox')) == sorted(
ably.options.get_fallback_rest_hosts()) 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
# RSC15f | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='foo') | ||||||||||||||||||||||||||||||||
|
@@ -182,13 +182,19 @@ async def test_query_time_param(self): | |||||||||||||||||||||||||||||||
@dont_vary_protocol | ||||||||||||||||||||||||||||||||
def test_requests_over_https_production(self): | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='token') | ||||||||||||||||||||||||||||||||
assert 'https://rest.ably.io' == '{0}://{1}'.format(ably.http.preferred_scheme, ably.http.preferred_host) | ||||||||||||||||||||||||||||||||
assert 'https://main.realtime.ably.net' == '{0}://{1}'.format( | ||||||||||||||||||||||||||||||||
ably.http.preferred_scheme, ably.http.preferred_host | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
assert ably.http.preferred_port == 443 | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@dont_vary_protocol | ||||||||||||||||||||||||||||||||
def test_requests_over_http_production(self): | ||||||||||||||||||||||||||||||||
ably = AblyRest(token='token', tls=False) | ||||||||||||||||||||||||||||||||
assert 'http://rest.ably.io' == '{0}://{1}'.format(ably.http.preferred_scheme, ably.http.preferred_host) | ||||||||||||||||||||||||||||||||
assert 'http://main.realtime.ably.net' == '{0}://{1}'.format( | ||||||||||||||||||||||||||||||||
ably.http.preferred_scheme, ably.http.preferred_host | ||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
assert ably.http.preferred_port == 80 | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
@dont_vary_protocol | ||||||||||||||||||||||||||||||||
|
@@ -211,7 +217,7 @@ async def test_environment(self): | |||||||||||||||||||||||||||||||
except AblyException: | ||||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||||
request = get_mock.call_args_list[0][0][0] | ||||||||||||||||||||||||||||||||
assert request.url == 'https://custom-rest.ably.io:443/time' | ||||||||||||||||||||||||||||||||
assert request.url == 'https://custom.realtime.ably.net:443/time' | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
await ably.close() | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix Yoda condition and update environment to endpoint.
Update the test to use endpoint instead of environment for consistency with ADR-119.
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.8.2)
84-84: Yoda condition detected
Rewrite as
host == "sandbox.realtime.ably-nonprod.net"
(SIM300)