diff --git a/README.md b/README.md index bb64f0a..ae29c91 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,8 @@ $ python examples/report_users_and_phones.py ``` $ nose2 + +Example: `cd tests/admin && nose2` ``` # Linting diff --git a/duo_client/admin.py b/duo_client/admin.py index 73e9bd4..b47d574 100644 --- a/duo_client/admin.py +++ b/duo_client/admin.py @@ -3625,6 +3625,23 @@ def get_policy_summary_v2(self): response = self.json_api_call("GET", path, {}) return response + def calculate_policy(self, integration_key, user_id): + """ + Args: + integration_key - The integration_key of the application to evaluate. (required) + user_id - The user_id of the user to evaluate (required) + + Returns (dict) - Dictionary containing "policy_elements" and "sections" + """ + + path = "/admin/v2/policies/calculate" + response = self.json_api_call( + "GET", + path, + {"integration_key": integration_key, "user_id": user_id}, + ) + return response + def get_passport_config(self): """ Returns the current Passport configuration. diff --git a/tests/admin/test_policies.py b/tests/admin/test_policies.py index e684142..f149bd2 100644 --- a/tests/admin/test_policies.py +++ b/tests/admin/test_policies.py @@ -98,4 +98,17 @@ def test_get_policy_summary(self): uri, _ = response["uri"].split("?") self.assertEqual(response["method"], "GET") - self.assertEqual(uri, "/admin/v2/policies/summary") \ No newline at end of file + self.assertEqual(uri, "/admin/v2/policies/summary") + + def test_calculate_policy(self): + ikey = "DI82WWNVI5Z4V10LZJR6" + ukey = "DUQU89MDEWOUR277H44G" + + response = self.client.calculate_policy(integration_key=ikey, user_id=ukey) + uri, args = response["uri"].split("?") + + self.assertEqual(response["method"], "GET") + self.assertEqual(uri, "/admin/v2/policies/calculate") + self.assertDictEqual( + util.params_to_dict(args), {"integration_key": [ikey], "user_id": [ukey]} + ) \ No newline at end of file