Skip to content

Commit

Permalink
Merge branch 'main' into tamirkamara/2396-support-standard-app-servic…
Browse files Browse the repository at this point in the history
…e-plans
  • Loading branch information
tamirkamara authored Aug 9, 2022
2 parents 5cf2058 + 478e07d commit 6606e33
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.7"
__version__ = "0.4.8"
1 change: 1 addition & 0 deletions api_app/resources/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
AIRLOCK_REQUEST_ILLEGAL_STATUS_CHANGE = "Airlock request status change was illegal"
AIRLOCK_REQUEST_IN_PROGRESS = "Airlock request is being processed, please try again later."
AIRLOCK_REQUEST_IS_CANCELED = "Airlock request was cancelled."
AIRLOCK_REQUEST_UNACCESSIBLE = "Airlock request is in invalid status: rejected, blocked or failed."
AIRLOCK_REQUEST_INVALID_STATUS = "Airlock request status is unknown."
AIRLOCK_UNAUTHORIZED_TO_SA = "User is unauthorized to access airlock request files in its current status."
AIRLOCK_NOT_ENABLED_IN_WORKSPACE = "Airlock is not enabled in this workspace."
Expand Down
4 changes: 4 additions & 0 deletions api_app/services/airlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def validate_request_status(airlock_request: AirlockRequest):
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=strings.AIRLOCK_REQUEST_IN_PROGRESS)
elif airlock_request.status == AirlockRequestStatus.Cancelled:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=strings.AIRLOCK_REQUEST_IS_CANCELED)
elif airlock_request.status in [AirlockRequestStatus.Failed,
AirlockRequestStatus.Rejected,
AirlockRequestStatus.Blocked]:
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=strings.AIRLOCK_REQUEST_UNACCESSIBLE)
else:
return

Expand Down
40 changes: 39 additions & 1 deletion api_app/tests_ma/test_services/test_airlock.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from fastapi import HTTPException, status
import pytest
from services.airlock import validate_user_allowed_to_access_storage_account, get_required_permission

from resources import strings
from services.airlock import validate_user_allowed_to_access_storage_account, get_required_permission, \
validate_request_status
from models.domain.airlock_resource import AirlockResourceType
from models.domain.airlock_request import AirlockRequest, AirlockRequestStatus, AirlockRequestType
from tests_ma.test_api.conftest import create_workspace_owner_user, create_workspace_researcher_user
Expand Down Expand Up @@ -60,6 +63,41 @@ def test_validate_user_is_allowed_to_access_grants_access_to_user_with_a_valid_r
) is None)


@pytest.mark.parametrize('airlock_status',
[AirlockRequestStatus.ApprovalInProgress,
AirlockRequestStatus.RejectionInProgress,
AirlockRequestStatus.BlockingInProgress])
def test_validate_request_status_raises_error_for_in_progress_request(airlock_status):
airlock_request = sample_airlock_request(airlock_status)
with pytest.raises(HTTPException) as ex:
validate_request_status(airlock_request)

assert ex.value.status_code == status.HTTP_400_BAD_REQUEST
assert ex.value.detail == strings.AIRLOCK_REQUEST_IN_PROGRESS


def test_validate_request_status_raises_error_for_canceled_request():
airlock_request = sample_airlock_request(AirlockRequestStatus.Cancelled)
with pytest.raises(HTTPException) as ex:
validate_request_status(airlock_request)

assert ex.value.status_code == status.HTTP_400_BAD_REQUEST
assert ex.value.detail == strings.AIRLOCK_REQUEST_IS_CANCELED


@pytest.mark.parametrize('airlock_status',
[AirlockRequestStatus.Failed,
AirlockRequestStatus.Rejected,
AirlockRequestStatus.Blocked])
def test_validate_request_status_raises_error_for_unaccessible_request(airlock_status):
airlock_request = sample_airlock_request(airlock_status)
with pytest.raises(HTTPException) as ex:
validate_request_status(airlock_request)

assert ex.value.status_code == status.HTTP_400_BAD_REQUEST
assert ex.value.detail == strings.AIRLOCK_REQUEST_UNACCESSIBLE


@pytest.mark.parametrize('airlock_status',
[AirlockRequestStatus.Submitted,
AirlockRequestStatus.InReview,
Expand Down

0 comments on commit 6606e33

Please sign in to comment.