Skip to content
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

Merged
merged 4 commits into from
Oct 7, 2024
Merged

feat: add version check support #299

merged 4 commits into from
Oct 7, 2024

Conversation

tdstein
Copy link
Collaborator

@tdstein tdstein commented Sep 26, 2024

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

Copy link

github-actions bot commented Sep 26, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
1144 1098 96% 0% 🟢

New Files

File Coverage Status
src/posit/connect/context.py 100% 🟢
TOTAL 100% 🟢

Modified Files

File Coverage Status
src/posit/connect/client.py 99% 🟢
TOTAL 99% 🟢

updated for commit: e1be1c4 by action🐍

src/posit/connect/context.py Outdated Show resolved Hide resolved
@@ -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
Copy link
Collaborator Author

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.

Copy link
Collaborator

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

@tdstein tdstein marked this pull request as ready for review September 27, 2024 13:14
@tdstein
Copy link
Collaborator Author

tdstein commented Sep 27, 2024

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.

Copy link
Collaborator

@dbkegley dbkegley left a 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

Comment on lines -167 to +171
client = Client("https://connect.example", "12345")
c = Client("https://connect.example", "12345")
c.ctx.version = None
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Comment on lines +44 to +57
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()
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@tdstein tdstein merged commit 0e9cf02 into main Oct 7, 2024
32 checks passed
@tdstein tdstein deleted the tdstein/272-2 branch October 7, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add the Connect version as a resource attribute.
3 participants