-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
60e046f
to
510e21d
Compare
There was a problem hiding this 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.
If this is ready for review, please use an adequate name for the PR. Thanks! |
platform_plugin_turnitin/turnitin.py
Outdated
dict: The status of the similarity report generation process. | ||
""" | ||
|
||
payload = { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
method_map = { | ||
"get": requests.get, | ||
"post": requests.post, | ||
"put": requests.put, | ||
"delete": requests.delete, | ||
"patch": requests.patch, | ||
} |
There was a problem hiding this comment.
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, ...)
There was a problem hiding this comment.
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: ...
# 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 | ||
) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
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
e5274a9
to
c08dde3
Compare
c08dde3
to
e5274a9
Compare
e5274a9
to
6bdae62
Compare
There was a problem hiding this 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
@mariajgrimaldi please let me know if we can merge this one |
- turnitin:get_user_data() : delete 'user_' prefix. - turnitin:get_django_user(): method created. - api_hander: get_request_method_func(): method created. - api_handler: turnitin_api_handler(): changes abour args.
d978932
to
77e2356
Compare
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:
Testing
Follow the workflow gif ahead... Secret Key on basecamp