Skip to content

Commit

Permalink
Use get
Browse files Browse the repository at this point in the history
  • Loading branch information
islean committed Mar 13, 2024
1 parent d2f2be3 commit 32d3bab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
21 changes: 13 additions & 8 deletions tests/integration/endpoints/test_patching_analyses.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from flask.testing import FlaskClient
from http import HTTPStatus
from trailblazer.dto.update_analyses import AnalysisUpdate, UpdateAnalyses
from unittest import mock

from flask import g
from flask.testing import FlaskClient

import trailblazer.server.api
from trailblazer.dto.update_analyses import AnalysisUpdate, UpdateAnalyses
from trailblazer.store.models import Analysis


Expand All @@ -13,11 +17,12 @@ def test_patch_analysis(client: FlaskClient, analysis: Analysis):
request = UpdateAnalyses(analyses=[update])
data: str = request.model_dump_json()

# WHEN patching the analysis
response = client.patch("/api/v1/analyses", data=data, content_type="application/json")
with mock.patch.object(trailblazer.server.api, "before_request", return_value=None):
# WHEN patching the analysis
response = client.patch("/api/v1/analyses", data=data, content_type="application/json")

# THEN it gives a success response
assert response.status_code == HTTPStatus.OK
# THEN it gives a success response
assert response.status_code == HTTPStatus.OK

# THEN it should return the analysis
assert response.json["analyses"]
# THEN it should return the analysis
assert response.json["analyses"]
3 changes: 2 additions & 1 deletion trailblazer/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ def patch_analyses(analysis_service: AnalysisService = Provide[Container.analysi
"""Update data (such as status, visibility, comments etc.) for multiple analyses at once."""
try:
request_data = UpdateAnalyses.model_validate(request.json)
user = g.get("current_user")
response: UpdateAnalysesResponse = analysis_service.update_analyses(
data=request_data, user=g.current_user
data=request_data, user=user
)
return jsonify(response.model_dump()), HTTPStatus.OK
except ValidationError as error:
Expand Down

0 comments on commit 32d3bab

Please sign in to comment.