From 7e636114786a98a3648a29cdafe7163eb812bc3c Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Thu, 9 May 2013 17:19:10 -0400 Subject: [PATCH] Start adding view tests for discussion client. Note that these will not work unless you change your test.py to enable discussion forums. --- .../django_comment_client/base/tests.py | 50 +++++++++++++++++++ .../django_comment_client/tests/factories.py | 13 +++++ .../django_comment_client/tests/test_utils.py | 14 +----- 3 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 lms/djangoapps/django_comment_client/base/tests.py create mode 100644 lms/djangoapps/django_comment_client/tests/factories.py diff --git a/lms/djangoapps/django_comment_client/base/tests.py b/lms/djangoapps/django_comment_client/base/tests.py new file mode 100644 index 0000000000..70f830bff0 --- /dev/null +++ b/lms/djangoapps/django_comment_client/base/tests.py @@ -0,0 +1,50 @@ +import logging + +from django.test.utils import override_settings +from django.test.client import Client +from student.tests.factories import UserFactory, CourseEnrollmentFactory +from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from django.core.urlresolvers import reverse + +from django.core.management import call_command + +from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE +from nose.tools import assert_true, assert_equal + +log = logging.getLogger(__name__) + + +@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) +class ViewsTestCase(ModuleStoreTestCase): + def setUp(self): + # create a course + self.course = CourseFactory.create(org='MITx', course='999', + display_name='Robot Super Course') + self.course_id = self.course.id + + # seed the forums permissions and roles + call_command('seed_permissions_roles', self.course_id) + + self.student = UserFactory(username='student', password='test', + email='student@edx.org') + self.enrollment = CourseEnrollmentFactory(user=self.student, + course_id=self.course_id) + + self.client = Client() + assert_true(self.client.login(username='student', password='test')) + + def test_create_thread(self): + thread = {"body": ["this is a post"], + "anonymous_to_peers": ["false"], + "auto_subscribe": ["true"], + "anonymous": ["false"], + "title": ["Hello"] + } + url = reverse('create_thread', + kwargs={'commentable_id': 'i4x-MITx-999-course-Robot_Super_Course', + 'course_id': self.course_id}) + # url = '/courses/MITx/999/Robot_Super_Course/discussion/i4x-MITx-999-course-Robot_Super_Course/threads/create' + # url = 'MITx/999/Robot_Super_Course/threads/create' + response = self.client.post(url, data=thread) + assert_equal(response.status_code, 200) diff --git a/lms/djangoapps/django_comment_client/tests/factories.py b/lms/djangoapps/django_comment_client/tests/factories.py new file mode 100644 index 0000000000..eb1d9477c3 --- /dev/null +++ b/lms/djangoapps/django_comment_client/tests/factories.py @@ -0,0 +1,13 @@ +from factory import DjangoModelFactory +from django_comment_client.models import Role, Permission + + +class RoleFactory(DjangoModelFactory): + FACTORY_FOR = Role + name = 'Student' + course_id = 'edX/toy/2012_Fall' + + +class PermissionFactory(DjangoModelFactory): + FACTORY_FOR = Permission + name = 'create_comment' diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py index 80b8419d5a..a7c0ce0a39 100644 --- a/lms/djangoapps/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/django_comment_client/tests/test_utils.py @@ -1,22 +1,10 @@ from django.test import TestCase -from factory import DjangoModelFactory from student.tests.factories import UserFactory, CourseEnrollmentFactory -from django_comment_client.models import Role, Permission +from factories import RoleFactory import django_comment_client.utils as utils -class RoleFactory(DjangoModelFactory): - FACTORY_FOR = Role - name = 'Student' - course_id = 'edX/toy/2012_Fall' - - -class PermissionFactory(DjangoModelFactory): - FACTORY_FOR = Permission - name = 'create_comment' - - class DictionaryTestCase(TestCase): def test_extract(self): d = {'cats': 'meow', 'dogs': 'woof'}