def test_13(): payload = '{"sentence":value_not_string}' with app.test_client() as client: # send request to server, and get response try: response = client.post('http://localhost:98/curl', json = JSONMixin().json_module.loads(payload, object_pairs_hook = my_obj_pairs_hook)) except JSONDecodeError as e: # check whether we get the expected response back assert e.args == ('Expecting value: line 1 column 13 (char 12)',)
def test_14(): payload = '{sentence:"key_not_string"}' with app.test_client() as client: # send request to server, and get response try: response = client.post('http://localhost:98/curl', json=JSONMixin().json_module.loads(payload, object_pairs_hook=my_obj_pairs_hook)) except JSONDecodeError as e: # check whether we get the expected response back assert e.args == ('Expecting property name enclosed in double quotes: line 1 column 2 (char 1)',)
def test_12(): payload = '{"not_sentence": "I feel good."}' expected_status_code = 400 expected_response = { "error_message": "Failed to decode JSON object: Expecting key/value pair with key of 'sentence'.", "status": "error", "status_code": "400 - Bad Request" } with app.test_client() as client: # send request to server, and get response response = client.post('http://localhost:98/curl', json = JSONMixin().json_module.loads(payload, object_pairs_hook = my_obj_pairs_hook)) # check whether we get the expected response back assert response.status_code == expected_status_code assert json.loads(response.data) == expected_response
def test_102(): payload = '{"sentence": "I feel bad."}' expected_status_code = 200 expected_response = { "score": { "compound": -0.5423, "neg": 0.778, "neu": 0.222, "pos": 0.0 }, "sentence": "feel bad", "status": "complete" } with app.test_client() as client: # send request to server, and get response response = client.post('http://localhost:98/curl', json = JSONMixin().json_module.loads(payload, object_pairs_hook = my_obj_pairs_hook)) # check whether we get the expected response back assert response.status_code == expected_status_code assert json.loads(response.data) == expected_response
def test_21(): payload = '{"sentence": "I\'D l@&$%%^ov*)e t+++o ' \ '<p>haVe<h1> thRee cUPs of Lat81405878tè' \ '<br /><br />frOM yo74593ur caffè. "}' expected_status_code = 200 expected_response = { "score": { "compound": 0.6369, "neg": 0.0, "neu": 0.543, "pos": 0.457 }, "sentence": "id love three cups latte caffe", "status": "complete" } with app.test_client() as client: # send request to server, and get response response = client.post('http://localhost:98/curl', json = JSONMixin().json_module.loads(payload, object_pairs_hook = my_obj_pairs_hook)) # check whether we get the expected response back assert response.status_code == expected_status_code assert json.loads(response.data) == expected_response