Test generation of chat settings
Ensure that the chat connection settings are generated properly for the template context.
This commit is contained in:
committed by
Joe Blaylock
parent
c53a550f3b
commit
f4ae0e0cae
@@ -124,3 +124,26 @@ class ViewsTestCase(TestCase):
|
||||
self.assertContains(result, expected_end_text)
|
||||
else:
|
||||
self.assertNotContains(result, "Classes End")
|
||||
|
||||
def test_chat_settings(self):
|
||||
mock_user = MagicMock()
|
||||
mock_user.username = "johndoe"
|
||||
|
||||
mock_course = MagicMock()
|
||||
mock_course.id = "a/b/c"
|
||||
|
||||
# Stub this out in the case that it's not in the settings
|
||||
domain = "jabber.edx.org"
|
||||
settings.JABBER_DOMAIN = domain
|
||||
|
||||
chat_settings = views.chat_settings(mock_course, mock_user)
|
||||
|
||||
# Test the proper format of all chat settings
|
||||
self.assertEquals(chat_settings['domain'], domain)
|
||||
self.assertEquals(chat_settings['room'], "a-b-c_class")
|
||||
self.assertEquals(chat_settings['username'], "johndoe@%s" % domain)
|
||||
|
||||
# TODO: this needs to be changed once we figure out how to
|
||||
# generate/store a real password.
|
||||
self.assertEquals(chat_settings['password'], "johndoe@%s" % domain)
|
||||
|
||||
|
||||
@@ -235,6 +235,30 @@ def update_timelimit_module(user, course_id, model_data_cache, timelimit_descrip
|
||||
return context
|
||||
|
||||
|
||||
def chat_settings(course, user):
|
||||
"""
|
||||
Returns a dict containing the settings required to connect to a
|
||||
Jabber chat server and room.
|
||||
"""
|
||||
return {
|
||||
'domain': settings.JABBER_DOMAIN,
|
||||
|
||||
# Jabber doesn't like slashes, so replace with dashes
|
||||
'room': "{ID}_class".format(ID=course.id.replace('/', '-')),
|
||||
|
||||
'username': "{USER}@{DOMAIN}".format(
|
||||
USER=user.username, DOMAIN=settings.JABBER_DOMAIN
|
||||
),
|
||||
|
||||
# TODO: clearly this needs to be something other than the username
|
||||
# should also be something that's not necessarily tied to a
|
||||
# particular course
|
||||
'password': "{USER}@{DOMAIN}".format(
|
||||
USER=user.username, DOMAIN=settings.JABBER_DOMAIN
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@login_required
|
||||
@ensure_csrf_cookie
|
||||
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
|
||||
@@ -300,13 +324,7 @@ def index(request, course_id, chapter=None, section=None,
|
||||
}
|
||||
|
||||
if course.show_chat:
|
||||
context['chat'] = {
|
||||
'domain': settings.JABBER_DOMAIN,
|
||||
'room': "{ID}_class".format(ID=course.id.replace('/', '-')), # Jabber doesn't like /s
|
||||
'username': "{USER}@{DOMAIN}".format(USER=user.username, DOMAIN=settings.JABBER_DOMAIN),
|
||||
# TODO: clearly this needs to be something other than the username
|
||||
'password': "{USER}@{DOMAIN}".format(USER=user.username, DOMAIN=settings.JABBER_DOMAIN),
|
||||
}
|
||||
context['chat'] = chat_settings(course, user)
|
||||
|
||||
chapter_descriptor = course.get_child_by(lambda m: m.url_name == chapter)
|
||||
if chapter_descriptor is not None:
|
||||
|
||||
Reference in New Issue
Block a user