Skip to content

Commit

Permalink
Merge pull request openedx#321
Browse files Browse the repository at this point in the history
* origin/aliang8/quality:
  Fix 171 PEP8 errors
  • Loading branch information
stvstnfrd committed Jul 2, 2015
2 parents aa4c982 + fde17b5 commit 0b8a4f3
Show file tree
Hide file tree
Showing 45 changed files with 314 additions and 207 deletions.
3 changes: 2 additions & 1 deletion cms/djangoapps/contentstore/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def setUp(self):
self.course_key = self.store.make_course_key('myu', 'mydept.mycourse', 'myrun')
course_url = reverse_url('course_handler')
with mock.patch.dict('django.conf.settings.FEATURES', {"DEFAULT_STORE_FOR_NEW_COURSE": None}):
self.client.ajax_post(course_url,
self.client.ajax_post(
course_url,
{
'org': self.course_key.org,
'number': self.course_key.course,
Expand Down
54 changes: 26 additions & 28 deletions cms/djangoapps/contentstore/views/tests/test_bulksettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from datetime import datetime
import random


@unittest.skip("Bulk Settings are currently disabled")
class BulkSettingsTests(CourseTestCase):
"""
Expand Down Expand Up @@ -38,7 +39,6 @@ def setUp(self):
"""
super(BulkSettingsTests, self).setUp()


def populate_course_with_seed_data(self):
"""
Populates the given course hierarchy with initial settings data
Expand All @@ -47,16 +47,14 @@ def populate_course_with_seed_data(self):

self.do_recursive_population(self.course, ['chapter', 'sequential', 'vertical', 'problem'])


def do_recursive_population(self,parent, stack):
def do_recursive_population(self, parent, stack):
block_category = stack.pop(0)
for _ in range(2):
child = self.create_item_of_category(block_category, parent)
stack_copy = list(stack)
if stack_copy:
self.do_recursive_population(child, stack_copy)


def create_item_of_category(self, category, parent):
"""
Given a category and the parent, creates a block (item)
Expand All @@ -69,13 +67,12 @@ def create_item_of_category(self, category, parent):
metadata[setting_type] = self.generate_random_value_for(setting_type)

item = ItemFactory.create(
parent_location = parent.location,
category = category,
metadata = metadata
parent_location=parent.location,
category=category,
metadata=metadata,
)
return item


def generate_random_value_for(self, setting_type):
"""
Given a setting type, (metadata attribute of a mixin class)
Expand All @@ -84,7 +81,7 @@ def generate_random_value_for(self, setting_type):

randomization_values = ["Always", "On Reset", "Never", "Per Student"]
show_answer_values = ["Always", "Answered", "Attempted", "Closed",
"Finished", "Past Due", "Never"]
"Finished", "Past Due", "Never"]
format_values = ["Quiz", "Homework"]

if setting_type == "start" or setting_type == "due":
Expand All @@ -101,37 +98,37 @@ def generate_random_value_for(self, setting_type):
elif setting_type == "showanswer":
return show_answer_values[random.randint(0, 6)]
else:
return format_values[random.randint(0,1)]

return format_values[random.randint(0, 1)]

def test_empty_course(self):
"""
Test that the computed settings data is empty when the course is empty.
"""
empty_course = CourseFactory.create(
org = 'edx',
number = '999',
display_name = 'test_course'
org='edx',
number='999',
display_name='test_course',
)

computed_settings_data = BulkSettingsUtil.get_bulksettings_metadata(empty_course)
self.assertEqual(len(computed_settings_data), 0, msg="empty course should contain no settings")


def test_empty_problem(self):
"""
Test with no problems. If no unit holds any problems, the list should be empty.
"""
empty_problem_course = CourseFactory.create(
org = 'edx',
number = '999',
display_name = 'no_problem_course'
org='edx',
number='999',
display_name='no_problem_course',
)
self.do_recursive_population(empty_problem_course, ['chapter', 'sequential', 'vertical'])
computed_settings_data = BulkSettingsUtil.get_bulksettings_metadata(empty_problem_course)
self.assertEqual(len(computed_settings_data), 0,
msg="course with no problem should yield no bulksettings")

self.assertEqual(
len(computed_settings_data),
0,
msg='course with no problem should yield no bulksettings',
)

def test_multiple_bulksettings(self):
"""
Expand All @@ -148,7 +145,6 @@ def test_multiple_bulksettings(self):
for i in range(self.NUM_RANDOM_TESTS):
self.test_bulksettings_data_correctness()


def test_bulksettings_data_correctness(self):
"""
Test that the populated course settings correctly match the result
Expand Down Expand Up @@ -203,27 +199,30 @@ def test_bulksettings_data_correctness(self):
self.assertTrue(self.do_values_match(self.PROBLEM_SETTING_TYPES,
component, computed_component_settings))


def do_values_match(self, setting_types, child, computed_settings):
"""
Checks if the actual settings of the given child matches
the computed settings
"""

for setting_type in setting_types:
setting= getattr(child, setting_type)
setting = getattr(child, setting_type)

if setting_type == 'start' or setting_type == 'due':
setting = setting.strftime('%m/%d/%Y')

self.assertEqual(setting, computed_settings[setting_type],
msg="setting_type" + str(setting_type) + "does not match")
self.assertEqual(
setting,
computed_settings[setting_type],
msg="setting_type {setting_type} does not match".format(
setting_type=setting_type,
),
)
if setting != computed_settings[setting_type]:
return False

return True


def populate_settings(self):

"""
Expand Down Expand Up @@ -252,4 +251,3 @@ def populate_settings(self):
setattr(component, setting_type, self.generate_random_value_for(setting_type))
component.save()
self.save_course()

1 change: 1 addition & 0 deletions cms/djangoapps/contentstore/views/transcripts_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def get_transcripts_presence(videos, item):
})
return transcripts_presence


def _transcripts_logic(transcripts_presence, videos):
"""
By `transcripts_presence` content, figure what show to user:
Expand Down
7 changes: 4 additions & 3 deletions cms/djangoapps/contentstore/views/utilities/bulksettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ def utility_bulksettings_handler(request, course_key_string):

# traverse into the course tree and extract problem settings information
settings_data = BulkSettingsUtil.get_bulksettings_metadata(course)
return render_to_response('bulksettings.html',
return render_to_response(
'bulksettings.html',
{
'context_course':course,
'settings_data':settings_data,
'context_course': course,
'settings_data': settings_data,
'setting_type_list_map': SETTING_TYPE_LIST_MAP,
'section_setting_map': SECTION_SETTING_MAP,
'subsection_setting_map': SUBSECTION_SETTING_MAP
Expand Down
10 changes: 6 additions & 4 deletions cms/djangoapps/contentstore/views/utilities/captions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.keys import UsageKey
from xmodule.video_module.transcripts_utils import (
GetTranscriptsFromYouTubeException,
TranscriptsRequestValidationException,
download_youtube_subs)
GetTranscriptsFromYouTubeException,
TranscriptsRequestValidationException,
download_youtube_subs,
)
from xmodule.video_module import manage_video_subtitles_save

from ..transcripts_ajax import get_transcripts_presence
Expand Down Expand Up @@ -125,7 +126,8 @@ def captions_index(request, course_key):
depth=2,
)

return render_to_response('captions.html',
return render_to_response(
'captions.html',
{
'videos': get_videos(course),
'context_course': course,
Expand Down
6 changes: 3 additions & 3 deletions cms/djangoapps/models/settings/course_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CourseDetails(object):
def __init__(self, org, course_id, run):
# still need these for now b/c the client's screen shows these 3 fields
self.org = org
self.course_id = course_id # This actually holds the course number.
self.course_id = course_id # This actually holds the course number.
self.run = run
self.start_date = None # 'start'
self.end_date = None # 'end'
Expand All @@ -46,7 +46,7 @@ def __init__(self, org, course_id, run):
self.syllabus = None # a pdf file asset
self.short_description = ""
self.overview = "" # html to render as the overview
self.about_sidebar_html = "" # html to render as the about_sidebar_html
self.about_sidebar_html = ''
self.pre_enrollment_email = render_to_string('emails/default_pre_enrollment_message.txt', {})
self.post_enrollment_email = render_to_string('emails/default_post_enrollment_message.txt', {})
self.pre_enrollment_email_subject = "Thanks for Enrolling in {}".format(self.course_id)
Expand Down Expand Up @@ -145,7 +145,7 @@ def update_from_json(cls, course_key, jsondict, user):
# Added to allow admins to enable/disable enrollment emails
if 'enable_enrollment_email' in jsondict:
descriptor.enable_enrollment_email = jsondict['enable_enrollment_email']
dirty=True
dirty = True

if 'start_date' in jsondict:
converted = date.from_json(jsondict['start_date'])
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/sneakpeek/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth import logout
from django.shortcuts import redirect


class SneakPeekLogoutMiddleware(object):
"""
Middleware that logs out all sneakpeek users and then retries (redirects) the same URL
Expand All @@ -23,4 +24,3 @@ def process_request(self, request):

logout(request)
return redirect(request.get_full_path())

32 changes: 19 additions & 13 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,19 +676,25 @@

# Todo: add aws entries for this
COURSE_UTILITIES = [
{"short_description": "Bulk Operations",
"items": [
{"short_description": "Get all captions from YouTube",
"long_description": "This utility will attempt to get or update captions for all videos in the course from YouTube. Please allow it a couple of minutes to run.",
"action_url": "utility_captions_handler",
"action_text": "Check Captions",
"action_external": False},
# {"short_description": "Bulk view problem settings",
# "long_description": "This utility will allow you to view all section, subsection and problem settings in one page.",
# "action_url": "utility_bulksettings_handler",
# "action_text": "View Problem Settings",
# "action_external" : False}
]
{
'short_description': 'Bulk Operations',
'items': [
{
'short_description': 'Get all captions from YouTube',
'long_description': (
'This utility will attempt to get or update captions for all videos '
'in the course from YouTube. Please allow it a couple of minutes to run.'
),
'action_url': 'utility_captions_handler',
'action_text': 'Check Captions',
'action_external': False,
},
#{'short_description': 'Bulk view problem settings',
# 'long_description': 'This utility will allow you to view all section, subsection and problem settings in one page.',
# 'action_url': 'utility_bulksettings_handler',
# 'action_text': 'View Problem Settings',
# 'action_external': False,},
],
}
]
############################# VIDEO UPLOAD PIPELINE #############################
Expand Down
2 changes: 1 addition & 1 deletion cms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# Remove sneakpeek during tests to prevent unwanted redirect
MIDDLEWARE_CLASSES = tuple([
mwc for mwc in MIDDLEWARE_CLASSES
if mwc != 'sneakpeek.middleware.SneakPeekLogoutMiddleware'
if mwc != 'sneakpeek.middleware.SneakPeekLogoutMiddleware'
])

THIS_UUID = uuid4().hex[:5]
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/external_auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ def shib_login(request):
def _safe_postlogin_redirect(redirect_to, localhost, default_redirect='/'):
"""
If redirect_to param is safe (not off this host), then perform the redirect.
If a redirect whitelist is defined, check that redirect_to is safe to a host
If a redirect whitelist is defined, check that redirect_to is safe to a host
in that list or localhost (you don't need to include the host itself in the whitelist).
Otherwise just redirect to '/'.
@param redirect_to: user-supplied redirect url
Expand Down
Loading

0 comments on commit 0b8a4f3

Please sign in to comment.