def test_status_change_view(config, get_csrf_request_with_db, full_estimation, user): config.add_route(PROJECT_ITEM_ROUTE, PROJECT_ITEM_ROUTE) config.testing_securitypolicy(userid="test", groupids=('admin', ), permissive=True) from autonomie.views.estimations.rest_api import EstimationStatusRestView request = get_csrf_request_with_db(post={ 'submit': 'valid', 'comment': u"Test comment" }, context=full_estimation) from pyramid_layout.layout import LayoutManager request.user = user request.is_xhr = True view = EstimationStatusRestView(request) result = view.__call__() assert result == { 'redirect': PROJECT_ITEM_ROUTE.format(id=full_estimation.project_id) } assert full_estimation.status == 'valid' assert full_estimation.statuses[-1].status_comment == u"Test comment" assert full_estimation.statuses[-1].status_code == 'valid'
def test_status_change_view_invalid_error(config, get_csrf_request_with_db, estimation, user): config.add_route(PROJECT_ITEM_ROUTE, PROJECT_ITEM_ROUTE) from autonomie.utils.rest import RestError from autonomie.views.estimations.rest_api import EstimationStatusRestView request = get_csrf_request_with_db(post={'submit': 'valid'}) request.context = estimation request.user = user request.is_xhr = True view = EstimationStatusRestView(request) with pytest.raises(RestError) as invalid_exc: view.__call__() assert invalid_exc.value.code == 400 assert estimation.status == 'draft'
def test_status_change_view_forbidden_error(config, get_csrf_request_with_db, full_estimation, user): config.add_route(PROJECT_ITEM_ROUTE, PROJECT_ITEM_ROUTE) config.testing_securitypolicy(userid="test", groupids=('admin', ), permissive=False) from autonomie.utils.rest import RestError from autonomie.views.estimations.rest_api import EstimationStatusRestView request = get_csrf_request_with_db(post={'submit': 'valid'}) request.context = full_estimation request.user = user request.is_xhr = True view = EstimationStatusRestView(request) with pytest.raises(RestError) as forbidden_exc: view.__call__() assert forbidden_exc.value.code == 403 assert full_estimation.status == 'draft'
def test_status_change_view(config, get_csrf_request_with_db, full_estimation, user): config.add_route('project', '/{id}') config.testing_securitypolicy(userid="test", groupids=('admin', ), permissive=True) from autonomie.views.estimations.rest_api import EstimationStatusRestView request = get_csrf_request_with_db(post={ 'submit': 'valid', 'comment': u"Test comment" }) request.context = full_estimation request.user = user request.is_xhr = True view = EstimationStatusRestView(request) result = view.__call__() assert result == {'redirect': '/%s' % full_estimation.project_id} assert full_estimation.status == 'valid' assert full_estimation.statuses[-1].status_comment == u"Test comment" assert full_estimation.statuses[-1].status_code == 'valid'