def test_should_return_error_message_in_tastypie_if_exception_while_loading_vcl(self): with patch('vaas.cluster.cluster.load_vcl_task.delay', side_effect=Exception('load vcl failed')): request = MagicMock(id='10', session={}) middleware = VclRefreshMiddleware() VclRefreshState.set_refresh('10', [MagicMock(id='1')]) response = middleware.process_response(request, HttpCreated()) assert_true(isinstance(response, HttpApplicationError)) assert_equals(b'Exception: load vcl failed', response.content)
def test_should_return_error_message_in_tastypie_if_exception_while_loading_vcl(self): with patch.object(VarnishCluster, 'load_vcl', side_effect=Exception('load vcl failed')): request = MagicMock(id='10', session={}) middleware = VclRefreshMiddleware() VclRefreshState.set_refresh('10', ['cluster-1']) response = middleware.process_response(request, HttpCreated()) assert_true(isinstance(response, HttpApplicationError)) assert_equals('Exception: load vcl failed', response.content)
def test_should_return_error_message_if_exception_while_loading_vcl(self): with patch('vaas.cluster.cluster.load_vcl_task.delay', side_effect=Exception('load vcl failed')): request = MagicMock(id='10', session={}) middleware = VclRefreshMiddleware() VclRefreshState.set_refresh('10', [MagicMock(id='1')]) middleware.process_response(request, None) assert_true('error_message' in request.session) assert_equals('Exception: load vcl failed', request.session['error_message'])
def test_should_return_error_message_if_exception_while_loading_vcl(self): with patch.object(VarnishCluster, 'load_vcl', side_effect=Exception('load vcl failed')): request = MagicMock(id='10', session={}) middleware = VclRefreshMiddleware() VclRefreshState.set_refresh('10', ['cluster-1']) middleware.process_response(request, None) assert_true('error_message' in request.session) assert_equals('Exception: load vcl failed', request.session['error_message'])
def regenerate_and_reload_vcl(clusters): logger = logging.getLogger('vaas') logger.debug("regenerate_and_reload_vcl(): %s" % str(clusters)) request = get_current_request() if request is not None: if 'action' in request.POST.keys(): logger.debug("ACTION: %s" % request.POST['action']) if '_selected_action' in request.POST.keys(): logger.debug("SELECTED: %s" % request.POST['_selected_action']) logger.debug("PATH: %s" % request.path) VclRefreshState.set_refresh(request.id, clusters)
def test_should_not_refresh_vcl_on_response_if_empty_cluster_list(self): request = MagicMock(id='10') middleware = VclRefreshMiddleware() middleware.process_request(request) clusters = [] VclRefreshState.set_refresh(request.id, clusters) with patch.object(VarnishCluster, '__init__', return_value=None): with patch.object(VarnishCluster, 'load_vcl', return_value=None) as load_vcl_mock: middleware.process_response(request, None) assert_equals(0, len(load_vcl_mock.call_args_list))
def test_should_not_refresh_vcl_on_response_if_empty_cluster_list(self): request = MagicMock(id='10') middleware = VclRefreshMiddleware() middleware.process_request(request) clusters = [] VclRefreshState.set_refresh(request.id, clusters) with patch.object(VarnishCluster, '__init__', return_value=None): with patch.object( VarnishCluster, 'load_vcl', return_value=None ) as load_vcl_mock: middleware.process_response(request, None) assert_equals(0, len(load_vcl_mock.call_args_list))
def test_should_return_previously_set_value_and_clean_state(self): req_id = '1234' VclRefreshState.set_refresh(req_id, True) assert_equals({req_id: True}, VclRefreshState.refresh) assert_true(VclRefreshState.get_refresh(req_id)) assert_equals({}, VclRefreshState.refresh)
def test_should_return_default_value(self): non_existence_id = '1235' assert_false(VclRefreshState.get_refresh(non_existence_id))