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

Merge App and Api by creating a common utility for core logic #316

Merged
merged 7 commits into from
Jul 16, 2021

Conversation

Ugtan
Copy link
Collaborator

@Ugtan Ugtan commented Jun 22, 2021

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.

@Ugtan Ugtan force-pushed the merge_api_app branch 2 times, most recently from 01f9aa3 to 8c66e7a Compare June 26, 2021 23:28
Copy link
Collaborator

@rtgdk rtgdk left a 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
Copy link
Collaborator

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

Copy link
Collaborator Author

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)
Copy link
Collaborator

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

Copy link
Collaborator Author

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
Copy link
Collaborator

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

Copy link
Collaborator Author

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
Copy link
Collaborator

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
Copy link
Collaborator

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

Copy link
Collaborator Author

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):
"""
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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.

@rtgdk
Copy link
Collaborator

rtgdk commented Jun 27, 2021

@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.

@Ugtan
Copy link
Collaborator Author

Ugtan commented Jun 28, 2021

@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.

@Ugtan
Copy link
Collaborator Author

Ugtan commented Jun 30, 2021

@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 Validate API
ValidateApiTests

For Convert API
ConvertApiTests

For Compare API
compareApiTests

For Check License API(Not passing idk why)
image

Getting this re-module error not sure why. Will try to fix it.
image

@Ugtan Ugtan requested a review from rtgdk June 30, 2021 03:20
Copy link
Collaborator

@rtgdk rtgdk left a 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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Understood.

@rtgdk
Copy link
Collaborator

rtgdk commented Jul 4, 2021

@Ugtan For check license api, it might be failing due to python3 str/bytes issue on spdx_license_matcher side.

@rtgdk
Copy link
Collaborator

rtgdk commented Jul 4, 2021

@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.

@Ugtan
Copy link
Collaborator Author

Ugtan commented Jul 4, 2021

For check license api, it might be failing due to python3 str/bytes issue on spdx_license_matcher side.

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.

@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 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

@rtgdk
Copy link
Collaborator

rtgdk commented Jul 8, 2021

@Ugtan Can you share the test results?

@Ugtan
Copy link
Collaborator Author

Ugtan commented Jul 9, 2021

Here you go @rtgdk

Test results for the API:

image

image

image

image

The APP test cases are failing after the changes I'm not quite sure why 15 of them failed with the following error:

image
image

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

@Ugtan
Copy link
Collaborator Author

Ugtan commented Jul 12, 2021

@rtgdk Fixed it. Both APP and API test cases are working. I have already shared the API ones. The test results for the app:

image

Copy link
Collaborator

@rtgdk rtgdk left a 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.

@rtgdk rtgdk merged commit 220fed0 into spdx:python3 Jul 16, 2021
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.

2 participants