From abfed9502cac334aa1a7d5217ed233a0776e459d Mon Sep 17 00:00:00 2001 From: Arunmozhi Date: Thu, 14 Sep 2023 12:27:53 +0530 Subject: [PATCH] fix: quality issues --- .../statements/learner_course_completion.py | 17 +++++++++++--- .../statements/learner_course_enrollment.py | 6 ++--- .../test_statements/test_course_completion.py | 23 +++++++++++++------ .../test_learner_course_enrollment.py | 14 ++++++++--- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/integrated_channels/xapi/statements/learner_course_completion.py b/integrated_channels/xapi/statements/learner_course_completion.py index 12e5a79407..a4457312b0 100644 --- a/integrated_channels/xapi/statements/learner_course_completion.py +++ b/integrated_channels/xapi/statements/learner_course_completion.py @@ -4,7 +4,7 @@ from tincan import LanguageMap, Result, Score, Verb -from integrated_channels.xapi.constants import MAX_SCORE, MIN_SCORE, OBJECT_ID_URI, X_API_VERB_COMPLETED +from integrated_channels.xapi.constants import MAX_SCORE, MIN_SCORE, X_API_VERB_COMPLETED from integrated_channels.xapi.statements.base import EnterpriseStatement @@ -13,7 +13,18 @@ class LearnerCourseCompletionStatement(EnterpriseStatement): xAPI Statement to serialize data related to course completion. """ - def __init__(self, site, user, user_social_auth, course_overview, course_grade, object_type, object_id_type=OBJECT_ID_URI, *args, **kwargs): + def __init__( + self, + site, + user, + user_social_auth, + course_overview, + course_grade, + object_type, + object_id_type, + *args, + **kwargs + ): """ Initialize and populate statement with learner info and course info. @@ -22,7 +33,7 @@ def __init__(self, site, user, user_social_auth, course_overview, course_grade, user_social_auth (UserSocialAuth): UserSocialAuth object for learner course_overview (CourseOverview): course overview object containing course details. course_grade (CourseGrade): User grade in the course. - object_id_type (string): Either OBJECT_ID_PLAIN or OBJECT_ID_URI. Defaults to OBJECT_ID_URI. + object_id_type (string): Either OBJECT_ID_PLAIN or OBJECT_ID_URI. """ kwargs.update( actor=self.get_actor(user, user_social_auth), diff --git a/integrated_channels/xapi/statements/learner_course_enrollment.py b/integrated_channels/xapi/statements/learner_course_enrollment.py index ddb29d95f8..6bf2d36a4b 100644 --- a/integrated_channels/xapi/statements/learner_course_enrollment.py +++ b/integrated_channels/xapi/statements/learner_course_enrollment.py @@ -4,7 +4,7 @@ from tincan import LanguageMap, Verb -from integrated_channels.xapi.constants import OBJECT_ID_URI, X_API_VERB_REGISTERED +from integrated_channels.xapi.constants import X_API_VERB_REGISTERED from integrated_channels.xapi.statements.base import EnterpriseStatement @@ -13,7 +13,7 @@ class LearnerCourseEnrollmentStatement(EnterpriseStatement): xAPI statement to serialize data related to course registration. """ - def __init__(self, site, user, user_social_auth, course_overview, object_type, object_id_type=OBJECT_ID_URI, *args, **kwargs): + def __init__(self, site, user, user_social_auth, course_overview, object_type, object_id_type, *args, **kwargs): """ Initialize and populate statement with learner info and course info. @@ -22,7 +22,7 @@ def __init__(self, site, user, user_social_auth, course_overview, object_type, o user_social_auth (UserSocialAuth): UserSocialAuth object of learner for the enterprise if learner has a linked third party auth account course_overview (CourseOverview): course overview object containing course details. - object_id_type (string): Either OBJECT_ID_PLAIN or OBJECT_ID_URI. Defaults to OBJECT_ID_URI. + object_id_type (string): Either OBJECT_ID_PLAIN or OBJECT_ID_URI. """ kwargs.update( actor=self.get_actor(user, user_social_auth), diff --git a/tests/test_integrated_channels/test_xapi/test_statements/test_course_completion.py b/tests/test_integrated_channels/test_xapi/test_statements/test_course_completion.py index 180d3bf26f..6034fd2a1c 100644 --- a/tests/test_integrated_channels/test_xapi/test_statements/test_course_completion.py +++ b/tests/test_integrated_channels/test_xapi/test_statements/test_course_completion.py @@ -9,7 +9,12 @@ from faker import Factory as FakerFactory from pytest import mark -from integrated_channels.xapi.constants import OBJECT_ID_PLAIN, X_API_ACTIVITY_COURSE, X_API_VERB_COMPLETED +from integrated_channels.xapi.constants import ( + OBJECT_ID_PLAIN, + OBJECT_ID_URI, + X_API_ACTIVITY_COURSE, + X_API_VERB_COMPLETED, +) from integrated_channels.xapi.statements.learner_course_completion import LearnerCourseCompletionStatement from test_utils import factories @@ -151,7 +156,8 @@ def test_statement_course(self): self.mock_social_auth, self.course_overview, self.course_grade, - 'course' + 'course', + OBJECT_ID_URI, ) self.assertDictEqual(json.loads(statement.to_json()), self.expected_course) @@ -165,7 +171,8 @@ def test_statement_courserun(self): self.mock_social_auth, self.course_overview, self.course_grade, - 'courserun' + 'courserun', + OBJECT_ID_URI, ) self.assertDictEqual(json.loads(statement.to_json()), self.expected_courserun) @@ -179,7 +186,8 @@ def test_statement_notpassed(self): self.mock_social_auth, self.course_overview, self.course_grade_notpassed, - 'course' + 'course', + OBJECT_ID_URI, ) self.assertDictEqual(json.loads(statement.to_json()), self.expected_notpassed) @@ -193,8 +201,9 @@ def test_statement_with_different_course_id_formats(self): self.mock_social_auth, self.course_overview, self.course_grade, - 'course' - ) # defaults to URI format + 'course', + OBJECT_ID_URI, + ) self.assertEqual(json.loads(statement.to_json())["object"]["id"], self.object_id_course) @@ -205,7 +214,7 @@ def test_statement_with_different_course_id_formats(self): self.course_overview, self.course_grade, 'course', - OBJECT_ID_PLAIN + OBJECT_ID_PLAIN, ) self.assertEqual(json.loads(statement.to_json())["object"]["id"], self.plain_course_id) diff --git a/tests/test_integrated_channels/test_xapi/test_statements/test_learner_course_enrollment.py b/tests/test_integrated_channels/test_xapi/test_statements/test_learner_course_enrollment.py index 248e548392..608abc1056 100644 --- a/tests/test_integrated_channels/test_xapi/test_statements/test_learner_course_enrollment.py +++ b/tests/test_integrated_channels/test_xapi/test_statements/test_learner_course_enrollment.py @@ -9,7 +9,12 @@ from faker import Factory as FakerFactory from pytest import mark -from integrated_channels.xapi.constants import OBJECT_ID_PLAIN, X_API_ACTIVITY_COURSE, X_API_VERB_REGISTERED +from integrated_channels.xapi.constants import ( + OBJECT_ID_PLAIN, + OBJECT_ID_URI, + X_API_ACTIVITY_COURSE, + X_API_VERB_REGISTERED, +) from integrated_channels.xapi.statements.learner_course_enrollment import LearnerCourseEnrollmentStatement from test_utils import factories @@ -124,6 +129,7 @@ def test_statement_course(self): self.mock_social_auth, self.course_overview, 'course', + OBJECT_ID_URI, ) self.assertDictEqual(json.loads(statement.to_json()), self.expected_course) @@ -137,6 +143,7 @@ def test_statement_courserun(self): self.mock_social_auth, self.course_overview, 'courserun', + OBJECT_ID_URI, ) self.assertDictEqual(json.loads(statement.to_json()), self.expected_courserun) @@ -149,8 +156,9 @@ def test_statement_with_different_course_id_formats(self): self.user, self.mock_social_auth, self.course_overview, - 'course' - ) # defaults to URI format + 'course', + OBJECT_ID_URI, + ) self.assertEqual(json.loads(statement.to_json())["object"]["id"], self.object_id_course)