Repository: auth0/auth0-python
Pull request #389 (2022-07-27 21:17:53)

Add `include_totals` pagination parameter to `all_organization_invitations`
### Changes

No pagination properties are returned when calling [get-invitations](https://auth0.com/docs/api/management/v2/#!/Organizations/get_invitations) and cannot be requested. The current implementation of `all_organization_invitations` does not enable passing `include_totals`. 

This results in client applications reimplementing paging logic that is already solved by the `start`, `limit`, and `total` properties.

Given that the API already expects `include_totals`, this MR adds the missing parameter to `organizations.all_organization_invitations`.

#### change log
- Updated `organizations.all_organization_invitations` to include expected parameters for pagination:
  - include_totals

- Per [API documentation](https://auth0.com/docs/api/management/v2/#!/Organizations/get_invitations), returning the total is noted as unsupported in the method comment
 

*NOTE:* In order to maintain backwards compatibility, the default value for `include_totals` is `False`. This is inconsistent. I err'd on the side of caution to avoid changing the default response format from a list to a dictionary.
 
### References

n/a

### Testing

Updated existing unit tests to verify parameters are included per the existing pattern.

Manual testing may be done using:

```
...
organizations.all_organization_members_async(id=some_id, include_totals=True, page=1, per_page=10)
```

- [X] This change adds unit test coverage
- [X] This change adds integration test coverage
- [X] This change has been tested on the latest version of the platform/language or why not

### 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/organizations.py b/auth0/v3/management/organizations.py
index f9f2afe..42bb23f 100644
--- a/auth0/v3/management/organizations.py
+++ b/auth0/v3/management/organizations.py
@@ -338,7 +338,13 @@ class Organizations(object):
         return self.client.delete(self._url(id, "members", user_id, "roles"), data=body)
 
     # Organization Invitations
-    def all_organization_invitations(self, id, page=None, per_page=None):
+    def all_organization_invitations(
+        self,
+        id,
+        page=None,
+        per_page=None,
+        include_totals=False,
+    ):
         """Retrieves a list of all the organization invitations.
 
         Args:
@@ -350,9 +356,18 @@ class Organizations(object):
            per_page (int, optional): The amount of entries per page. When not set,
               the default value is up to the server.
 
+           include_totals (bool, optional): True if the query summary is
+              to be included in the result, False otherwise. Defaults to False.
+              NOTE: returns start and limit, total count is not yet supported
+
         See: https://auth0.com/docs/api/management/v2#!/Organizations/get_invitations
         """
-        params = {"page": page, "per_page": per_page}
+        params = {
+            "page": page,
+            "per_page": per_page,
+            "include_totals": str(include_totals).lower(),
+        }
+
         return self.client.get(self._url(id, "invitations"), params=params)
 
     def get_organization_invitation(self, id, invitaton_id):


Test patch:
diff --git a/auth0/v3/test/management/test_organizations.py b/auth0/v3/test/management/test_organizations.py
index d584dd3..e4c58f2 100644
--- a/auth0/v3/test/management/test_organizations.py
+++ b/auth0/v3/test/management/test_organizations.py
@@ -372,7 +372,14 @@ class TestOrganizations(unittest.TestCase):
         self.assertEqual(
             "https://domain/api/v2/organizations/test-org/invitations", args[0]
         )
-        self.assertEqual(kwargs["params"], {"page": None, "per_page": None})
+        self.assertEqual(
+            kwargs["params"],
+            {
+                "page": None,
+                "per_page": None,
+                "include_totals": "false",
+            },
+        )
 
         # Specific pagination
         c.all_organization_invitations("test-org", page=7, per_page=25)
@@ -382,7 +389,33 @@ class TestOrganizations(unittest.TestCase):
         self.assertEqual(
             "https://domain/api/v2/organizations/test-org/invitations", args[0]
         )
-        self.assertEqual(kwargs["params"], {"page": 7, "per_page": 25})
+        self.assertEqual(
+            kwargs["params"],
+            {
+                "page": 7,
+                "per_page": 25,
+                "include_totals": "false",
+            },
+        )
+
+        # Return paged collection with paging properties
+        c.all_organization_invitations(
+            "test-org", page=7, per_page=25, include_totals=True
+        )
+
+        args, kwargs = mock_instance.get.call_args
+
+        self.assertEqual(
+            "https://domain/api/v2/organizations/test-org/invitations", args[0]
+        )
+        self.assertEqual(
+            kwargs["params"],
+            {
+                "page": 7,
+                "per_page": 25,
+                "include_totals": "true",
+            },
+        )
 
     @mock.patch("auth0.v3.management.organizations.RestClient")
     def test_get_organization_invitation(self, mock_rc):