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: add create external certificate task #76

Merged
merged 3 commits into from
Aug 8, 2023

Conversation

andrey-canon
Copy link
Collaborator

Description

https://edunext.atlassian.net/browse/FUTUREX-481

Testing instructions

Before

After

@github-actions github-actions bot added the size/s label Aug 3, 2023
@github-actions github-actions bot added the test label Aug 4, 2023
@github-actions github-actions bot added size/m m lines label and removed size/s labels Aug 4, 2023
@andrey-canon andrey-canon changed the base branch from and/add_certificates_api to and/add_basic_authentication August 4, 2023 22:35
@andrey-canon andrey-canon force-pushed the and/certifictae_task branch 2 times, most recently from a85da6d to 2b62c92 Compare August 5, 2023 01:09
@andrey-canon andrey-canon marked this pull request as ready for review August 5, 2023 01:09
@andrey-canon
Copy link
Collaborator Author

@johanv26 this is ready for review


def get_student_api():
"""Allow to get the student_api module from
https://github.com/eduNEXT/edunext-platform/blob/ednx-release/mango.master/common/djangoapps/student/models_api.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

student_api is weird because the file name is models_api but there are no classes. May be is my habit to relate models to classes hehehe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you check the certificate code openedx changes the models_api to student_api, so that's why a used the same openedx convention, however I'm not using this anymore, this belongs to a first version, and now I'm getting the user english name from the certificate data. So I will remove this

@@ -63,7 +64,7 @@ def create_course_notifications(course_key, **kwargs): # pylint: disable=unused
create_course_notifications_task.delay(course_id=str(course_key))


def certificate_publisher(certificate, **kwargs): # pylint: disable=unused-argument
def certificate_publisher(certificate, metadata, **kwargs): # pylint: disable=unused-argument
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def certificate_publisher(certificate, metadata, **kwargs): # pylint: disable=unused-argument
def certificate_publisher(certificate, metadata, *args, **kwargs): # pylint: disable=unused-argument

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO that is not necessary, since the signal doesn't' send any args

logger = logging.getLogger(__name__)


def _user_has_passing_grade(user, course_id):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok this also brings some refactor.

def _user_has_passing_grade(user, course_id):
"""Determines if a user has passed a course based on the grading policies.
Args:
user<User>: Instace of Django User model.
course_id<str>: Unique course identifier.
Returns:
course_grade.passed<bool>: True if the user has passed the course, otherwise False
"""
course_grade = CourseGradeFactory().read(user, course_key=CourseKey.from_string(course_id))
return course_grade.passed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, Imoved some common method to an different file in order to use them in multiple places, the name starting with _ could be consider as wrong since that have a private connotation, but I didn't make bigger this pr by adding name changes

certificate_publisher(self.certificate_data, self.metadata)

generate_data_mock.assert_called_with(
timestamp=self.metadata.time,
Copy link
Collaborator

Choose a reason for hiding this comment

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

the time of the object where is generated, or is auto generated?

self.metadata = EventsMetadata(
event_type="org.openedx.learning.certificate.created.v1",
minorversion=0,
)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@johanseto johanseto Aug 8, 2023

Choose a reason for hiding this comment

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

But in this case what return Self.metadata.time
That could raise an error?if its optional...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Defaults to current time in UTC.


@patch("eox_nelp.signals.receivers._generate_external_certificate_data")
@patch("eox_nelp.signals.receivers.create_external_certificate")
def test_create_call(self, mock_task, generate_data_mock):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def test_create_call(self, mock_task, generate_data_mock):
def test_create_call(self, create_external_certificate_mock, generate_data_mock):

this is not more explicit?

User = get_user_model()


def _generate_external_certificate_data(timestamp, certificate_data):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def _generate_external_certificate_data(timestamp, certificate_data):
def _generate_futurex_external_certificate_data(timestamp, certificate_data):

??
Because we have a function like dispatch futurex progress?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I used futurex because that is the name of the service. In this case I have no idea how the service name's but probably it's not futurex since the base url is different

@andrey-canon andrey-canon changed the base branch from and/add_basic_authentication to master August 8, 2023 18:24
Copy link
Collaborator

@johanseto johanseto left a comment

Choose a reason for hiding this comment

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

LGTM in my opinion

@andrey-canon andrey-canon merged commit 7c7401a into master Aug 8, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/m m lines label test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants