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 Client Grants, Resource Servers and Rules #110

Merged
merged 5 commits into from
Jun 27, 2018

Conversation

lbalmaceda
Copy link
Contributor

What

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

I kept this free from breaking changes by providing an include_totals=False value (since if that's true, the response is an Object rather than an Array).

Scope

  • Clients Grants
  • User Grants (Missing entity, not going to be implemented)
  • Resource Servers
  • Rules

How it was tested

✅ Unit tests asserting the params with which the function was called. Similar to the other pagination PR.

@lbalmaceda lbalmaceda added this to the v3-Next milestone Jun 19, 2018
@codecov-io
Copy link

codecov-io commented Jun 19, 2018

Codecov Report

Merging #110 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #110      +/-   ##
==========================================
+ Coverage   93.46%   93.47%   +0.01%     
==========================================
  Files          32       32              
  Lines         643      644       +1     
==========================================
+ Hits          601      602       +1     
  Misses         42       42
Impacted Files Coverage Δ
auth0/v3/management/emails.py 94.73% <ø> (ø) ⬆️
auth0/v3/management/logs.py 100% <ø> (ø) ⬆️
auth0/v3/management/users.py 100% <ø> (ø) ⬆️
auth0/v3/management/tenants.py 100% <ø> (ø) ⬆️
auth0/v3/management/clients.py 100% <ø> (ø) ⬆️
auth0/v3/management/device_credentials.py 100% <ø> (ø) ⬆️
auth0/v3/management/connections.py 100% <ø> (ø) ⬆️
auth0/v3/management/client_grants.py 100% <100%> (ø) ⬆️
auth0/v3/management/resource_servers.py 100% <100%> (ø) ⬆️
auth0/v3/management/rules.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 30c96b1...b4b9e6f. Read the comment docs.

Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

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

Minor stuff

params = {'audience': audience or None}
params = {
'audience': audience or None,
'per_page': per_page,
Copy link
Contributor

Choose a reason for hiding this comment

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

Match the order of the function params, IMHO

'audience': audience or None,
'per_page': per_page,
'page': page,
'include_totals': str(include_totals).lower()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a boolean argument in the docs ... why a string here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this are query params. Sending them as Strings is OK.

c.all()

args, kwargs = mock_instance.get.call_args

self.assertEqual('https://domain/api/v2/client-grants', args[0])
self.assertEqual(kwargs['params'], {'audience': None})
self.assertEqual(kwargs['params'], {
Copy link
Contributor

Choose a reason for hiding this comment

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

kwargs 😆

self.assertEqual('https://domain/api/v2/client-grants', args[0])
self.assertEqual(kwargs['params'], {
'audience': 'http://domain.auth0.com/api/v2/',
'per_page': None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Minuscule but inconsistent order here (page first)

"""Retrieves all client grants.

Args:
audience (str, optional): URL Encoded audience of a Resource Server
to filter
audience (str, optional): URL Encoded audience of a Resource Server
Copy link
Contributor

Choose a reason for hiding this comment

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

"encoded" lowercase

@@ -24,15 +24,28 @@ def _url(self, id=None):
return url + '/' + id
return url

def all(self, audience=None):
def all(self, audience=None, page=None, per_page=None, include_totals=False):
"""Retrieves all client grants.

Args:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these blocks include a link to the v2 API doc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only for create and update now.

"""

params = {'audience': audience or None}
params = {
'audience': audience or None,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing that you're just keeping what was there but why not just audience here? Could audience ever be a value where None is used or even makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if audience is empty I don't want to send the parameter at all.

>>> audience = '1'
>>> audience or None
'1'
>>> audience = ''
>>> audience or None
>>> 

page (int, optional): The result's page number (zero based).

per_page (int, optional): The amount of entries per page.
Default: 50. Max value: 100
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we talked through including these values in docs and landed on not including them because they were apt to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a copy paste issue and is present on most of the new endpoints implementing pagination that default to None. I'll check the rest as well. Nice catch :)

joshcanhelp
joshcanhelp previously approved these changes Jun 26, 2018
@lbalmaceda lbalmaceda merged commit e6a2831 into master Jun 27, 2018
@lbalmaceda lbalmaceda deleted the add-pagination branch June 27, 2018 12:43
@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

3 participants