Merge pull request #20162 from jolyonb/incr-200
INCR-200 Migrate common/djangoapps/util/tests and migrations
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.conf import settings
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
# Converted from the original South migration 0002_default_rate_limit_config.py
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Mixins for the CourseDiscoveryApiClient.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
|
||||
import httpretty
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Tests for course utils.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
from django.conf import settings
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
Tests for util.date_utils
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
from datetime import datetime, timedelta, tzinfo
|
||||
|
||||
@@ -130,7 +132,7 @@ class StrftimeLocalizedTest(unittest.TestCase):
|
||||
)
|
||||
def test_usual_strftime_behavior(self, fmt_expected):
|
||||
(fmt, expected) = fmt_expected
|
||||
dtime = datetime(2013, 02, 14, 16, 41, 17)
|
||||
dtime = datetime(2013, 2, 14, 16, 41, 17)
|
||||
self.assertEqual(expected, strftime_localized(dtime, fmt))
|
||||
# strftime doesn't like Unicode, so do the work in UTF8.
|
||||
self.assertEqual(expected, dtime.strftime(fmt.encode('utf8')).decode('utf8'))
|
||||
@@ -144,7 +146,7 @@ class StrftimeLocalizedTest(unittest.TestCase):
|
||||
)
|
||||
def test_shortcuts(self, fmt_expected):
|
||||
(fmt, expected) = fmt_expected
|
||||
dtime = datetime(2013, 02, 14, 16, 41, 17)
|
||||
dtime = datetime(2013, 2, 14, 16, 41, 17)
|
||||
self.assertEqual(expected, strftime_localized(dtime, fmt))
|
||||
|
||||
@patch('util.date_utils.pgettext', fake_pgettext(translations={
|
||||
@@ -163,7 +165,7 @@ class StrftimeLocalizedTest(unittest.TestCase):
|
||||
)
|
||||
def test_translated_words(self, fmt_expected):
|
||||
(fmt, expected) = fmt_expected
|
||||
dtime = datetime(2013, 02, 14, 16, 41, 17)
|
||||
dtime = datetime(2013, 2, 14, 16, 41, 17)
|
||||
self.assertEqual(expected, strftime_localized(dtime, fmt))
|
||||
|
||||
@patch('util.date_utils.ugettext', fake_ugettext(translations={
|
||||
@@ -183,7 +185,7 @@ class StrftimeLocalizedTest(unittest.TestCase):
|
||||
)
|
||||
def test_translated_formats(self, fmt_expected):
|
||||
(fmt, expected) = fmt_expected
|
||||
dtime = datetime(2013, 02, 14, 16, 41, 17)
|
||||
dtime = datetime(2013, 2, 14, 16, 41, 17)
|
||||
self.assertEqual(expected, strftime_localized(dtime, fmt))
|
||||
|
||||
@patch('util.date_utils.ugettext', fake_ugettext(translations={
|
||||
@@ -196,7 +198,7 @@ class StrftimeLocalizedTest(unittest.TestCase):
|
||||
)
|
||||
def test_recursion_protection(self, fmt_expected):
|
||||
(fmt, expected) = fmt_expected
|
||||
dtime = datetime(2013, 02, 14, 16, 41, 17)
|
||||
dtime = datetime(2013, 2, 14, 16, 41, 17)
|
||||
self.assertEqual(expected, strftime_localized(dtime, fmt))
|
||||
|
||||
@ddt.data(
|
||||
@@ -205,6 +207,6 @@ class StrftimeLocalizedTest(unittest.TestCase):
|
||||
"%Y/%m/%d%",
|
||||
)
|
||||
def test_invalid_format_strings(self, fmt):
|
||||
dtime = datetime(2013, 02, 14, 16, 41, 17)
|
||||
dtime = datetime(2013, 2, 14, 16, 41, 17)
|
||||
with self.assertRaises(ValueError):
|
||||
strftime_localized(dtime, fmt)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Tests for util.db module."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
@@ -12,6 +14,7 @@ from django.db.transaction import TransactionManagementError, atomic
|
||||
from django.test import TestCase, TransactionTestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.six import StringIO
|
||||
from six.moves import range
|
||||
|
||||
from util.db import commit_on_success, enable_named_outer_atomic, generate_int_id, outer_atomic
|
||||
|
||||
@@ -199,7 +202,7 @@ class GenerateIntIdTestCase(TestCase):
|
||||
minimum = 1
|
||||
maximum = times
|
||||
for __ in range(times):
|
||||
self.assertIn(generate_int_id(minimum, maximum), range(minimum, maximum + 1))
|
||||
self.assertIn(generate_int_id(minimum, maximum), list(range(minimum, maximum + 1)))
|
||||
|
||||
@ddt.data(10)
|
||||
def test_used_ids(self, times):
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
"""Tests for disabling rate limiting. """
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
@@ -6,6 +6,8 @@ cache values can't leak between different TestCase classes and methods. The need
|
||||
for this will go away whenever Django merges the fix to reset the caches between
|
||||
tests (https://code.djangoproject.com/ticket/11505).
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.core.cache import caches
|
||||
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, SharedModuleStoreTestCase
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
"""
|
||||
Tests for file.py
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
from io import StringIO
|
||||
@@ -11,10 +13,10 @@ from django.core import exceptions
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.http import HttpRequest
|
||||
from django.test import TestCase
|
||||
from pytz import UTC
|
||||
from mock import Mock, patch
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from opaque_keys.edx.locations import CourseLocator
|
||||
from pytz import UTC
|
||||
from six import text_type
|
||||
|
||||
import util.file
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Test for JsonResponse and JsonResponseBadRequest util classes.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
import unittest
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
Tests for keyword_substitution.py
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from ddt import ddt, file_data
|
||||
from mock import patch
|
||||
|
||||
@@ -114,13 +117,13 @@ class KeywordSubTest(ModuleStoreTestCase):
|
||||
test_string = 'This string should not be subbed here %%USER_ID%%'
|
||||
|
||||
no_course_context = dict(
|
||||
(key, value) for key, value in self.context.iteritems() if key != 'course_title'
|
||||
(key, value) for key, value in six.iteritems(self.context) if key != 'course_title'
|
||||
)
|
||||
result = Ks.substitute_keywords_with_data(test_string, no_course_context)
|
||||
self.assertEqual(test_string, result)
|
||||
|
||||
no_user_id_context = dict(
|
||||
(key, value) for key, value in self.context.iteritems() if key != 'user_id'
|
||||
(key, value) for key, value in six.iteritems(self.context) if key != 'user_id'
|
||||
)
|
||||
result = Ks.substitute_keywords_with_data(test_string, no_user_id_context)
|
||||
self.assertEqual(test_string, result)
|
||||
|
||||
@@ -2,8 +2,12 @@
|
||||
Tests for memcache in util app
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.core.cache import caches
|
||||
from django.test import TestCase
|
||||
from six import unichr
|
||||
from six.moves import range
|
||||
|
||||
from util.memcache import safe_key
|
||||
|
||||
@@ -14,7 +18,7 @@ class MemcacheTest(TestCase):
|
||||
"""
|
||||
|
||||
# Test whitespace, control characters, and some non-ASCII UTF-16
|
||||
UNICODE_CHAR_CODES = (range(30) + [127] +
|
||||
UNICODE_CHAR_CODES = (list(range(30)) + [127] +
|
||||
[129, 500, 2 ** 8 - 1, 2 ** 8 + 1, 2 ** 16 - 1])
|
||||
|
||||
def setUp(self):
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
Tests for the milestones helpers library, which is the integration point for the edx_milestones API
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import ddt
|
||||
import pytest
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from milestones import api as milestones_api
|
||||
@@ -78,16 +81,16 @@ class MilestonesHelpersTestCase(ModuleStoreTestCase):
|
||||
self.assertEqual(len(response), 0)
|
||||
|
||||
def test_add_course_milestone_returns_none_when_app_disabled(self):
|
||||
response = milestones_helpers.add_course_milestone(unicode(self.course.id), 'requires', self.milestone)
|
||||
response = milestones_helpers.add_course_milestone(six.text_type(self.course.id), 'requires', self.milestone)
|
||||
self.assertIsNone(response)
|
||||
|
||||
def test_get_course_milestones_returns_none_when_app_disabled(self):
|
||||
response = milestones_helpers.get_course_milestones(unicode(self.course.id))
|
||||
response = milestones_helpers.get_course_milestones(six.text_type(self.course.id))
|
||||
self.assertEqual(len(response), 0)
|
||||
|
||||
def test_add_course_content_milestone_returns_none_when_app_disabled(self):
|
||||
response = milestones_helpers.add_course_content_milestone(
|
||||
unicode(self.course.id),
|
||||
six.text_type(self.course.id),
|
||||
'i4x://any/content/id',
|
||||
'requires',
|
||||
self.milestone
|
||||
@@ -96,7 +99,7 @@ class MilestonesHelpersTestCase(ModuleStoreTestCase):
|
||||
|
||||
def test_get_course_content_milestones_returns_none_when_app_disabled(self):
|
||||
response = milestones_helpers.get_course_content_milestones(
|
||||
unicode(self.course.id),
|
||||
six.text_type(self.course.id),
|
||||
'i4x://doesnt/matter/for/this/test',
|
||||
'requires'
|
||||
)
|
||||
@@ -111,7 +114,7 @@ class MilestonesHelpersTestCase(ModuleStoreTestCase):
|
||||
self.assertIn('ENTRANCE_EXAM', response)
|
||||
|
||||
def test_get_course_milestones_fulfillment_paths_returns_none_when_app_disabled(self):
|
||||
response = milestones_helpers.get_course_milestones_fulfillment_paths(unicode(self.course.id), self.user)
|
||||
response = milestones_helpers.get_course_milestones_fulfillment_paths(six.text_type(self.course.id), self.user)
|
||||
self.assertIsNone(response)
|
||||
|
||||
def test_add_user_milestone_returns_none_when_app_disabled(self):
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
"""
|
||||
Tests for the organizations helpers library, which is the integration point for the edx-organizations API
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from mock import patch
|
||||
|
||||
from util import organizations_helpers
|
||||
@@ -42,7 +45,7 @@ class OrganizationsHelpersTestCase(ModuleStoreTestCase):
|
||||
self.assertEqual(len(response), 0)
|
||||
|
||||
def test_get_course_organizations_returns_none_when_app_disabled(self):
|
||||
response = organizations_helpers.get_course_organizations(unicode(self.course.id))
|
||||
response = organizations_helpers.get_course_organizations(six.text_type(self.course.id))
|
||||
self.assertEqual(len(response), 0)
|
||||
|
||||
def test_add_organization_returns_none_when_app_disabled(self):
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Tests for util.password_policy_validators module."""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
|
||||
from ddt import data, ddt, unpack
|
||||
@@ -9,7 +11,9 @@ from django.core.exceptions import ValidationError
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from util.password_policy_validators import (
|
||||
create_validator_config, validate_password, password_validators_instruction_texts,
|
||||
create_validator_config,
|
||||
password_validators_instruction_texts,
|
||||
validate_password
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Tests for sandboxing.py in util app
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Tests for string_utils.py
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from util.string_utils import str_to_bool
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Tests for the Zendesk"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
from smtplib import SMTPException
|
||||
|
||||
|
||||
Reference in New Issue
Block a user