1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00

inserito test PUT

This commit is contained in:
stefanogoldoni 2021-05-25 22:21:05 +02:00
parent 02886a65db
commit 44919f2f8f
2 changed files with 34 additions and 22 deletions

View file

@ -171,7 +171,7 @@ def page_alert(aid):
try:
alert.evaluation_mode = ConditionMode(request.json['evaluation_mode'])
except KeyError:
return json_error("Unknown `type` specified.", GENERIC_ENUM_INVALID), 400
return json_error("Unknown `evaluation_mode` specified.", GENERIC_ENUM_INVALID), 400
except Exception as e:
return json_error("Unknown error:" + str(e), GENERIC_UFO), 400
ext.session.commit()
@ -203,7 +203,7 @@ def page_alert(aid):
try:
alert.evaluation_mode = ConditionMode(mode)
except KeyError:
return json_error("Unknown `type` specified.", GENERIC_ENUM_INVALID), 400
return json_error("Unknown `evaluation_mode` specified.", GENERIC_ENUM_INVALID), 400
except Exception as e:
return json_error("Unknown error:" + str(e), GENERIC_UFO), 400
if request.json['conditions'] is not None:

View file

@ -3,7 +3,7 @@ from flask.testing import Client
'''A file that contains tests of classes and methods for all the requests concerning an user.'''
# test del file repository_conditions
# test del file repository_alerts
class TestAlertsGetAllOfARepository:
@ -158,41 +158,53 @@ class TestAlertPost:
'''
# test del file condition
# test del file alert
class TestOneConditionOfARepository:
def test_condition_not_found(self, flask_client: Client, user_headers):
r = flask_client.get(f'/api/v1/conditions/99', headers=user_headers)
class TestOneAlertOfARepository:
def test_alert_not_found(self, flask_client: Client, user_headers):
r = flask_client.get(f'/api/v1/alert/99', headers=user_headers)
assert r.status_code == 404
assert r.json["result"] == "failure"
# test GET
def test_get_condition(self, flask_client: Client, user_headers):
r = flask_client.get(f'/api/v1/conditions/3', headers=user_headers)
def test_get_alert(self, flask_client: Client, user_headers):
r = flask_client.get(f'/api/v1/alert/1', headers=user_headers)
assert r.status_code == 200
assert r.json["result"] == "success"
# test PATCH
def test_patch_condition_no_json(self, flask_client: Client, user_headers):
r = flask_client.patch(f'/api/v1/conditions/3', headers=user_headers)
def test_patch_alert_no_json(self, flask_client: Client, user_headers):
r = flask_client.patch(f'/api/v1/alert/1', headers=user_headers)
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_patch_condition_wrong_type(self, flask_client: Client, user_headers):
r = flask_client.patch(f'/api/v1/conditions/3', headers=user_headers,
json={"content": "string", "type": 99})
def test_patch_alert_wrong_evaluation_mode(self, flask_client: Client, user_headers):
r = flask_client.patch(f'/api/v1/alert/1', headers=user_headers,
json={"evaluation_mode": 99})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_patch_condition_for_success(self, flask_client: Client, user_headers):
r = flask_client.patch(f'/api/v1/conditions/3', headers=user_headers,
json={"content": "patchedForTest", "type": 0})
assert r.status_code == 204
def test_patch_alert_for_success(self, flask_client: Client, user_headers):
r = flask_client.patch(f'/api/v1/alert/1', headers=user_headers,
json={
"evaluation_mode": 1,
"limit": 1,
"name": "new_name",
"window_size": 1
})
assert r.status_code == 200
assert r.json["result"] == "success"
# test PUT
def test_put_alert_no_json(self, flask_client: Client, user_headers):
r = flask_client.patch(f'/api/v1/alert/2', headers=user_headers)
assert r.status_code == 400
assert r.json["result"] == "failure"
# test DELETE
def test_delete_condition_for_success(self, flask_client: Client, user_headers):
r = flask_client.delete(f'/api/v1/conditions/3', headers=user_headers)
def test_delete_alert_for_success(self, flask_client: Client, user_headers):
r = flask_client.delete(f'/api/v1/alert/1', headers=user_headers)
assert r.status_code == 204
'''