mirror of
https://github.com/pds-nest/nest.git
synced 2025-02-16 12:43:58 +00:00
inserito test PUT
This commit is contained in:
parent
02886a65db
commit
44919f2f8f
2 changed files with 34 additions and 22 deletions
|
@ -171,7 +171,7 @@ def page_alert(aid):
|
||||||
try:
|
try:
|
||||||
alert.evaluation_mode = ConditionMode(request.json['evaluation_mode'])
|
alert.evaluation_mode = ConditionMode(request.json['evaluation_mode'])
|
||||||
except KeyError:
|
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:
|
except Exception as e:
|
||||||
return json_error("Unknown error:" + str(e), GENERIC_UFO), 400
|
return json_error("Unknown error:" + str(e), GENERIC_UFO), 400
|
||||||
ext.session.commit()
|
ext.session.commit()
|
||||||
|
@ -203,7 +203,7 @@ def page_alert(aid):
|
||||||
try:
|
try:
|
||||||
alert.evaluation_mode = ConditionMode(mode)
|
alert.evaluation_mode = ConditionMode(mode)
|
||||||
except KeyError:
|
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:
|
except Exception as e:
|
||||||
return json_error("Unknown error:" + str(e), GENERIC_UFO), 400
|
return json_error("Unknown error:" + str(e), GENERIC_UFO), 400
|
||||||
if request.json['conditions'] is not None:
|
if request.json['conditions'] is not None:
|
||||||
|
|
|
@ -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.'''
|
'''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:
|
class TestAlertsGetAllOfARepository:
|
||||||
|
@ -158,41 +158,53 @@ class TestAlertPost:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
|
||||||
# test del file condition
|
# test del file alert
|
||||||
|
|
||||||
|
|
||||||
class TestOneConditionOfARepository:
|
class TestOneAlertOfARepository:
|
||||||
def test_condition_not_found(self, flask_client: Client, user_headers):
|
def test_alert_not_found(self, flask_client: Client, user_headers):
|
||||||
r = flask_client.get(f'/api/v1/conditions/99', headers=user_headers)
|
r = flask_client.get(f'/api/v1/alert/99', headers=user_headers)
|
||||||
assert r.status_code == 404
|
assert r.status_code == 404
|
||||||
assert r.json["result"] == "failure"
|
assert r.json["result"] == "failure"
|
||||||
|
|
||||||
# test GET
|
# test GET
|
||||||
def test_get_condition(self, flask_client: Client, user_headers):
|
def test_get_alert(self, flask_client: Client, user_headers):
|
||||||
r = flask_client.get(f'/api/v1/conditions/3', headers=user_headers)
|
r = flask_client.get(f'/api/v1/alert/1', headers=user_headers)
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert r.json["result"] == "success"
|
assert r.json["result"] == "success"
|
||||||
|
|
||||||
# test PATCH
|
# test PATCH
|
||||||
def test_patch_condition_no_json(self, flask_client: Client, user_headers):
|
def test_patch_alert_no_json(self, flask_client: Client, user_headers):
|
||||||
r = flask_client.patch(f'/api/v1/conditions/3', headers=user_headers)
|
r = flask_client.patch(f'/api/v1/alert/1', headers=user_headers)
|
||||||
assert r.status_code == 400
|
assert r.status_code == 400
|
||||||
assert r.json["result"] == "failure"
|
assert r.json["result"] == "failure"
|
||||||
|
|
||||||
def test_patch_condition_wrong_type(self, flask_client: Client, user_headers):
|
def test_patch_alert_wrong_evaluation_mode(self, flask_client: Client, user_headers):
|
||||||
r = flask_client.patch(f'/api/v1/conditions/3', headers=user_headers,
|
r = flask_client.patch(f'/api/v1/alert/1', headers=user_headers,
|
||||||
json={"content": "string", "type": 99})
|
json={"evaluation_mode": 99})
|
||||||
assert r.status_code == 400
|
assert r.status_code == 400
|
||||||
assert r.json["result"] == "failure"
|
assert r.json["result"] == "failure"
|
||||||
|
|
||||||
def test_patch_condition_for_success(self, flask_client: Client, user_headers):
|
def test_patch_alert_for_success(self, flask_client: Client, user_headers):
|
||||||
r = flask_client.patch(f'/api/v1/conditions/3', headers=user_headers,
|
r = flask_client.patch(f'/api/v1/alert/1', headers=user_headers,
|
||||||
json={"content": "patchedForTest", "type": 0})
|
json={
|
||||||
assert r.status_code == 204
|
"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
|
# test DELETE
|
||||||
def test_delete_condition_for_success(self, flask_client: Client, user_headers):
|
def test_delete_alert_for_success(self, flask_client: Client, user_headers):
|
||||||
r = flask_client.delete(f'/api/v1/conditions/3', headers=user_headers)
|
r = flask_client.delete(f'/api/v1/alert/1', headers=user_headers)
|
||||||
assert r.status_code == 204
|
assert r.status_code == 204
|
||||||
'''
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue