Commit bcf83553 by Victor Shnayder

Pass course_id instead of course to get_site_status_msg

* makes testing easier -- don't need course objects
parent ddcd166b
...@@ -10,7 +10,7 @@ import sys ...@@ -10,7 +10,7 @@ import sys
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def get_site_status_msg(course): def get_site_status_msg(course_id):
""" """
Look for a file settings.STATUS_MESSAGE_PATH. If found, read it, Look for a file settings.STATUS_MESSAGE_PATH. If found, read it,
parse as json, and do the following: parse as json, and do the following:
...@@ -33,9 +33,9 @@ def get_site_status_msg(course): ...@@ -33,9 +33,9 @@ def get_site_status_msg(course):
status_dict = json.loads(content) status_dict = json.loads(content)
msg = status_dict.get('global', None) msg = status_dict.get('global', None)
if course and course.id in status_dict: if course_id in status_dict:
msg = msg + "<br>" if msg else '' msg = msg + "<br>" if msg else ''
msg += status_dict[course.id] msg += status_dict[course_id]
return msg return msg
except: except:
......
from django.conf import settings from django.conf import settings
from django.test import TestCase from django.test import TestCase
from mock import Mock
import os import os
from override_settings import override_settings from override_settings import override_settings
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
...@@ -53,13 +52,11 @@ class TestStatus(TestCase): ...@@ -53,13 +52,11 @@ class TestStatus(TestCase):
def setUp(self): def setUp(self):
""" """
Mock courses, since we don't have to have full django Fake course ids, since we don't have to have full django
settings (common tests run without the lms settings imported) settings (common tests run without the lms settings imported)
""" """
self.full = Mock() self.full_id = 'edX/full/2012_Fall'
self.full.id = 'edX/full/2012_Fall' self.toy_id = 'edX/toy/2012_Fall'
self.toy = Mock()
self.toy.id = 'edX/toy/2012_Fall'
def create_status_file(self, contents): def create_status_file(self, contents):
""" """
...@@ -88,6 +85,6 @@ class TestStatus(TestCase): ...@@ -88,6 +85,6 @@ class TestStatus(TestCase):
print "course=None:" print "course=None:"
self.assertEqual(get_site_status_msg(None), exp_none) self.assertEqual(get_site_status_msg(None), exp_none)
print "course=toy:" print "course=toy:"
self.assertEqual(get_site_status_msg(self.toy), exp_toy) self.assertEqual(get_site_status_msg(self.toy_id), exp_toy)
print "course=full:" print "course=full:"
self.assertEqual(get_site_status_msg(self.full), exp_full) self.assertEqual(get_site_status_msg(self.full_id), exp_full)
...@@ -15,11 +15,11 @@ from status.status import get_site_status_msg ...@@ -15,11 +15,11 @@ from status.status import get_site_status_msg
<%block cached="False"> <%block cached="False">
<% <%
try: try:
c = course course_id = course.id
except: except:
# can't figure out a better way to get at a possibly-defined course var # can't figure out a better way to get at a possibly-defined course var
c = None course_id = None
site_status_msg = get_site_status_msg(c) site_status_msg = get_site_status_msg(course_id)
%> %>
% if site_status_msg: % if site_status_msg:
<div class="site-status"> <div class="site-status">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment