Commit 228d1d92 authored by David Foucher's avatar David Foucher

Add test for non existing authorized user to update rule

parent 5d07fb68
......@@ -539,6 +539,20 @@ async def test_authentification(patch_authorisations, client, mock_get):
}
async def test_authentification_with_no_authorisation(patch_authorisations, client, mock_get):
body = {
"email": "test@test.fr",
"password": "test",
"file": "/règles nationales/CPF.rules"
}
auth = []
patch_authorisations(auth)
mock_get(status_code=500)
resp = await client.post("/authentification", body=body)
assert resp.status == HTTPStatus.INTERNAL_SERVER_ERROR
async def test_authentification_with_2_records(patch_authorisations, client, mock_get):
body = {
"email": "test@test.fr",
......
......@@ -246,10 +246,13 @@ async def authent(request, response):
else:
continue
if data.get('token') != atoken and not authsuccess:
if not bool(AUTHORIZED):
raise ValueError("Il n'existe pas encore d'autorisations (fichier"
+ " authorisations.csv vide ou inexistant).")
elif data.get('token') != atoken and not authsuccess:
raise HttpError(HTTPStatus.UNAUTHORIZED,
'Le token n\'est pas reconnu.')
elif data.get('token','') == '' and not authsuccess:
elif data.get('token', '') == '' and not authsuccess:
raise HttpError(HTTPStatus.UNAUTHORIZED,
'Email ou mot de passe non reconnu.')
else:
......@@ -290,44 +293,3 @@ async def source_save(request, response):
raise HttpError(HTTPStatus.NOT_MODIFIED, message="Aucune modification apportée")
except ValueError as err:
raise HttpError(HTTPStatus.UNPROCESSABLE_ENTITY, message=err)
# now = datetime.datetime.today().strftime('%y%m%d%H%M')
# request_data = request.json
# commit_message = request_data.get('comment')
# filename = request_data.get('filename')
# content = request_data.get('content')
# mail = request_data.get('author_email')
# name = request_data.get('author_name')
# gl = gitlab.Gitlab('https://git.beta.pole-emploi.fr', private_token=GITLAB_TOKEN)
# project = gl.projects.get('open-source/trefle', lazy=True)
# branch = f"modification-{fold_name(request_data.get('title')).lower()}"
# original_fingerprint = hash(project.files.get(filename,
# ref='master').decode().decode())
# modified_fingerprint = hash(content)
# is_modified = original_fingerprint != modified_fingerprint
# data = {
# 'branch': f'RULE-{branch}-{now}',
# 'start_branch': 'master',
# 'commit_message': commit_message,
# 'author_email': mail,
# 'author_name': name,
# 'actions': [
# {
# 'action': 'update',
# 'file_path': filename,
# 'content': content,
# }
# ]
# }
# if not is_modified:
# raise HttpError(HTTPStatus.NOT_MODIFIED, message="Aucune modification apportée")
# if mail in COMMIT_AUTHORIZED:
# commit = project.commits.create(data)
# else:
# raise HttpError(HTTPStatus.UNAUTHORIZED, 'Code vide ou invalide')
# response.json = commit.attributes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment