-
Notifications
You must be signed in to change notification settings - Fork 57
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
Merge App and Api by creating a common utility for core logic #316
Conversation
01f9aa3
to
8c66e7a
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.
Can you post the test case status for these changes?
src/api/views.py
Outdated
@@ -20,6 +20,7 @@ | |||
from api.serializers import ValidateSerializer,ConvertSerializer,CompareSerializer,CheckLicenseSerializer,SubmitLicenseSerializer,ValidateSerializerReturn,ConvertSerializerReturn,CompareSerializerReturn,CheckLicenseSerializerReturn,SubmitLicenseSerializerReturn |
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.
Don't force push commits. Makes it hard to review changes. We can squash commits while merging
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.
Alright. I won't force push commits from now onwards.
src/api/views.py
Outdated
httpstatus = output.get('status', None) | ||
context_dict = output.get('context', None) | ||
response = output.get('response', None) | ||
message = output.get('message', None) |
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.
Have a common function for this too, as this conversion if needed in every api
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.
Sure. I was thinking the same. It would reduce code redundancy as this piece of code is used both in app and api.
src/api/views.py
Outdated
elif httpstatus == 400: | ||
returnstatus = status.HTTP_400_BAD_REQUEST | ||
else: | ||
returnstatus = status.HTTP_404_NOT_FOUND |
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.
Common function for this conversion too
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.
Alright.
src/api/views.py
Outdated
elif response: | ||
result = response | ||
else: | ||
result = message |
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.
Can we simplify this logic?
query.result=result | ||
query.status=httpstatus | ||
ValidateFileUpload.objects.filter(file=uploaded_file).update(result=result,status=httpstatus) | ||
ValidateFileUpload.objects.filter(file=uploaded_file).update(result=result, status=httpstatus) | ||
serial = ValidateSerializerReturn(instance=query) | ||
return Response( | ||
serial.data, status=returnstatus |
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.
Can we other functions apart from views functions like extensionGiven
, getFileFormat
, etc. to a utils.py file? Basically this file should contain only core logic, other business logic function should be moved to utils function
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.
Sure. I will do that.
|
||
|
||
def license_compare_helper(request): | ||
""" |
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.
Just confirming that you copied this code from app/views.py, right? Coz similar api code was outdated.
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.
Yeah, it's the code from app views.
src/api/views.py
Outdated
@@ -20,6 +20,7 @@ | |||
from api.serializers import ValidateSerializer,ConvertSerializer,CompareSerializer,CheckLicenseSerializer,SubmitLicenseSerializer,ValidateSerializerReturn,ConvertSerializerReturn,CompareSerializerReturn,CheckLicenseSerializerReturn,SubmitLicenseSerializerReturn | |||
from api.oauth import generate_github_access_token,convert_to_auth_token,get_user_from_token | |||
from app.models import LicenseRequest | |||
from app.core import initialise_jpype, license_validate_helper, license_check_helper |
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.
Import core instead of specific functions. Make it hard to maintain and also better understanding of code flow.
@Ugtan Looks good in the first iteration. Can you also attach test case run results here after every PR? Just want to make sure we are not opening a new hole in our application. |
@rtgdk Sure, I will attach a screenshot of the API test cases once I complete the other two APIs for compare and convert most probably today itself. And, I'm testing both APP and API to make sure both of them work simultaneously. |
@rtgdk Could you take a look at it once, please? @SantiagoTorres Would definitely appreciate your review as well. thanks I have merged App and Api code for license Validate, Compare, Convert, and Check License. I will also attach the screenshot of the test cases of all these functions below. For Check License API(Not passing idk why) Getting this re-module error not sure why. Will try to fix it. |
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.
Great work @Ugtan left some comments to fix. I'll it merge it post that.
src/app/core.py
Outdated
from time import time | ||
from traceback import format_exc | ||
from urllib.parse import urljoin | ||
from app.views import formatToContentType, getFileFormat |
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.
Move these functions to utils.py, views.py should just be a wrapper over helper functions.
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.
Alright, I will move these functions to utils.py file
src/app/core.py
Outdated
from time import time | ||
from traceback import format_exc | ||
from urllib.parse import urljoin | ||
from app.views import formatToContentType, getFileFormat |
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.
This will be a cyclic dependency kind of logic, views depends on core, core depends on views for some functions
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.
Understood.
@Ugtan For check license api, it might be failing due to python3 str/bytes issue on spdx_license_matcher side. |
@Ugtan Merged the django3 PR. Please rebase those changes with this PR and post the test results again for both app and api. Also, please make sure that we didn't lose any functions/functionality due to these changes. I'll merge after you post the results post rebase. |
I'm not quite sure regarding the issue as it works perfectly when I use the check license functionality on localhost. I also tried to run the SPDX License Matcher and it worked as well. I'm facing the issue only while running the test cases to check license API.
I will rebase the branch and share the test results for both the app and API with you. I have briefly tested everything and the test cases also working fine so I don't think we will run into any problem. @rtgdk |
@Ugtan Can you share the test results? |
Here you go @rtgdk Test results for the API: The APP test cases are failing after the changes I'm not quite sure why 15 of them failed with the following error: I'm not quite sure why are these test cases failing. I also tried to dig a little but couldn't figure out the root cause for the error to occur. I have been trying for some time, Could you help if possible? @rtgdk |
@rtgdk Fixed it. Both APP and API test cases are working. I have already shared the API ones. The test results for the app: |
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.
@Ugtan Thanks! Merging this.
Fixes #287
The PR adds support for a common utility that contains all the core logic required for the SPDX Online tools. Both App and Api make use of this utility so, we don't have to test the app and api individually. It reduces redundancy and makes it easy to test the modules and maintain them.