refactor: Ran pyupgrade on openedx/{testing, tests}
This commit is contained in:
@@ -3,15 +3,14 @@ Test signal handlers for completion.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
import ddt
|
||||
import pytest
|
||||
import six
|
||||
from completion import handlers
|
||||
from completion.models import BlockCompletion
|
||||
from completion.test_utils import CompletionSetUpMixin
|
||||
from django.test import TestCase
|
||||
from mock import patch
|
||||
from pytz import utc
|
||||
from xblock.completable import XBlockCompletionMode
|
||||
from xblock.core import XBlock
|
||||
@@ -47,7 +46,7 @@ class ScorableCompletionHandlerTestCase(CompletionSetUpMixin, TestCase):
|
||||
COMPLETION_SWITCH_ENABLED = True
|
||||
|
||||
def setUp(self):
|
||||
super(ScorableCompletionHandlerTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.block_key = self.context_key.make_usage_key(block_type='problem', block_id='red')
|
||||
|
||||
def call_scorable_block_completion_handler(self, block_key, score_deleted=None):
|
||||
@@ -63,8 +62,8 @@ class ScorableCompletionHandlerTestCase(CompletionSetUpMixin, TestCase):
|
||||
handlers.scorable_block_completion(
|
||||
sender=self,
|
||||
user_id=self.user.id,
|
||||
course_id=six.text_type(self.context_key),
|
||||
usage_id=six.text_type(block_key),
|
||||
course_id=str(self.context_key),
|
||||
usage_id=str(block_key),
|
||||
weighted_earned=0.0,
|
||||
weighted_possible=3.0,
|
||||
modified=datetime.utcnow().replace(tzinfo=utc),
|
||||
@@ -124,8 +123,8 @@ class ScorableCompletionHandlerTestCase(CompletionSetUpMixin, TestCase):
|
||||
grades_signals.PROBLEM_WEIGHTED_SCORE_CHANGED.send_robust(
|
||||
sender=self,
|
||||
user_id=self.user.id,
|
||||
course_id=six.text_type(self.context_key),
|
||||
usage_id=six.text_type(self.block_key),
|
||||
course_id=str(self.context_key),
|
||||
usage_id=str(self.block_key),
|
||||
weighted_earned=0.0,
|
||||
weighted_possible=3.0,
|
||||
modified=datetime.utcnow().replace(tzinfo=utc),
|
||||
@@ -143,15 +142,15 @@ class DisabledCompletionHandlerTestCase(CompletionSetUpMixin, TestCase):
|
||||
COMPLETION_SWITCH_ENABLED = False
|
||||
|
||||
def setUp(self):
|
||||
super(DisabledCompletionHandlerTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.block_key = self.context_key.make_usage_key(block_type='problem', block_id='red')
|
||||
|
||||
def test_disabled_handler_does_not_submit_completion(self):
|
||||
handlers.scorable_block_completion(
|
||||
sender=self,
|
||||
user_id=self.user.id,
|
||||
course_id=six.text_type(self.context_key),
|
||||
usage_id=six.text_type(self.block_key),
|
||||
course_id=str(self.context_key),
|
||||
usage_id=str(self.block_key),
|
||||
weighted_earned=0.0,
|
||||
weighted_possible=3.0,
|
||||
modified=datetime.utcnow().replace(tzinfo=utc),
|
||||
|
||||
@@ -3,7 +3,6 @@ Test models, managers, and validators.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import six
|
||||
from completion import models
|
||||
from completion.test_utils import CompletionWaffleTestMixin, submit_completions_for_testing
|
||||
from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH
|
||||
@@ -11,7 +10,6 @@ from django.core.exceptions import ValidationError
|
||||
from django.test import TestCase
|
||||
from edx_toggles.toggles.testutils import override_waffle_switch
|
||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
from six.moves import range, zip
|
||||
|
||||
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
@@ -42,7 +40,7 @@ class CompletionSetUpMixin(CompletionWaffleTestMixin):
|
||||
"""
|
||||
def set_up_completion(self):
|
||||
self.user = UserFactory()
|
||||
self.block_key = UsageKey.from_string(u'block-v1:edx+test+run+type@video+block@doggos')
|
||||
self.block_key = UsageKey.from_string('block-v1:edx+test+run+type@video+block@doggos')
|
||||
self.completion = models.BlockCompletion.objects.create(
|
||||
user=self.user,
|
||||
context_key=self.block_key.context_key,
|
||||
@@ -59,7 +57,7 @@ class SubmitCompletionTestCase(CompletionSetUpMixin, TestCase):
|
||||
semantics.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(SubmitCompletionTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.override_waffle_switch(True)
|
||||
self.set_up_completion()
|
||||
|
||||
@@ -100,7 +98,7 @@ class SubmitCompletionTestCase(CompletionSetUpMixin, TestCase):
|
||||
assert models.BlockCompletion.objects.count() == 2
|
||||
|
||||
def test_new_block(self):
|
||||
newblock = UsageKey.from_string(u'block-v1:edx+test+run+type@video+block@puppers')
|
||||
newblock = UsageKey.from_string('block-v1:edx+test+run+type@video+block@puppers')
|
||||
with self.assertNumQueries(SELECT + UPDATE + 4 * SAVEPOINT):
|
||||
_, isnew = models.BlockCompletion.objects.submit_completion(
|
||||
user=self.user,
|
||||
@@ -128,7 +126,7 @@ class CompletionDisabledTestCase(CompletionSetUpMixin, TestCase):
|
||||
Tests that completion API is not called when the feature is disabled.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(CompletionDisabledTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
# insert one completion record...
|
||||
self.set_up_completion()
|
||||
# ...then disable the feature.
|
||||
@@ -152,13 +150,13 @@ class SubmitBatchCompletionTestCase(CompletionWaffleTestMixin, TestCase):
|
||||
semantics.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(SubmitBatchCompletionTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.override_waffle_switch(True)
|
||||
|
||||
self.block_key = UsageKey.from_string('block-v1:edx+test+run+type@video+block@doggos')
|
||||
self.course_key_obj = CourseKey.from_string('course-v1:edx+test+run')
|
||||
self.user = UserFactory()
|
||||
CourseEnrollmentFactory.create(user=self.user, course_id=six.text_type(self.course_key_obj))
|
||||
CourseEnrollmentFactory.create(user=self.user, course_id=str(self.course_key_obj))
|
||||
|
||||
def test_submit_batch_completion(self):
|
||||
blocks = [(self.block_key, 1.0)]
|
||||
@@ -194,14 +192,14 @@ class BatchCompletionMethodTests(CompletionWaffleTestMixin, TestCase):
|
||||
Tests for the classmethods that retrieve course/block completion data.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(BatchCompletionMethodTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.override_waffle_switch(True)
|
||||
|
||||
self.user = UserFactory.create()
|
||||
self.other_user = UserFactory.create()
|
||||
self.course_key = CourseKey.from_string("edX/MOOC101/2049_T2")
|
||||
self.other_course_key = CourseKey.from_string("course-v1:ReedX+Hum110+1904")
|
||||
self.block_keys = [UsageKey.from_string("i4x://edX/MOOC101/video/{}".format(number)) for number in range(5)]
|
||||
self.block_keys = [UsageKey.from_string(f"i4x://edX/MOOC101/video/{number}") for number in range(5)]
|
||||
self.block_keys_with_runs = [key.replace(course_key=self.course_key) for key in self.block_keys]
|
||||
self.other_course_block_keys = [self.other_course_key.make_usage_key('html', '1')]
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ from completion.models import BlockCompletion
|
||||
from completion.services import CompletionService
|
||||
from completion.test_utils import CompletionWaffleTestMixin
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from six.moves import range
|
||||
|
||||
from openedx.core.djangolib.testing.utils import skip_unless_lms
|
||||
from common.djangoapps.student.tests.factories import UserFactory
|
||||
@@ -28,7 +27,7 @@ class CompletionServiceTestCase(CompletionWaffleTestMixin, SharedModuleStoreTest
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(CompletionServiceTestCase, cls).setUpClass()
|
||||
super().setUpClass()
|
||||
cls.course = CourseFactory.create()
|
||||
with cls.store.bulk_operations(cls.course.id):
|
||||
cls.chapter = ItemFactory.create(
|
||||
@@ -80,7 +79,7 @@ class CompletionServiceTestCase(CompletionWaffleTestMixin, SharedModuleStoreTest
|
||||
cls.problems = [cls.problem, cls.problem2, cls.problem3, cls.problem4, cls.problem5]
|
||||
|
||||
def setUp(self):
|
||||
super(CompletionServiceTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.override_waffle_switch(True)
|
||||
self.user = UserFactory.create()
|
||||
self.other_user = UserFactory.create()
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Test models, managers, and validators.
|
||||
"""
|
||||
|
||||
|
||||
import ddt
|
||||
import six
|
||||
from completion.test_utils import CompletionWaffleTestMixin
|
||||
from completion.waffle import ENABLE_COMPLETION_TRACKING_SWITCH
|
||||
from django.urls import reverse
|
||||
@@ -38,7 +36,7 @@ class CompletionBatchTestCase(CompletionWaffleTestMixin, ModuleStoreTestCase):
|
||||
"""
|
||||
Create the test data.
|
||||
"""
|
||||
super(CompletionBatchTestCase, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.url = reverse('completion:v1:completion-batch')
|
||||
|
||||
# Enable the waffle flag for all tests
|
||||
@@ -49,21 +47,21 @@ class CompletionBatchTestCase(CompletionWaffleTestMixin, ModuleStoreTestCase):
|
||||
org='TestX', number='101', display_name='Test',
|
||||
default_store=ModuleStoreEnum.Type.split,
|
||||
)
|
||||
assert six.text_type(self.course.id) == self.COURSE_KEY
|
||||
assert str(self.course.id) == self.COURSE_KEY
|
||||
self.problem = ItemFactory.create(
|
||||
parent=self.course, category="problem", display_name="Test Problem", publish_item=False,
|
||||
)
|
||||
assert six.text_type(self.problem.location) == self.BLOCK_KEY
|
||||
assert str(self.problem.location) == self.BLOCK_KEY
|
||||
# And an old mongo course:
|
||||
self.course_deprecated = CourseFactory.create(
|
||||
org='TestX', number='201', display_name='Test',
|
||||
default_store=ModuleStoreEnum.Type.mongo,
|
||||
)
|
||||
assert six.text_type(self.course_deprecated.id) == self.COURSE_KEY_DEPRECATED
|
||||
assert str(self.course_deprecated.id) == self.COURSE_KEY_DEPRECATED
|
||||
self.problem_deprecated = ItemFactory.create(
|
||||
parent=self.course_deprecated, category="problem", display_name="Test Problem",
|
||||
)
|
||||
assert six.text_type(self.problem_deprecated.location) == self.BLOCK_KEY_DEPRECATED
|
||||
assert str(self.problem_deprecated.location) == self.BLOCK_KEY_DEPRECATED
|
||||
|
||||
# Create users
|
||||
self.staff_user = UserFactory(is_staff=True)
|
||||
@@ -152,8 +150,8 @@ class CompletionBatchTestCase(CompletionWaffleTestMixin, ModuleStoreTestCase):
|
||||
400,
|
||||
{
|
||||
"detail": (
|
||||
u"Block with key: 'block-v1:TestX+101+OtherCourse+type@problem+block@other' "
|
||||
u"is not in context {}".format(COURSE_KEY)
|
||||
"Block with key: 'block-v1:TestX+101+OtherCourse+type@problem+block@other' "
|
||||
"is not in context {}".format(COURSE_KEY)
|
||||
)
|
||||
}
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user