invalid_pagesize = deepcopy(request_json) invalid_pagesize.update(pagesize=0) with login_disabled_app.test_client() as client: response = client.post("api/brand/test/1", json=invalid_pagesize) data = json.loads(response.data) ErrorSchema().load(data) assert response.status_code == 400 @pytest.mark.parametrize( "method,http_method,test_url,error,status_code", [("select", "POST", "/api/brand/test/1", NoContentError(), 204), ("select", "POST", "/api/brand/test/1", ElasticsearchException(), 504), ("select", "POST", "/api/brand/test/1", ElasticsearchDslException(), 504), ("select", "POST", "/api/brand/test/1", Exception(), 500)]) def test_kind_products_controller_error(mocker, get_request_function, method, http_method, test_url, error, status_code): with mocker.patch.object(ProductService, method, side_effect=error): make_request = get_request_function(http_method) response = make_request(test_url) if status_code == 204: with pytest.raises(JSONDecodeError): json.loads(response.data) else: data = json.loads(response.data) ErrorSchema().load(data)
with login_disabled_app.test_client() as client: response = client.post("api/product/list", json=invalid_amount) data = json.loads(response.data) ErrorSchema().load(data) assert response.status_code == 400 @pytest.mark.parametrize( "method,http_method,test_url,error,status_code", [("select_by_item_list", "POST", "/api/product/list", ValidationError("test"), 400), ("select_by_item_list", "POST", "/api/product/list", ElasticsearchException(), 504), ("select_by_item_list", "POST", "/api/product/list", ElasticsearchDslException(), 504), ("select_by_item_list", "POST", "/api/product/list", Exception(), 500)]) def test_kind_products_controller_error(mocker, get_request_function, request_json, method, http_method, test_url, error, status_code): with mocker.patch.object(ProductService, method, side_effect=error): make_request = get_request_function(http_method) response = make_request(test_url, json=request_json) data = json.loads(response.data) ErrorSchema().load(data) assert response.status_code == status_code
invalid_range = deepcopy(request_json) invalid_range["pricerange"].update(min=100.0, max=50.0) with login_disabled_app.test_client() as client: response = client.post("api/brand/test", json=invalid_range) data = json.loads(response.data) ErrorSchema().load(data) assert response.status_code == 400 @pytest.mark.parametrize("method,http_method,test_url,error,status_code", [ ("get_total", "POST", "/api/brand/test", NoContentError(), 204), ("get_total", "POST", "/api/brand/test", ElasticsearchException(), 504), ("get_total", "POST", "/api/brand/test", ElasticsearchDslException(), 504), ("get_total", "POST", "/api/brand/test", Exception(), 500) ]) def test_brand_controller_error(mocker, get_request_function, method, http_method, test_url, error, status_code): with mocker.patch.object(ProductService, method, side_effect=error): make_request = get_request_function(http_method) response = make_request(test_url) if status_code == 204: with pytest.raises(JSONDecodeError): json.loads(response.data) else: data = json.loads(response.data) ErrorSchema().load(data)
response = client.post( "api/product/total", json=invalid_amount ) data = json.loads(response.data) ErrorSchema().load(data) assert response.status_code == 400 @pytest.mark.parametrize( "method,http_method,test_url,error,status_code", [ ("select_by_item_list", "POST", "/api/product/total", ValidationError("test"), 400), ("select_by_item_list", "POST", "/api/product/total", ElasticsearchException(), 504), ("select_by_item_list", "POST", "/api/product/total", ElasticsearchDslException(), 504), ("select_by_item_list", "POST", "/api/product/total", Exception(), 500) ] ) def test_kind_products_controller_error(mocker, get_request_function, request_json, method, http_method, test_url, error, status_code): with mocker.patch.object(ProductService, method, side_effect=error): make_request = get_request_function(http_method) response = make_request( test_url, json=request_json ) data = json.loads(response.data) ErrorSchema().load(data)
with login_disabled_app.test_client() as client: response = client.get( "api/start" ) data = json.loads(response.data) ProductsCountSchema().load(data) assert response.status_code == 200 @pytest.mark.parametrize( "method,http_method,test_url,error,status_code", [ ("products_count", "GET", "/api/start", ElasticsearchException(), 504), ("products_count", "GET", "/api/start", ElasticsearchDslException(), 504), ("products_count", "GET", "/api/start", Exception(), 500) ] ) def test_start_controller_error(mocker, get_request_function, method, http_method, test_url, error, status_code): with mocker.patch.object(ProductService, method, side_effect=error): make_request = get_request_function(http_method) response = make_request( test_url ) data = json.loads(response.data) ErrorSchema().load(data) assert response.status_code == status_code
invalid_range = deepcopy(request_json) invalid_range["pricerange"].update(min=100.0, max=50.0) with login_disabled_app.test_client() as client: response = client.post("api/search/test", json=invalid_range) data = json.loads(response.data) ErrorSchema().load(data) assert response.status_code == 400 @pytest.mark.parametrize( "method,http_method,test_url,error,status_code", [("get_total", "POST", "/api/search/test", NoContentError(), 204), ("get_total", "POST", "/api/search/test", ElasticsearchException(), 504), ("get_total", "POST", "/api/search/test", ElasticsearchDslException(), 504), ("get_total", "POST", "/api/search/test", Exception(), 500)]) def test_search_controller_error(mocker, get_request_function, method, http_method, test_url, error, status_code): with mocker.patch.object(ProductService, method, side_effect=error): make_request = get_request_function(http_method) response = make_request(test_url) if status_code == 204: with pytest.raises(JSONDecodeError): json.loads(response.data) else: data = json.loads(response.data) ErrorSchema().load(data)
"api/session/test", json=invalid_range ) data = json.loads(response.data) ErrorSchema().load(data) assert response.status_code == 400 @pytest.mark.parametrize( "method,http_method,test_url,error,status_code", [ ("select_by_id", "POST", "/api/session/test", NoContentError(), 204), ("select_by_id", "POST", "/api/session/test", NotFoundError(), 404), ("select_by_id", "POST", "/api/session/test", ElasticsearchException(), 504), ("select_by_id", "POST", "/api/session/test", ElasticsearchDslException(), 504), ("select_by_id", "POST", "/api/session/test", Exception(), 500) ] ) def test_start_controller_error(mocker, get_request_function, method, http_method, test_url, error, status_code): with mocker.patch.object(SessionService, method, side_effect=error): make_request = get_request_function(http_method) response = make_request( test_url ) if status_code == 204: with pytest.raises(JSONDecodeError): json.loads(response.data) else:
with login_disabled_app.test_client() as client: response = client.get( "api/product/id" ) data = json.loads(response.data) ProductResultsSchema().load(data) assert response.status_code == 200 @pytest.mark.parametrize( "method,http_method,test_url,error,status_code", [ ("select_by_id", "GET", "api/product/id", NotFoundError(), 404), ("select_by_id", "GET", "api/product/id", ElasticsearchException(), 504), ("select_by_id", "GET", "api/product/id", ElasticsearchDslException(), 504), ("select_by_id", "GET", "api/product/id", Exception(), 500) ] ) def test_product_controller_error(mocker, get_request_function, method, http_method, test_url, error, status_code): with mocker.patch.object(ProductService, method, side_effect=error): make_request = get_request_function(http_method) response = make_request( test_url ) data = json.loads(response.data) if status_code == 404: assert data == {}