Skip to content

Commit c705539

Browse files
samyarpotlapallismlindauer
authored andcommitted
Updating files for testing
1 parent a081f49 commit c705539

File tree

3 files changed

+69
-13
lines changed

3 files changed

+69
-13
lines changed

src/sasctl/_services/score_execution.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,22 @@ def create_score_execution(
7070
if not output_table_name:
7171
output_table_name = f"{model_name}_{score_definition_id}"
7272

73-
# Deleting any score executions that are already executing the same score definition
74-
try:
75-
score_execution = cls.get(
76-
f"/executions?filter=eq(scoreExecutionRequest.scoreDefinitionId,%27{score_definition_id}%27)"
73+
# Getting all score executions that are using the inputted score_definition_id
74+
75+
score_execution = cls.list_executions(filter=f"eq(scoreDefinitionId, '{score_definition_id}')")
76+
77+
if score_execution.status_code >= 400:
78+
raise HTTPError(
79+
{
80+
f"Something went wrong in the GET statement. See error: {score_execution.json()}"
81+
}
7782
)
78-
execution_count = score_execution.get("count") # Exception catch location
79-
if execution_count == 1:
80-
execution_id = score_execution.get("items", [0], ["id"])
81-
deleted_score_execution = cls.delete_execution(execution_id)
82-
print(deleted_score_execution)
83-
except KeyError:
84-
print("There may not be a score execution already running.")
83+
84+
# Checking the count of the execution list to see if there are any score executions for this score_definition_id already running
85+
execution_count = score_execution.get("count") # Exception catch location
86+
if execution_count == 1:
87+
execution_id = score_execution.get("items", [0], ["id"])
88+
deleted_execution = cls.delete_execution(execution_id)
8589

8690
headers_score_exec = {"Content-Type": "application/json"}
8791

tests/unit/test_score_definitions.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,38 @@ def test_create_score_definition():
3636
"""
3737
with mock.patch("sasctl.core.Session._get_authorization_token"):
3838
current_session("example.com", "username", "password")
39+
40+
TARGET = {
41+
"name": MODEL_NAME,
42+
"projectId": PROJECT_ID,
43+
"modeler": USER,
44+
"description": "model description",
45+
"function": "Classification",
46+
"algorithm": "Dummy Algorithm",
47+
"tool": "pytest",
48+
"champion": True,
49+
"role": "champion",
50+
"immutable": True,
51+
"retrainable": True,
52+
"scoreCodeType": None,
53+
"targetVariable": None,
54+
"trainTable": None,
55+
"classificationEventProbabilityVariableName": None,
56+
"classificationTargetEventValue": None,
57+
"location": None,
58+
"properties": [
59+
{"name": "custom1", "value": 123, "type": "numeric"},
60+
{"name": "custom2", "value": "somevalue", "type": "string"},
61+
# {'name': 'customDate', 'value': 1672462800000, 'type': 'date'},
62+
{"name": "customDateTime", "value": 1672481272000, "type": "dateTime"},
63+
],
64+
"inputVariables": [],
65+
"outputVariables": [],
66+
"version": 2,
67+
}
68+
69+
# Passed params should be set correctly
70+
target = copy.deepcopy(TARGET)
3971

4072
with mock.patch(
4173
"sasctl._services.model_repository.ModelRepository.get_model"

tests/unit/test_score_execution.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from sasctl import current_session
2323
from sasctl.core import RestObj, VersionInfo
2424
from sasctl._services.score_definitions import ScoreDefinitions as sd
25+
from sasctl._services.score_execution import ScoreExecution as se
2526

2627

2728
def test_create_score_execution():
@@ -32,9 +33,12 @@ def test_create_score_execution():
3233
-no
3334
- Valid execution id?
3435
35-
-Valid count key?
36+
-Valid count key? -> treated like input mapping -> no because i think it's required
37+
- output table -> treat like input mapping but within the create_score_execution step (do I for library and server in score definition thought?)
3638
3739
"""
40+
with mock.patch("sasctl.core.Session._get_authorization_token"):
41+
current_session("example.com", "username", "password")
3842

3943
with mock.patch(
4044
"sasctl._services.score_definitions.ScoreDefinitions.get_definition"
@@ -45,5 +49,21 @@ def test_create_score_execution():
4549
with mock.patch(
4650
"sasctl._services.score_execution.ScoreExecution.delete_execution"
4751
) as delete_execution:
48-
pytest.skip()
52+
with mock.patch(
53+
"sasctl._services.score_execution.ScoreExecution.post"
54+
) as post:
55+
get_definition.return_value.status_code = 404
56+
with pytest.raises(HTTPError):
57+
se.create_score_execution(
58+
score_definition_id="12345",
59+
)
60+
get_definition.return_value.status_code = 200
61+
get_execution.return_value.status_code = 400 #we might need a separate try except here to show that 404 statement is weird and should exit the program
62+
with pytest.raises(HTTPError):
63+
se.create_score_execution(
64+
score_definition_id="12345",
65+
)
66+
#stdout or pytest.raises but without ending program?
67+
68+
#pytest.skip()
4969
# raise HTTP error?

0 commit comments

Comments
 (0)