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

Add pagination to Clients and Connections #106

Merged
merged 5 commits into from
Jun 18, 2018
Merged

Conversation

lbalmaceda
Copy link
Contributor

@lbalmaceda lbalmaceda commented Jun 6, 2018

What

This PR adds pagination support on MGMT API entities that were missing.

Scope

  • Clients
  • Connections
  • Users (Already available)
  • Logs (Already available)

Discussion

  • While pagination is going to be enforced on new tenants, existing tenants can still call the endpoint without a page value and in turn, retrieve the full list of items. However for this specific SDK, the entities that already had pagination implemented had a default page value of 0, meaning if a specific page is not asked, the first one is always returned. On the present PR the new entities supporting pagination don't have the same behavior. Instead, they skip sending the page parameter if no value is specified. Should we maintain the same pagination behavior as other entities or avoid a possible breaking change?

How it was tested

I re-used the existing tests and added a few similar. I noticed the tests were actually checking the arguments with which the method was being called. One of the checks was that the arguments matched against a given (expected) dictionary value. This dictionary included keys with None value (A Python type similar to JS's undefined). My concern was that these keys were being set as query parameters anyway, sending invalid values on the server request. I added logging support (for testing purposes, not committed to this PR) and tried locally to see what was the actual outcome. Below is an example showing how the parameters are not added to the call if they are of type None.

# test/management/test_clients.py
        c = Clients(domain='domain', token='jwttoken')
        c.all(page=7, per_page=25)

        args, kwargs = mock_instance.get.call_args

        self.assertEqual('https://domain/api/v2/clients', args[0])
        self.assertEqual(kwargs['params'], {'fields': None,
                                            'include_fields': 'true',
                                            'page': 7,
                                            'per_page': 25})

# The final request URL (from my terminal)
        GET /api/v2/clients?include_fields=true&page=7&per_page=25

@codecov-io
Copy link

codecov-io commented Jun 6, 2018

Codecov Report

Merging #106 into master will increase coverage by 0.09%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #106      +/-   ##
==========================================
+ Coverage   93.05%   93.15%   +0.09%     
==========================================
  Files          32       32              
  Lines         634      643       +9     
==========================================
+ Hits          590      599       +9     
  Misses         44       44
Impacted Files Coverage Δ
auth0/v3/management/clients.py 100% <100%> (ø) ⬆️
auth0/v3/management/connections.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3b3353b...a0eb1b2. Read the comment docs.

@lbalmaceda lbalmaceda changed the title Add pagination Add pagination to Clients and Connections Jun 7, 2018
Copy link
Member

@cocojoe cocojoe left a comment

Choose a reason for hiding this comment

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

LGTM Although I'm not a Python dev 😄 Tests look good though.

@markprovan
Copy link

Initially I thought it would be good to get the request url into a unit test, but on digging into auth0/v3/management/rest.py I realised this would just be testing the requests package.

Looks good! 👍

@lbalmaceda
Copy link
Contributor Author

@markprovan @cocojoe similar to what I mentioned in the description, in the libraries I own I'd test the actual outcome instead of the params being passed to the function. So tests would check the final URL, query parameters and body instead. I don't care about what the method does internally. That shouldn't matter for the purpose.

@cocojoe cocojoe added this to the v3-Next milestone Jun 12, 2018
@lbalmaceda lbalmaceda merged commit fce4988 into master Jun 18, 2018
@lbalmaceda lbalmaceda deleted the add-pagination branch June 18, 2018 17:00
@lbalmaceda lbalmaceda modified the milestones: v3-Next, 3.3.0 Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants