Skip to content

Commit 410b9cc

Browse files
samyarpotlapallismlindauer
authored andcommitted
Fixed mapping issue in score_definitions
1 parent 2a3607f commit 410b9cc

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

src/sasctl/_services/score_definitions.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66
import json
77
from typing import Union
88

9-
from ..core import current_session, delete, get, sasctl_command
10-
from .cas_management import CASManagement
11-
from .model_repository import ModelRepository
12-
from .service import Service
9+
# from ..core import current_session, delete, get, sasctl_command
10+
from sasctl.core import current_session, delete, get, sasctl_command
11+
from sasctl._services.cas_management import CASManagement
12+
from sasctl._services.model_repository import ModelRepository
13+
from sasctl._services.service import Service
14+
15+
# from .cas_management import CASManagement
16+
# from .model_repository import ModelRepository
17+
# from .service import Service
1318

1419

1520
class ScoreDefinitions(Service):
@@ -96,6 +101,7 @@ def create_score_definition(
96101
"variableName": input_item["name"],
97102
}
98103
inputMapping.append(var)
104+
99105
except:
100106
print("This model does not have the optional 'inputVariables' parameter.")
101107

@@ -149,3 +155,11 @@ def create_score_definition(
149155
"/definitions", data=json.dumps(save_score_def), headers=headers_score_def
150156
)
151157
# The response information of the score definition can be seen as a JSON as well as a RestOBJ
158+
159+
160+
score_def = ScoreDefinitions()
161+
print(
162+
score_def.create_score_definition(
163+
"test_name", "69ed3f2f-b4c2-43e7-9f9c-24d009e20e16", "HMEQPERF_1_Q1"
164+
)
165+
)

tests/unit/test_score_definitions.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
from sasctl._services.score_definitions import ScoreDefinitions as sd
2626

2727

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+
2840
def test_create_score_definition():
2941
"""
3042
Test Cases:
@@ -40,16 +52,6 @@ def test_create_score_definition():
4052
with mock.patch("sasctl.core.Session._get_authorization_token"):
4153
current_session("example.com", "username", "password")
4254

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-
5355
# Mocking the REST API calls and functions
5456
with mock.patch(
5557
"sasctl._services.model_repository.ModelRepository.get_model"
@@ -129,18 +131,21 @@ def test_create_score_definition():
129131
assert response
130132

131133
# 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
144149
get_table.return_value.status_code = 200
145150
get_table.return_value.json.return_value = {
146151
"tableName": "test_table"
@@ -153,6 +158,6 @@ def test_create_score_definition():
153158
assert response
154159
assert post.call_count == 3
155160

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

Comments
 (0)