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

test: Add tests for Users with mock responses #46

Merged
merged 6 commits into from
Feb 23, 2024
Merged

Conversation

nealrichardson
Copy link
Collaborator

Plus some TODOs that come out of this (I'll come back to them tomorrow, or you can feel free to push to this branch). This should exercise some of the previously untested code, and should open up a path for adding some enhancements on top.

Copy link

github-actions bot commented Feb 21, 2024

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
507 487 96% 80% 🟢

New Files

No new covered files...

Modified Files

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

updated for commit: 40e03d7 by action🐍

@responses.activate
def test_get_users(self):
responses.get(
"https://connect.example/__api__/v1/users",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made these fixtures by querying a real Connect and then sanitizing the responses.

Comment on lines 98 to 101
# TODO: page_size should go with find(), can't pass it to client.users
u = Users(con.config, con.session, page_size=2)
# TODO: Add __len__ method to Users
assert len(u.find().data) == 3
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I want this to be is:

u = con.users.find(page_size=2)
assert len(u) == 3

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about making page_size a Config property. There are a handful of endpoints that support paging. Placing the value in Config will make it accessible to all future implementations of Resources.

       con = Client(api_key="12345", url="https://connect.example/", page_size=2)
       u = con.users.find()
       assert len(u) == 3

Adding page_size to find will require more refactoring.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding page_size to find will require more refactoring.

Yeah that's why I didn't just do it yesterday 😂 I had an idea while walking the dog though, may give it a shot later.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄 Sounds good!

For what it's worth, I'm thinking through another version of the Resources base class that will do a better job of handling these situations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, my other thought was to ship this, build (or more likely let you build) the Content classes, and see how some of this shakes out when we have two kinds of Resources to work with.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some issues for these and linked the issue numbers in the comment (i.e. # TODO(#47)) so that we can find them later.

@nealrichardson nealrichardson marked this pull request as ready for review February 22, 2024 21:02
@@ -6,3 +6,4 @@ responses>=0.25
ruff==0.1.14
setuptools==69.0.3
setuptools-scm==8.0.4
pandas
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 version pin here bc for our purposes, it doesn't matter, and because the current release of pandas isn't available for Python 3.8.

@nealrichardson
Copy link
Collaborator Author

I'm going to merge this: it pushes test coverage to 96% of lines, and it covers the key functionality of the Users resources. I want to try a refactor and need this coverage in place first.

@nealrichardson nealrichardson merged commit b8aacc7 into main Feb 23, 2024
7 checks passed
@nealrichardson nealrichardson deleted the test-users branch February 23, 2024 17:29
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.

2 participants