-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: add version check support #299
Conversation
☂️ Python Coverage
Overall Coverage
New Files
Modified Files
|
@@ -48,6 +48,7 @@ def test_posit_credentials_provider(self): | |||
register_mocks() | |||
|
|||
client = Client(api_key="12345", url="https://connect.example/") | |||
client.ctx.version = None |
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.
We are setting the version to None
to avoid mocking the API request to /server_settings.
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.
Should we put this in a helper function of some sort? Something like test_client(...)
that does this internally. There are other ways too, but this is a lot of the same thing over and over (and a bit of specialized knowledge that you basically always have to do this in these tests
After a few iterations, I landed on the decorator approach. This seems idiomatic and self-documenting. I tried a few declarative approaches (i.e., checking the version inline), but that felt brittle. |
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.
Looks great! I like the annotation approach, that feels very idiomatic
client = Client("https://connect.example", "12345") | ||
c = Client("https://connect.example", "12345") | ||
c.ctx.version = None |
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.
Any reason for the client -> c
here?
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.
Just making the references the same across the file.
def test_version_missing(self): | ||
class Stub(ContentManager): | ||
def __init__(self, ctx): | ||
self.ctx = ctx | ||
|
||
@requires("1.0.0") | ||
def success(self): | ||
pass | ||
|
||
ctx = MagicMock() | ||
ctx.version = None | ||
instance = Stub(ctx) | ||
|
||
instance.success() |
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.
This test is for behavior we use while testing, but not one we expect users to hit, yeah? If yeah, it would be good to comment about that just so it's clear this isn't a desired end-user behavior.
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.
No, this is designed behavior. If the version is hidden in the server settings, then ctx.version
will be None. When the value is None
the version check is skipped since we aren't sure. In the case of breaking API changes, we will need to perform the fallback sequence based on the HTTP response.
Adds a new decorator,
@context.requires
, which asserts version compatibility when the server version is known. The check is skipped if the server version is unknown (e.g., the Connect configuration disables version information).Also marks the OAuth API with a '2024.08.0' requirement.
Closes #272