-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssessmentFunction.py
57 lines (48 loc) · 2.32 KB
/
AssessmentFunction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import base64
import json
from EncryptAndDecryptFunction import doDecryption, doEncryption, pprintJsonFormat
from HttpRequestFunction import getHttpRequest, loadFile, postHttpRequestJson, saveJsonFormat
fileName = "demoConfig.json"
#ASM-2106-000048
def AssessmentInit():
print("Assessment Init")
def addAssessment():
updateAssessmentPayload()
addAssessmentURL = "https://uat-api.ssg-wsg.sg/tpg/assessments"
assessmentPayload = loadFile("AssessmentPayLoad.json")
ciptertext = doEncryption(assessmentPayload.encode())
response = postHttpRequestJson(addAssessmentURL, ciptertext.decode())
plainText = doDecryption(response.text)
pprintJsonFormat(plainText)
json_load = json.loads(plainText.decode())
if (json_load["status"] < 400):
print("Successfully Add Assessment")
saveAssessmentRefNumber(json_load["data"]["assessment"]["referenceNumber"])
else:
raise Exception
def deleteAssessment():
deleteAssessmentURL = "https://uat-api.ssg-wsg.sg/tpg/assessments/details/ASM-2106-000048"
payload = "{\"assessment\":{\"action\": \"void\"}}"
cancelPayloadEncrypt = doEncryption(payload.encode())
resp = postHttpRequestJson(deleteAssessmentURL, cancelPayloadEncrypt.decode())
plainText = doDecryption(resp.text)
pprintJsonFormat(plainText)
#Update the latest Run Id, UEN ,and Course Ref Number payload according to the config file
def updateAssessmentPayload():
#load config File
configInfo = loadFile(fileName)
configInfoJson = json.loads(configInfo)
#load Attendance Json File
assessmentPayload = loadFile("AssessmentPayLoad.json")
assessmentPayload = json.loads(assessmentPayload)
#Update the latest value and save
assessmentPayload["assessment"]["trainingPartner"]["code"] = configInfoJson["code"]
assessmentPayload["assessment"]["course"]["referenceNumber"] = configInfoJson["CourseRefNum"]
assessmentPayload["assessment"]["trainingPartner"]["uen"] = configInfoJson["UEN"]
assessmentPayload["assessment"]["course"]["run"]["id"] = configInfoJson["runId"]
saveJsonFormat(assessmentPayload, "AssessmentPayLoad.json")
def saveAssessmentRefNumber(assessmentRefNumber):
configInfo = loadFile(fileName)
configInfo = json.loads(configInfo)
configInfo["AssessmentRefNum"] = assessmentRefNumber
saveJsonFormat(configInfo, fileName)