Repository: auth0/auth0-python
Pull request #300 (2022-01-04 14:40:20)

Add pagination to device credentials
### Changes

Please describe both what is changing and why this is important. Include:

Added two pagination parameters to the /v3/management/device-credentials get method. 

### References

This is in relation to https://github.com/auth0/auth0-python/issues/299

### Testing

Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors. 

- [x] This change adds unit test coverage

### Checklist

- [x] I have read the [Auth0 general contribution guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
- [x] I have read the [Auth0 Code of Conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)
- [x] All existing and new tests complete without errors



Patch:
diff --git a/auth0/v3/management/device_credentials.py b/auth0/v3/management/device_credentials.py
index fda6c81..23c2c9d 100644
--- a/auth0/v3/management/device_credentials.py
+++ b/auth0/v3/management/device_credentials.py
@@ -34,7 +34,7 @@ class DeviceCredentials(object):
             return '{}/{}'.format(url, id)
         return url
 
-    def get(self, user_id, client_id, type, fields=None, include_fields=True):
+    def get(self, user_id, client_id, type, fields=None, include_fields=True, page=None, per_page=None, include_totals=False):
         """List device credentials.
 
         Args:
@@ -51,6 +51,14 @@ class DeviceCredentials(object):
             include_fields (bool, optional): True if the fields specified are
                 to be included in the result, False otherwise. Defaults to True.
 
+            page (int, optional): Page index of the results to return. First page is 0.
+
+            per_page (int, optional): Number of results per page.
+
+            include_totals (bool, optional): True to return results inside an object
+                that contains the total result count (True) or as a direct array of
+                results (False, default).
+
         See: https://auth0.com/docs/api/management/v2#!/Device_Credentials/get_device_credentials
         """
 
@@ -60,6 +68,9 @@ class DeviceCredentials(object):
             'user_id': user_id,
             'client_id': client_id,
             'type': type,
+            'page': page,
+            'per_page': per_page,
+            'include_totals': str(include_totals).lower()
         }
         return self.client.get(self._url(), params=params)
 


Test patch:
diff --git a/auth0/v3/test/management/test_device_credentials.py b/auth0/v3/test/management/test_device_credentials.py
index 6aa854d..036067f 100644
--- a/auth0/v3/test/management/test_device_credentials.py
+++ b/auth0/v3/test/management/test_device_credentials.py
@@ -16,7 +16,7 @@ class TestDeviceCredentials(unittest.TestCase):
         mock_instance = mock_rc.return_value
 
         c = DeviceCredentials(domain='domain', token='jwttoken')
-        c.get(user_id='uid', client_id='cid', type='type')
+        c.get(user_id='uid', client_id='cid', type='type', page=0, per_page=20)
 
         args, kwargs = mock_instance.get.call_args
 
@@ -25,7 +25,24 @@ class TestDeviceCredentials(unittest.TestCase):
                                             'include_fields': 'true',
                                             'user_id': 'uid',
                                             'client_id': 'cid',
-                                            'type': 'type'})
+                                            'type': 'type',
+                                            'page': 0,
+                                            'per_page': 20,
+                                            'include_totals': 'false'})
+
+        c.get(user_id='uid', client_id='cid', type='type', page=5, per_page=50, include_totals=True)
+
+        args, kwargs = mock_instance.get.call_args
+
+        self.assertEqual('https://domain/api/v2/device-credentials', args[0])
+        self.assertEqual(kwargs['params'], {'fields': None,
+                                            'include_fields': 'true',
+                                            'user_id': 'uid',
+                                            'client_id': 'cid',
+                                            'type': 'type',
+                                            'page': 5,
+                                            'per_page': 50,
+                                            'include_totals': 'true'})
 
     @mock.patch('auth0.v3.management.device_credentials.RestClient')
     def test_create(self, mock_rc):