@@ -65,79 +65,47 @@ def test_create_score_execution():
65
65
with mock .patch (
66
66
"sasctl._services.score_definitions.ScoreDefinitions.get_definition"
67
67
) as get_definition :
68
- with mock .patch (
69
- "sasctl._services.score_execution.ScoreExecution.list_executions"
70
- ) as list_executions :
71
- with mock .patch (
72
- "sasctl._services.score_execution.ScoreExecution.delete_execution"
73
- ) as delete_execution :
74
- with mock .patch (
75
- "sasctl._services.score_execution.ScoreExecution.post"
76
- ) as post :
77
- # Invalid score definition id test case
78
- get_definition .return_value = None
79
- with pytest .raises (HTTPError ):
80
- se .create_score_execution (score_definition_id = "12345" )
81
-
82
- # Valid score definition id and invalid list_executions argument test case
83
- get_definition_mock = CustomMock (
84
- json_info = {
85
- "inputData" : {
86
- "libraryName" : "cas-shared-default" ,
87
- "tableName" : "test_table" ,
88
- },
89
- "name" : "score_def_name" ,
90
- "objectDescriptor" : {
91
- "name" : "test_model" ,
92
- "type" : "sas.publish.example" ,
93
- "uri" : "/modelPublish/models/example" ,
94
- },
95
- },
96
- )
97
- get_definition .return_value = get_definition_mock
98
- list_executions .return_value = None
99
- with pytest .raises (HTTPError ):
100
- se .create_score_execution (score_definition_id = "12345" )
101
-
102
- # Valid list_executions argument with execution already running but invalid delete_execution argument test case
103
- list_mock_execution = CustomMock (
104
- json_info = {"count" : 1 , "items" : [{"id" : "1234" }]},
105
- )
106
- list_executions .return_value = list_mock_execution
107
- delete_execution .return_value .status_code = 404
108
- with pytest .raises (HTTPError ):
109
- se .create_score_execution (score_definition_id = "12345" )
110
-
111
- # Valid list_executions argument with execution already running but valid delete_execution argument test case
112
- list_executions .return_value = list_mock_execution
113
- delete_execution .return_value .status_code = 200
114
- response = se .create_score_execution (score_definition_id = "3456" )
115
- assert response
116
-
117
- # Valid list_executions argument without execution already running test case
118
- list_mock_execution_diff_count = CustomMock (
119
- json_info = {"count" : 0 , "items" : [{"id" : "1234" }]},
120
- )
121
- list_executions .return_value = list_mock_execution_diff_count
122
- response = se .create_score_execution (score_definition_id = "12345" )
123
- assert response
124
-
125
- # Checking whether the output table name remained the default empty string or the default changed as writted in score_execution
126
- data = post .call_args
127
- json_data = json .loads (data .kwargs ["data" ])
128
- assert json_data ["outputTable" ]["tableName" ] != ""
129
-
130
- # With output table specified within create_score_execution arguments test case
131
- response = se .create_score_execution (
132
- score_definition_id = "12345" , output_table_name = "example_table"
133
- )
134
- assert response
135
- assert post .call_count == 3
136
-
137
- # Checking whether specified output table name or the default output table name is in the response
138
- data = post .call_args
139
- json_data = json .loads (data .kwargs ["data" ])
140
- assert (
141
- target ["outputTable" ]["tableName" ]
142
- == json_data ["outputTable" ]["tableName" ]
143
- )
68
+ with mock .patch ("sasctl._services.score_execution.ScoreExecution.post" ) as post :
69
+ # Invalid score definition id test case
70
+ get_definition .return_value = None
71
+ with pytest .raises (HTTPError ):
72
+ se .create_score_execution (score_definition_id = "12345" )
73
+
74
+ # Valid score definition id and invalid list_executions argument test case
75
+ get_definition_mock = CustomMock (
76
+ json_info = {
77
+ "inputData" : {
78
+ "libraryName" : "cas-shared-default" ,
79
+ "tableName" : "test_table" ,
80
+ },
81
+ "name" : "score_def_name" ,
82
+ "objectDescriptor" : {
83
+ "name" : "test_model" ,
84
+ "type" : "sas.publish.example" ,
85
+ "uri" : "/modelPublish/models/example" ,
86
+ },
87
+ },
88
+ )
89
+ get_definition .return_value = get_definition_mock
90
+ response = se .create_score_execution (score_definition_id = "3456" )
91
+ assert response
92
+
93
+ # Checking whether the output table name remained the default empty string or the default changed as writted in score_execution
94
+ data = post .call_args
95
+ json_data = json .loads (data .kwargs ["data" ])
96
+ assert json_data ["outputTable" ]["tableName" ] != ""
97
+
98
+ # With output table specified within create_score_execution arguments test case
99
+ response = se .create_score_execution (
100
+ score_definition_id = "12345" , output_table_name = "example_table"
101
+ )
102
+ assert response
103
+ assert post .call_count == 2
104
+
105
+ # Checking whether specified output table name or the default output table name is in the response
106
+ data = post .call_args
107
+ json_data = json .loads (data .kwargs ["data" ])
108
+ assert (
109
+ target ["outputTable" ]["tableName" ]
110
+ == json_data ["outputTable" ]["tableName" ]
111
+ )
0 commit comments