1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00
pds-2021-g2-nest/nest_backend/test/test_4_alert.py
2021-05-25 21:57:01 +02:00

198 lines
8.8 KiB
Python

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
class TestAlertsGetAllOfARepository:
def test_repository_not_found(self, flask_client: Client, user_headers):
r = flask_client.get(f'/api/v1/repositories/99/alerts/', headers=user_headers)
assert r.status_code == 404
assert r.json["result"] == "failure"
def test_unauthorized_repository(self, flask_client: Client, admin_headers):
r = flask_client.get(f'/api/v1/repositories/1/alerts/', headers=admin_headers)
assert r.status_code == 403
assert r.json["result"] == "failure"
def test_get_all_alerts_of_a_repository(self, flask_client: Client, user_headers):
r = flask_client.get(f'/api/v1/repositories/1/alerts/', headers=user_headers)
assert r.status_code == 200
assert r.json["result"] == "success"
class TestAlertPost:
def test_missing_name(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_missing_limit(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={"name": "testalert"})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_missing_window_size(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={"name": "testalert", "limit": "1"})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_missing_evaluation_mode(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={
"conditions": [
{
"content": "pds2021",
"id": 0,
"type": 0
}
],
"XXXevaluation_modeXXX": 0,
"limit": 0,
"name": "pds",
"repository_id": 1,
"window_size": 0
})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_wrong_evaluation_mode(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={
"conditions": [
{
"content": "pds2021",
"id": 0,
"type": 0
}
],
"evaluation_mode": 99,
"limit": 0,
"name": "pds",
"repository_id": 1,
"window_size": 0
})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_missing_type(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={
"conditions": [
{
"content": "pds2021",
"id": 0,
"XXXtypeXXX": 99
}
],
"evaluation_mode": 0,
"limit": 0,
"name": "pds",
"repository_id": 1,
"window_size": 0
})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_wrong_type(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={
"conditions": [
{
"content": "pds2021",
"id": 0,
"type": 99
}
],
"evaluation_mode": 0,
"limit": 0,
"name": "pds",
"repository_id": 1,
"window_size": 0
})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_missing_content(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={
"conditions": [
{
"XXXcontentXXX": "pds2021",
"id": 0,
"type": 0
}
],
"evaluation_mode": 0,
"limit": 0,
"name": "pds",
"repository_id": 1,
"window_size": 0
})
assert r.status_code == 400
assert r.json["result"] == "failure"
def test_for_success(self, flask_client: Client, user_headers):
r = flask_client.post(f'/api/v1/repositories/1/alerts/', headers=user_headers,
json={
"conditions": [
{
"content": "pds2021",
"id": 0,
"type": 0
}
],
"evaluation_mode": 0,
"limit": 0,
"name": "pds",
"repository_id": 1,
"window_size": 0
})
assert r.status_code == 201
assert r.json["result"] == "success"
'''
# test del file condition
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)
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)
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)
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})
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
# 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)
assert r.status_code == 204
'''