def test_get_configuration_pass(self): """Validate get configuration does not throw exception when normal request is returned.""" initial = { "max_records": 1000, "log_level": "writeOnly", "full_policy": "overWrite", "threshold": 90 } expected = { "auditLogMaxRecords": 1000, "auditLogLevel": "writeOnly", "auditLogFullPolicy": "overWrite", "auditLogWarningThresholdPct": 90 } self._set_args(**initial) with mock.patch(self.REQ_FUNC, return_value=(200, { "runningAsProxy": True })): audit_log = AuditLog() with mock.patch(self.REQ_FUNC, return_value=(200, expected)): body = audit_log.get_configuration() self.assertTrue(body == expected)
def test_get_configuration_fail(self): """Verify AnsibleJsonFail exception is thrown.""" initial = { "max_records": 1000, "log_level": "writeOnly", "full_policy": "overWrite", "threshold": 90 } self._set_args(**initial) with mock.patch(self.REQ_FUNC, return_value=(200, { "runningAsProxy": True })): audit_log = AuditLog() with self.assertRaisesRegexp( AnsibleFailJson, r"Failed to retrieve the audit-log configuration!"): with mock.patch(self.REQ_FUNC, return_value=Exception()): audit_log.get_configuration()