def test_set_allowed_methods(self): fake_resp = mock.MagicMock() allowed_method_list = ['GET'] cors = CORS() cors._set_allowed_methods(fake_resp, allowed_method_list) fake_resp.append_header.assert_called_once_with( 'access-control-allow-methods', 'GET')
def test_process_methods_resource(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() fake_resource = mock.MagicMock() cors = CORS(allow_all_methods=True) cors._get_requested_method = mock.Mock(return_value='GET') cors._get_resource_methods = mock.Mock(return_value=['POST']) cors._set_allowed_methods = mock.Mock() self.assertEqual( cors._process_methods(fake_req, fake_resp, fake_resource), False) cors._set_allowed_methods.assert_called_once_with(fake_resp, ['POST'])
def test_process_methods_not_requested(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() fake_resource = mock.MagicMock() cors = CORS(allow_all_methods=True) cors._get_requested_method = mock.Mock(return_value=None) cors._set_allowed_methods = mock.Mock() self.assertEqual( cors._process_methods(fake_req, fake_resp, fake_resource), False) self.assertEqual(cors._set_allowed_methods.call_count, 0) cors._get_requested_method.assert_called_once_with(fake_req)
def test_process_methods_notfound(self): fake_req = mock.MagicMock() fake_resp = mock.MagicMock() fake_resource = mock.MagicMock() cors = CORS(allow_methods_list=['GET', 'POST', 'PUT', 'DELETE']) cors._set_allowed_methods = mock.Mock() cors._get_requested_method = mock.Mock(return_value='POST') cors._get_resource_methods = mock.Mock(return_value=['GET', 'PUT']) self.assertEqual( cors._process_methods(fake_req, fake_resp, fake_resource), False) cors._set_allowed_methods.assert_called_once_with( fake_resp, ['GET', 'PUT'])