diff --git a/Scripts/Migration_tool/Mark_Course_As_Complete/mark_course_as_complete.py b/Scripts/Migration_tool/Mark_Course_As_Complete/mark_course_as_complete.py index 47e86999..88b94d19 100644 --- a/Scripts/Migration_tool/Mark_Course_As_Complete/mark_course_as_complete.py +++ b/Scripts/Migration_tool/Mark_Course_As_Complete/mark_course_as_complete.py @@ -168,13 +168,15 @@ def check_resources(): def create_project_item(): - project_name = "Mark Course as Complete" + project_name = "Testing Course" item_name = "Courses to Mark as Complete" proj_payload = { - "data": { + "data": + { "type": "migration_projects", "attributes": {"name": project_name}, } + } proj_full_url = f"{baseurl}/migration/{PROJ_URL}" print(proj_full_url) @@ -184,10 +186,14 @@ def create_project_item(): item_full_url = f"{baseurl}/migration/{PROJ_URL}/{PROJ_ID}/{ITEM_URL}" item_payload = { - "data": { + "data": + { "type": "migration_items", - "attributes": {"type": "courses"}, + "attributes": { + "type": "courses" + }, } + } item_return = Calls.post(item_full_url, item_payload) ITEM_ID = item_return["data"]["id"] diff --git a/Scripts/Migration_tool/migration_playground.py b/Scripts/Migration_tool/migration_playground.py index 55ea36e1..af048041 100644 --- a/Scripts/Migration_tool/migration_playground.py +++ b/Scripts/Migration_tool/migration_playground.py @@ -110,13 +110,17 @@ def create_project(): """ project_name = "" payload = { - "data": { + "data":[ + { "type": "migration_projects", - "attributes": {"name": project_name}, - } + "attributes": { + "name": project_name + }, + } + ] } url = f"{BASEURL}/projects" - Calls.post(url, payload) + calls.post(url, payload) def get_all_projects(): @@ -127,7 +131,7 @@ def get_all_projects(): url = f"{BASEURL}/projects" ret = calls.get(url) - if ret["data"] == "": + if ret["data"] != []: for items in ret["data"]: project_ids.append(items["id"]) print(f"{ items['attributes']['name'] } -- { items['id'] }") @@ -142,9 +146,12 @@ def delete_all_projects(): Deletes all projects after returning the uuids of the projects currently available. """ project_ids = get_all_projects() + print("Within delete function") for proj in project_ids: + print(proj) url = f"{BASEURL}/projects/{proj}" - calls.delete(url) + resp = calls.delete(url) + print(resp) def get_specific_project(): @@ -157,6 +164,9 @@ def get_specific_project(): def create_enrollment(): + # important!! Received this error: + # {"errors":[{"data":{"0":["size cannot be less than 1"]}},{"resource_type":["resource type and item type must be same"]}]} + project_id = "6c7a21c2-de35-4b9d-9b80-a235401783af" item_id = "80b95e38-78d1-44b9-8d9f-be96d9c7bf6e" learner_uuid = "101d891d-f145-4cb2-8f7f-f0d8a90a743e" @@ -165,24 +175,31 @@ def create_enrollment(): formatted_now = now.strftime("%Y-%m-%d %H:%M:%S") print("Creating Enrollment") enroll_payload = { - "data": { + "data": [ + { "attributes": { - "enrolled_at": formatted_now, - "course_id": course_uuid, - "person_id": learner_uuid, + "uuid": "1234567890", + "display_name": "Enrollment Resource Test", + "type": "course", + "data": { + "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(f"{enroll_url.status_code} response is") + if enroll_url.status_code == 404 or enroll_url.status_code == 400: + print(f"A {enroll_url.status_code} error occurred.") + else: 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(): @@ -226,18 +243,30 @@ def create_attempt(): ) """ +def get_item(): + project_id = "6c7a21c2-de35-4b9d-9b80-a235401783af" + item_id = "80b95e38-78d1-44b9-8d9f-be96d9c7bf6e" + print("Checking item") + get_item_url = f"{BASEURL}/projects/{project_id}/items/{item_id}" + get_item = calls.get(get_item_url) + print(get_item) + + def check_resources(): + PROJ_ID = "6c7a21c2-de35-4b9d-9b80-a235401783af" + ITEM_ID = "80b95e38-78d1-44b9-8d9f-be96d9c7bf6e" print("Checking resources") get_resources_url = ( - f"{baseurl}/migration/projects/{PROJ_ID}/items/{ITEM_ID}/resources" + f"{BASEURL}/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) + get_resources = calls.get(get_resources_url) + print(get_resources) + # 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__": @@ -246,5 +275,7 @@ if __name__ == "__main__": # create_project() # get_all_projects() # get_specific_project() - create_enrollment() + # create_enrollment() + # check_resources() + get_item() # create_attempt() diff --git a/Scripts/Migration_tool/utils/__pycache__/calls.cpython-310.pyc b/Scripts/Migration_tool/utils/__pycache__/calls.cpython-310.pyc index d52ed0e1..022e26ac 100644 Binary files a/Scripts/Migration_tool/utils/__pycache__/calls.cpython-310.pyc and b/Scripts/Migration_tool/utils/__pycache__/calls.cpython-310.pyc differ diff --git a/Scripts/Migration_tool/utils/calls.py b/Scripts/Migration_tool/utils/calls.py index 93689847..b3af6fc4 100644 --- a/Scripts/Migration_tool/utils/calls.py +++ b/Scripts/Migration_tool/utils/calls.py @@ -12,7 +12,7 @@ BASEURL = "https://api.northpass.com/v2" def get(url): try: get_response = requests.get(url, headers=HEADERS) - # print(f"Executed Get Request. Status code is {get_response.status_code}") + print(f"Executed Get Request. Status code is {get_response.status_code}") except HTTPError as h: print( f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}" @@ -48,11 +48,11 @@ def post(url, payload): def delete(url): try: - get_response = requests.delete(url, headers=HEADERS) - # print(f"Executed Get Request. Status code is {get_response.status_code}") + delete_response = requests.delete(url, headers=HEADERS) + print(f"Executed Delete Request. Status code is {delete_response.status_code}") except HTTPError as h: print( - f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}" + f"Error occurred. Here's the info: {h} and status code: {delete_response.status_code}" ) finally: - return get_response + return delete_response