Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Turnitin API workflow test with openedx XBlock #4

Merged
merged 12 commits into from
Jan 30, 2024

Conversation

nandodev-net
Copy link
Contributor

@nandodev-net nandodev-net commented Oct 5, 2023

Turnitin API test xblock

this xblock describes the Turnitin API workflow to generate de similarity report and online viewer.

this workflow has 7 steps (handlers) with self explanatory names:

  1. get_eula_agreement
    with a given eula_version, request EULA html text to Turnitin API.
  1. accept_eula_agreement
    with a given eula_version and user_id, accept EULA agreement to Turnitin API.
  1. 1 . create_turnitin_submission_object
    with a user and submission data payload, create a submission object in Turnitin. Response: submission_id.
  1. 2 . upload_turnitin_submission_file
    with submission_id upload the document assessment.
  1. get_submission_status
    with submission_id get the uploaded document status {CREATED - PROCESSING - COMPLETE - ERROR}
  1. generate_similarity_report
    if the submission_status is COMPLETE, with submission_id generate the similarity report in Turnitin.
  1. get_similarity_report_status
    with submission_id get the similarity report status {PROCESSING - COMPLETE}.
  1. create_similarity_viewer
    if similarity report status is COMPLETE, with submission_id get the Viewer URL.

Testing

Follow the workflow gif ahead... Secret Key on basecamp

@nandodev-net nandodev-net force-pushed the FG/turnitin_api_test_xblock branch from 60e046f to 510e21d Compare October 5, 2023 13:24
@nandodev-net nandodev-net requested review from a team, Ian2012, BryanttV, mariajgrimaldi and johnvente and removed request for a team October 5, 2023 15:48
@nandodev-net nandodev-net marked this pull request as ready for review October 5, 2023 16:01
Copy link
Contributor

@BryanttV BryanttV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format the code, maybe you could use black 🤔, and don't forget the docstring when everything is ready.

platform_plugin_turnitin/turnitin.py Outdated Show resolved Hide resolved
platform_plugin_turnitin/turnitin.py Outdated Show resolved Hide resolved
platform_plugin_turnitin/turnitin.py Outdated Show resolved Hide resolved
platform_plugin_turnitin/turnitin.py Outdated Show resolved Hide resolved
platform_plugin_turnitin/turnitin.py Show resolved Hide resolved
platform_plugin_turnitin/turnitin.py Outdated Show resolved Hide resolved
platform_plugin_turnitin/turnitin.py Outdated Show resolved Hide resolved
platform_plugin_turnitin/turnitin.py Outdated Show resolved Hide resolved
platform_plugin_turnitin/turnitin_client/handlers.py Outdated Show resolved Hide resolved
@mariajgrimaldi
Copy link
Collaborator

If this is ready for review, please use an adequate name for the PR. Thanks!

dict: The status of the similarity report generation process.
"""

payload = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do these settings mean? should we have a plugin setting called TURNITIN_SIMILARITY_REPORT_SETTINGS for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariajgrimaldi Yes... we should define each parameter from the optional settings that Turnitin offers to obtain the result we expect from them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariajgrimaldi The only issue is that there are nested variables throughout the request structure. So in order to create the settings variable, we have to check the docs to create many variables as need and put them throughout the request structure. We need more time and owner's review to do this

Comment on lines 57 to 63
method_map = {
"get": requests.get,
"post": requests.post,
"put": requests.put,
"delete": requests.delete,
"patch": requests.patch,
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a method_map, you could pass directly the method:
turnitin_api_handler(requests.get, ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I believe it would be better to create the method_map within a separate function. This way, we can modify the method conditionals based on a list of strings, rather than a list of methods. This approach:
if request_method.lower() in ["post", "put", "patch"]
is more elegant than this:
if request_method in [requests.patch, request.post,....]
and certainly cleaner than a series of:
if request_method == requests.post: ... elif ... : ... else: ...

Comment on lines 71 to 79
# Calling the appropriate method
if request_method.lower() in ["post", "put", "patch"]:
response = method_func(
f"{TII_API_URL}/api/v1/{url_prefix}", headers=headers, json=data
)
else:
response = method_func(
f"{TII_API_URL}/api/v1/{url_prefix}", headers=headers, params=data
)
Copy link
Collaborator

@mariajgrimaldi mariajgrimaldi Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url = f"{TII_API_URL}/api/v1/{url_prefix}"
request_load = {
 "headers": headers
}
if params:
   request_load["params"] = params
if data:
   request_load["data"] = data
response = method_func(url, **request_load) 

When using get, the caller send params as an argument. When using the rest the caller sends data. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it :)
I propose this

args = {
    "headers": headers,
    "json" if request_method.lower() in ["post", "put", "patch"] else "params": data
}

response = method_func(f"{TII_API_URL}/api/v1/{url_prefix}", **args)

f"{TII_API_URL}/api/v1/{url_prefix}", headers=headers, params=data
)

return response
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be response.json()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a couple of endpoints in a different format, that's why I use .json() in some @XBlock.json_handler methods, and not in the turnitin_api_handler method

@nandodev-net nandodev-net changed the title Fg/turnitin api test xblock feat: Turnitin API workflow test with openedx XBlock Oct 9, 2023
@Ian2012 Ian2012 force-pushed the FG/turnitin_api_test_xblock branch from e5274a9 to c08dde3 Compare October 10, 2023 18:26
@nandodev-net nandodev-net force-pushed the FG/turnitin_api_test_xblock branch from c08dde3 to e5274a9 Compare October 10, 2023 18:27
@Ian2012 Ian2012 force-pushed the FG/turnitin_api_test_xblock branch from e5274a9 to 6bdae62 Compare October 10, 2023 19:13
Copy link
Collaborator

@mariajgrimaldi mariajgrimaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we'll use for the integration looks good! Thank you

@Ian2012
Copy link
Contributor

Ian2012 commented Oct 13, 2023

@mariajgrimaldi please let me know if we can merge this one

@BryanttV BryanttV force-pushed the FG/turnitin_api_test_xblock branch from d978932 to 77e2356 Compare January 30, 2024 20:13
@BryanttV BryanttV merged commit db58663 into main Jan 30, 2024
5 checks passed
@mariajgrimaldi mariajgrimaldi deleted the FG/turnitin_api_test_xblock branch April 24, 2024 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants