From d81da9df4dacbc30f85935248b827aa90e4b1610 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Tue, 29 Jan 2013 14:44:37 -0500 Subject: [PATCH] Add tests for django comment client mustache helpers --- .../django_comment_client/mustache_helpers.py | 2 ++ .../tests/test_mustache_helpers.py | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py diff --git a/lms/djangoapps/django_comment_client/mustache_helpers.py b/lms/djangoapps/django_comment_client/mustache_helpers.py index 6f04ca527c..9756294696 100644 --- a/lms/djangoapps/django_comment_client/mustache_helpers.py +++ b/lms/djangoapps/django_comment_client/mustache_helpers.py @@ -5,6 +5,8 @@ import urllib import sys import inspect +# This method is used to pluralize the words "discussion" and "comment" +# which is why you need to tack on an "s" for the case of 0 or two or more. def pluralize(content, text): num, word = text.split(' ') num = int(num or '0') diff --git a/lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py b/lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py new file mode 100644 index 0000000000..8638aba67e --- /dev/null +++ b/lms/djangoapps/django_comment_client/tests/test_mustache_helpers.py @@ -0,0 +1,26 @@ +import string +import random +import collections + +from django.test import TestCase + +import django_comment_client.mustache_helpers as mustache_helpers + +class PluralizeTestCase(TestCase): + + def test_pluralize(self): + self.text1 = '0 goat' + self.text2 = '1 goat' + self.text3 = '7 goat' + self.content = 'unused argument' + self.assertEqual(mustache_helpers.pluralize(self.content, self.text1), 'goats') + self.assertEqual(mustache_helpers.pluralize(self.content, self.text2), 'goat') + self.assertEqual(mustache_helpers.pluralize(self.content, self.text3), 'goats') + +class CloseThreadTextTestCase(TestCase): + + def test_close_thread_text(self): + self.contentClosed = {'closed': True} + self.contentOpen = {'closed': False} + self.assertEqual(mustache_helpers.close_thread_text(self.contentClosed), 'Re-open thread') + self.assertEqual(mustache_helpers.close_thread_text(self.contentOpen), 'Close thread')