25
25
from sasctl ._services .score_definitions import ScoreDefinitions as sd
26
26
27
27
28
+ class CustomMock :
29
+ def __init__ (self , status_code , json_info ):
30
+ self .status_code = status_code
31
+ self .json_info = json_info
32
+
33
+ def get (self , key1 , key2 = None , key3 = None ):
34
+ if key2 is None and key3 is None :
35
+ return self .json_info [key1 ]
36
+ else :
37
+ return self .json_info [key1 ][key2 ][key3 ]
38
+
39
+
28
40
def test_create_score_definition ():
29
41
"""
30
42
Test Cases:
@@ -40,16 +52,6 @@ def test_create_score_definition():
40
52
with mock .patch ("sasctl.core.Session._get_authorization_token" ):
41
53
current_session ("example.com" , "username" , "password" )
42
54
43
- # TARGET = {
44
- # "mappings": [
45
- # {"mappingValue": "first", "mappingType": "datasource", "variableName": "first"},
46
- # {"mappingValue": "second", "mappingType": "datasource", "variableName": "second"},
47
- # {"mappingValue": "third", "mappingType": "datasource", "variableName": "third"}
48
- # ]
49
- # }
50
-
51
- # target = copy.deepcopy(TARGET)
52
-
53
55
# Mocking the REST API calls and functions
54
56
with mock .patch (
55
57
"sasctl._services.model_repository.ModelRepository.get_model"
@@ -129,18 +131,21 @@ def test_create_score_definition():
129
131
assert response
130
132
131
133
# Checking response with inputVariables in model elements
132
- get_model .return_value .status_code = 200
133
- get_model .return_value .json .return_value = {
134
- "id" : "12345" ,
135
- "projectId" : "54321" ,
136
- "projectVersionId" : "67890" ,
137
- "name" : "test_model" ,
138
- "inputVariables" : [
139
- {"name" : "first" },
140
- {"name" : "second" },
141
- {"name" : "third" },
142
- ],
143
- }
134
+ model_mock_execution = CustomMock (
135
+ status_code = 200 ,
136
+ json_info = {
137
+ "id" : "12345" ,
138
+ "projectId" : "54321" ,
139
+ "projectVersionId" : "67890" ,
140
+ "name" : "test_model" ,
141
+ "inputVariables" : [
142
+ {"name" : "first" },
143
+ {"name" : "second" },
144
+ {"name" : "third" },
145
+ ],
146
+ },
147
+ )
148
+ get_model .return_value = model_mock_execution
144
149
get_table .return_value .status_code = 200
145
150
get_table .return_value .json .return_value = {
146
151
"tableName" : "test_table"
@@ -153,6 +158,6 @@ def test_create_score_definition():
153
158
assert response
154
159
assert post .call_count == 3
155
160
156
- # data = post.call_args
157
- # json_data = json.loads(data.kwargs["data"])
158
- # assert target ["mappings"] == json_data["mappings" ]
161
+ data = post .call_args
162
+ json_data = json .loads (data .kwargs ["data" ])
163
+ assert json_data ["mappings" ] != [ ]
0 commit comments