def test_policy_fail(self): # admin only rule, default test case user should fail request = self.mock_rest_request( body='''{"rules": [["compute", "compute:unlock_override"]]}''') response = policy.Policy().post(request) self.assertStatusCode(response, 200) self.assertEqual({"allowed": False}, response.json)
def test_rule_with_target(self): body = json.dumps( {"rules": [["compute", "os_compute_api:servers:index:get_all_tenants"]]}) request = self.mock_rest_request(body=body) response = policy.Policy().post(request) self.assertStatusCode(response, 200) self.assertEqual({"allowed": True}, response.json)
def test_policy_fail(self): # admin only rule, default test case user should fail request = self.mock_rest_request( body=('{"rules": [' '["compute",' '"os_compute_api:servers:index:get_all_tenants"]]}')) response = policy.Policy().post(request) self.assertStatusCode(response, 200) self.assertEqual({"allowed": False}, response.json)
def test_rule_with_target(self): body = '{"rules": [["compute", "compute:unlock_override"]]}' request = self.mock_rest_request(body=body) response = policy.Policy().post(request) self.assertStatusCode(response, 200) self.assertEqual({"allowed": True}, response.json)
def test_policy_error(self): # admin only rule, default test case user should fail request = self.mock_rest_request(body='''{"bad": "compute"}''') response = policy.Policy().post(request) self.assertStatusCode(response, 400)
def test_policy(self, body='{"rules": []}'): request = self.mock_rest_request(body=body) response = policy.Policy().post(request) self.assertStatusCode(response, 200) self.assertEqual({"allowed": True}, response.json)
def test_policy_error(self): request = self.mock_rest_request( body=json.dumps({"bad": "compute"})) response = policy.Policy().post(request) self.assertStatusCode(response, 400)
def _test_policy(self, body, expected=True): request = self.mock_rest_request(body=body) response = policy.Policy().post(request) self.assertStatusCode(response, 200) self.assertEqual({"allowed": expected}, response.json)