-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(1139): refactor forest client validator as util service, refs: #1139
- Loading branch information
1 parent
490510d
commit bb78831
Showing
9 changed files
with
170 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
server/admin_management/api/app/services/validator/forest_client_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import logging | ||
from typing import List, Union | ||
|
||
from api.app.constants import FOREST_CLIENT_STATUS | ||
from api.app.schemas import ForestClientValidationResponse | ||
|
||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def forest_client_number_exists( | ||
forest_client_find_result: List[ForestClientValidationResponse], | ||
) -> bool: | ||
# Exact client number search - should only contain 1 result. | ||
return len(forest_client_find_result) == 1 | ||
|
||
|
||
def forest_client_active( | ||
forest_client_find_result: List[ForestClientValidationResponse], | ||
) -> bool: | ||
return ( | ||
( | ||
forest_client_find_result[0][FOREST_CLIENT_STATUS["KEY"]] | ||
== FOREST_CLIENT_STATUS["CODE_ACTIVE"] | ||
) | ||
if forest_client_number_exists(forest_client_find_result) | ||
else False | ||
) | ||
|
||
|
||
def get_forest_client_status( | ||
forest_client_find_result: List[ForestClientValidationResponse], | ||
) -> Union[str, None]: | ||
return ( | ||
forest_client_find_result[0][FOREST_CLIENT_STATUS["KEY"]] | ||
if forest_client_number_exists(forest_client_find_result) | ||
else None | ||
) |
55 changes: 0 additions & 55 deletions
55
server/admin_management/api/app/services/validator_service.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
server/admin_management/tests/services/test_forest_client_validator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import logging | ||
|
||
from api.app.constants import FOREST_CLIENT_STATUS | ||
from api.app.integration.forest_client_integration import ForestClientIntegrationService | ||
from api.app.services.validator.forest_client_validator import ( | ||
forest_client_number_exists, | ||
forest_client_active, | ||
get_forest_client_status, | ||
) | ||
from tests.constants import ( | ||
TEST_FOREST_CLIENT_NUMBER, | ||
TEST_NON_EXIST_FOREST_CLIENT_NUMBER, | ||
TEST_INACTIVE_FOREST_CLIENT_NUMBER, | ||
) | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
def test_forest_client_number_exists( | ||
forest_client_integration_service: ForestClientIntegrationService, | ||
): | ||
# find active forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test forest_client_number_exists return true | ||
assert forest_client_number_exists(forest_client_validator_return) is True | ||
|
||
# find inactive forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_INACTIVE_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test forest_client_number_exists return true | ||
assert forest_client_number_exists(forest_client_validator_return) is True | ||
|
||
# find non exist forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_NON_EXIST_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test forest_client_number_exists return false | ||
assert forest_client_number_exists(forest_client_validator_return) is False | ||
|
||
|
||
def test_forest_client_active(forest_client_integration_service: ForestClientIntegrationService): | ||
# find active forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test forest_client_active return true | ||
assert forest_client_active(forest_client_validator_return) is True | ||
|
||
# find inactive forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_INACTIVE_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test forest_client_active return false | ||
assert forest_client_active(forest_client_validator_return) is False | ||
|
||
# find non exist forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_NON_EXIST_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test forest_client_active return false | ||
assert forest_client_active(forest_client_validator_return) is False | ||
|
||
|
||
def test_get_forest_client_status( | ||
forest_client_integration_service: ForestClientIntegrationService, | ||
): | ||
# find active forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test get_forest_client_status return forest client information | ||
assert get_forest_client_status( | ||
forest_client_validator_return | ||
) == FOREST_CLIENT_STATUS.get("CODE_ACTIVE") | ||
|
||
# find inactive forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_INACTIVE_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test get_forest_client_status return forest client information | ||
assert get_forest_client_status(forest_client_validator_return) == "DAC" | ||
|
||
# find non exist forest client number | ||
forest_client_validator_return = ( | ||
forest_client_integration_service.find_by_client_number( | ||
TEST_NON_EXIST_FOREST_CLIENT_NUMBER | ||
) | ||
) | ||
# test get_forest_client_status return None | ||
assert get_forest_client_status(forest_client_validator_return) is None |
Oops, something went wrong.