Start adding view tests for discussion client. Note that these will not work unless you change your test.py to enable discussion forums.

This commit is contained in:
Jay Zoldak
2013-05-09 17:19:10 -04:00
parent 90892450b7
commit 7e63611478
3 changed files with 64 additions and 13 deletions

View File

@@ -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)

View File

@@ -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'

View File

@@ -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'}