From f1f65c563ef06064e41853f3197d42cb8dc41f12 Mon Sep 17 00:00:00 2001 From: Arthur Barrett Date: Thu, 9 May 2013 11:51:24 -0400 Subject: [PATCH] fix failing unit test in lms.envs.test env --- lms/djangoapps/notes/api.py | 16 ++++++++++++++-- lms/djangoapps/notes/tests.py | 7 +++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/notes/api.py b/lms/djangoapps/notes/api.py index 9849c35d33..ea334faf10 100644 --- a/lms/djangoapps/notes/api.py +++ b/lms/djangoapps/notes/api.py @@ -28,6 +28,13 @@ API_SETTINGS = { #----------------------------------------------------------------------# # API requests are routed through api_request() using the resource map. +def api_enabled(request, course_id): + ''' + Returns True if the api is enabled for the course, otherwise False. + ''' + course = _get_course(request, course_id) + return notes_enabled_for_course(course) + @login_required def api_request(request, course_id, **kwargs): ''' @@ -37,8 +44,7 @@ def api_request(request, course_id, **kwargs): ''' # Verify that notes are enabled for the course - course = get_course_with_access(request.user, course_id, 'load') - if not notes_enabled_for_course(course): + if not api_enabled(request, course_id): log.debug('Notes not enabled for course') raise Http404 @@ -91,6 +97,12 @@ def api_format(request, response, data): content = json.dumps(data) return [content_type, content] +def _get_course(request, course_id): + ''' + Helper function to load and return a user's course. + ''' + return get_course_with_access(request.user, course_id, 'load') + #----------------------------------------------------------------------# # API actions exposed via the resource map. diff --git a/lms/djangoapps/notes/tests.py b/lms/djangoapps/notes/tests.py index 9861863561..c48202dcc2 100644 --- a/lms/djangoapps/notes/tests.py +++ b/lms/djangoapps/notes/tests.py @@ -14,8 +14,6 @@ import logging from . import utils, api, models -logging.disable(logging.CRITICAL) # remove debugging from the log output - class UtilsTest(TestCase): def setUp(self): ''' @@ -41,12 +39,17 @@ class UtilsTest(TestCase): {'type': 'foo'}, {'name': 'My Notes', 'type': 'notes'}, {'type':'bar'}] + self.assertTrue(utils.notes_enabled_for_course(self.course)) class ApiTest(TestCase): + def setUp(self): self.client = Client() + # Mocks + api.api_enabled = (lambda request, course_id: True) + # Create two accounts self.password = 'abc' self.student = User.objects.create_user('student', 'student@test.com', self.password)