'Creates a course, optionally with module_count discussion modules, and
a user with appropriate permissions.'

def set_up_course(self, module_count=0):

    self.course = CourseFactory.create(org='MITx', course='999', discussion_topics={'Some    Topic': {'id': 'some_topic'}}, display_name='Robot    Super    Course')
    self.course_id = self.course.id
    for i in range(module_count):
        ItemFactory.create(parent_location=self.course.location, category='discussion', discussion_id='id_module_{}'.format(i), discussion_category='Category    {}'.format(i), discussion_target='Discussion    {}'.format(i))
    call_command('seed_permissions_roles', unicode(self.course_id))
    with patch('student.models.cc.User.save'):
        uname = 'student'
        email = 'student@edx.org'
        self.password = 'test'
        self.student = User.objects.create_user(uname, email, self.password)
        self.student.is_active = True
        self.student.save()
        self.moderator = UserFactory.create(password=self.password)
        CourseEnrollmentFactory(user=self.student, course_id=self.course_id)
        CourseEnrollmentFactory(user=self.moderator, course_id=self.course.id)
        self.moderator.roles.add(Role.objects.get(name='Moderator', course_id=self.course.id))
        assert_true(self.client.login(username='student', password=self.password))
