2021-05-14 21:33:36 +00:00
|
|
|
from flask.testing import Client
|
|
|
|
|
|
|
|
'''A file that contains tests of classes and methods for all the requests concerning an user.'''
|
|
|
|
|
2021-05-15 09:12:12 +00:00
|
|
|
|
2021-05-14 21:33:36 +00:00
|
|
|
# test del file repository_conditions
|
|
|
|
|
|
|
|
|
|
|
|
class TestConditionGetAllOfARepository:
|
|
|
|
def test_repository_not_found(self, flask_client: Client, user_headers):
|
2021-05-25 08:41:59 +00:00
|
|
|
r = flask_client.get(f'/api/v1/repositories/99/conditions/', headers=user_headers)
|
2021-05-14 21:33:36 +00:00
|
|
|
assert r.status_code == 404
|
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
def test__unauthorized_repository(self, flask_client: Client, admin_headers):
|
2021-05-25 08:41:59 +00:00
|
|
|
r = flask_client.get(f'/api/v1/repositories/1/conditions/', headers=admin_headers)
|
2021-05-14 21:33:36 +00:00
|
|
|
assert r.status_code == 403
|
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
def test_get_all_conditions_of_a_repository(self, flask_client: Client, user_headers):
|
2021-05-25 08:41:59 +00:00
|
|
|
r = flask_client.get(f'/api/v1/repositories/1/conditions/', headers=user_headers)
|
2021-05-14 21:33:36 +00:00
|
|
|
assert r.status_code == 200
|
|
|
|
assert r.json["result"] == "success"
|
|
|
|
|
2021-05-15 09:12:12 +00:00
|
|
|
|
|
|
|
class TestConditionPost:
|
|
|
|
def test_missing_type(self, flask_client: Client, user_headers):
|
2021-05-25 08:41:59 +00:00
|
|
|
r = flask_client.post(f'/api/v1/repositories/1/conditions/', headers=user_headers,
|
2021-05-15 09:12:12 +00:00
|
|
|
json={})
|
|
|
|
assert r.status_code == 400
|
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
def test_wrong_type(self, flask_client: Client, user_headers):
|
2021-05-25 08:41:59 +00:00
|
|
|
r = flask_client.post(f'/api/v1/repositories/1/conditions/', headers=user_headers,
|
2021-05-15 09:12:12 +00:00
|
|
|
json={"content": "string", "type": 99})
|
2021-05-15 10:00:49 +00:00
|
|
|
assert r.status_code == 400
|
2021-05-15 09:12:12 +00:00
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
def test_missing_content(self, flask_client: Client, user_headers):
|
2021-05-25 08:41:59 +00:00
|
|
|
r = flask_client.post(f'/api/v1/repositories/1/conditions/', headers=user_headers,
|
2021-05-15 09:12:12 +00:00
|
|
|
json={"type": 0})
|
2021-05-15 10:00:49 +00:00
|
|
|
assert r.status_code == 400
|
2021-05-15 09:12:12 +00:00
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
|
|
|
def test_for_success(self, flask_client: Client, user_headers):
|
2021-05-25 08:41:59 +00:00
|
|
|
r = flask_client.post(f'/api/v1/repositories/1/conditions/', headers=user_headers,
|
2021-05-15 10:00:49 +00:00
|
|
|
json={"content": "onlyForTest", "type": 0})
|
2021-05-15 09:12:12 +00:00
|
|
|
assert r.status_code == 201
|
|
|
|
assert r.json["result"] == "success"
|
2021-05-14 21:33:36 +00:00
|
|
|
|
|
|
|
# test del file condition
|
|
|
|
|
|
|
|
|
2021-05-15 10:00:49 +00:00
|
|
|
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)
|
2021-05-14 21:33:36 +00:00
|
|
|
assert r.status_code == 404
|
|
|
|
assert r.json["result"] == "failure"
|
|
|
|
|
2021-05-15 10:00:49 +00:00
|
|
|
# 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"
|
2021-05-14 21:33:36 +00:00
|
|
|
|
2021-05-15 10:00:49 +00:00
|
|
|
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
|
2021-05-14 21:33:36 +00:00
|
|
|
|
2021-05-15 10:00:49 +00:00
|
|
|
# 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
|