Nothing left to do today, getting 500 errors for the enrollment and attempt resource endpoints. Everything is set up correctly for hitting those endpoints, but not sure if the 500 is on me or on the application/engineers.
This commit is contained in:
@ -18,6 +18,7 @@ Notes:
|
||||
|
||||
import json
|
||||
from utils import calls, apikeys
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
JSONDOC = "./api_docs.json"
|
||||
BASEURL = "https://api.northpass.com/v2/migration"
|
||||
@ -35,7 +36,6 @@ tupee = [
|
||||
# Get Resources (Done after you've added them from below)
|
||||
# *************************
|
||||
("/v2/migration/projects/{project_id}/items/{item_id}/resources", "get"),
|
||||
|
||||
# *************************
|
||||
# Post calls for creating new resources.
|
||||
# *************************
|
||||
@ -129,13 +129,14 @@ def get_all_projects():
|
||||
|
||||
if ret["data"] == "":
|
||||
for items in ret["data"]:
|
||||
project_ids.append(items['id'])
|
||||
project_ids.append(items["id"])
|
||||
print(f"{ items['attributes']['name'] } -- { items['id'] }")
|
||||
else:
|
||||
print("Looks like there are no projects created!")
|
||||
|
||||
return project_ids
|
||||
|
||||
|
||||
def delete_all_projects():
|
||||
"""
|
||||
Deletes all projects after returning the uuids of the projects currently available.
|
||||
@ -145,6 +146,7 @@ def delete_all_projects():
|
||||
url = f"{BASEURL}/projects/{proj}"
|
||||
calls.delete(url)
|
||||
|
||||
|
||||
def get_specific_project():
|
||||
"""
|
||||
Returns results from a specific project.
|
||||
@ -154,9 +156,95 @@ def get_specific_project():
|
||||
calls.get(url)
|
||||
|
||||
|
||||
def create_enrollment():
|
||||
project_id = "6c7a21c2-de35-4b9d-9b80-a235401783af"
|
||||
item_id = "80b95e38-78d1-44b9-8d9f-be96d9c7bf6e"
|
||||
learner_uuid = "101d891d-f145-4cb2-8f7f-f0d8a90a743e"
|
||||
course_uuid = "0d41bb57-bc65-4e05-adfd-58436ed0bd50"
|
||||
now = datetime.now()
|
||||
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print("Creating Enrollment")
|
||||
enroll_payload = {
|
||||
"data": {
|
||||
"attributes": {
|
||||
"enrolled_at": formatted_now,
|
||||
"course_id": course_uuid,
|
||||
"person_id": learner_uuid,
|
||||
}
|
||||
}
|
||||
}
|
||||
enroll_url = calls.post(
|
||||
f"{BASEURL}/projects/{project_id}/items/{item_id}/enrollment_resources",
|
||||
enroll_payload,
|
||||
)
|
||||
print(f"{enroll_url} response is")
|
||||
if enroll_url != 404:
|
||||
print("Cool, enrollment resource has been created. Let's create an attempt.")
|
||||
create_attempt(project_id, item_id, learner_uuid, course_uuid)
|
||||
else:
|
||||
print("A 404 error occurred.")
|
||||
|
||||
|
||||
def create_attempt():
|
||||
course_uuid = "f1b92092-60bd-4d52-922a-e462f132b69c"
|
||||
project_id = "6c7a21c2-de35-4b9d-9b80-a235401783af"
|
||||
item_id = "80b95e38-78d1-44b9-8d9f-be96d9c7bf6e"
|
||||
learner_uuid = "101d891d-f145-4cb2-8f7f-f0d8a90a743e"
|
||||
now = datetime.now()
|
||||
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
start_time = datetime.now() - timedelta(hours=2)
|
||||
print(f"{formatted_now} ---- {start_time}")
|
||||
new_attempt_payload = {
|
||||
"data": {
|
||||
"attributes": {
|
||||
"uuid": course_uuid,
|
||||
"display_name": f"norm@rsmsn.co's Attempt for course {course_uuid}",
|
||||
"learner_id": learner_uuid,
|
||||
"course_id": course_uuid,
|
||||
"progress": "100",
|
||||
"started_at": "2024-09-01 14:35:55",
|
||||
"completed_at": formatted_now,
|
||||
"completed_activities": [
|
||||
{"uuid": "1111", "completed_at": formatted_now}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
print(new_attempt_payload)
|
||||
attempt_call = calls.post(
|
||||
f"{BASEURL}/projects/{project_id}/items/{item_id}/course_attempt_resources",
|
||||
new_attempt_payload,
|
||||
)
|
||||
print(attempt_call)
|
||||
|
||||
|
||||
"""
|
||||
If the learner is enrolled, we can go straight to creating an attempt.
|
||||
(
|
||||
"/v2/migration/projects/{project_id}/items/{item_id}/course_attempt_resources",
|
||||
"post",
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
def check_resources():
|
||||
print("Checking resources")
|
||||
get_resources_url = (
|
||||
f"{baseurl}/migration/projects/{PROJ_ID}/items/{ITEM_ID}/resources"
|
||||
)
|
||||
get_resources = Calls.get(get_resources_url)
|
||||
if get_resources["data"] == []:
|
||||
print("Something went wrong. No resources were created.")
|
||||
else:
|
||||
print("We're in! Here's the data:")
|
||||
print(get_resources)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# delete_all_projects()
|
||||
# read_json_docs()
|
||||
# create_project()
|
||||
get_all_projects()
|
||||
# get_all_projects()
|
||||
# get_specific_project()
|
||||
create_enrollment()
|
||||
# create_attempt()
|
||||
|
||||
Reference in New Issue
Block a user