Commit 7f76517e by Calen Pennington

Cleanup courseware acceptance tests

parent c684a66a
......@@ -4,7 +4,9 @@
from __future__ import absolute_import
from lettuce import world, step
from lettuce.django import django_url
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from student.models import CourseEnrollment
from xmodule.modulestore import Location
from xmodule.modulestore.django import modulestore
......@@ -27,18 +29,24 @@ def create_course(_step, course):
# Create the course
# We always use the same org and display name,
# but vary the course identifier (e.g. 600x or 191x)
world.scenario_dict['COURSE'] = world.CourseFactory.create(org='edx',
number=course,
display_name='Test Course')
# Add a section to the course to contain problems
world.scenario_dict['SECTION'] = world.ItemFactory.create(parent_location=world.scenario_dict['COURSE'].location,
display_name='Test Section')
world.ItemFactory.create(
parent_location=world.scenario_dict['SECTION'].location,
world.scenario_dict['COURSE'] = world.CourseFactory.create(
org='edx',
number=course,
display_name='Test Course'
)
# Add a chapter to the course to contain problems
world.scenario_dict['CHAPTER'] = world.ItemFactory.create(
parent_location=world.scenario_dict['COURSE'].location,
category='chapter',
display_name='Test Chapter',
)
world.scenario_dict['SECTION'] = world.ItemFactory.create(
parent_location=world.scenario_dict['CHAPTER'].location,
category='sequential',
display_name='Test Section')
display_name='Test Section',
)
@step(u'I am registered for the course "([^"]*)"$')
......@@ -74,23 +82,32 @@ def go_into_course(step):
def course_id(course_num):
return "%s/%s/%s" % (world.scenario_dict['COURSE'].org, course_num,
world.scenario_dict['COURSE'].display_name.replace(" ", "_"))
world.scenario_dict['COURSE'].url_name)
def course_location(course_num):
return Location(loc_or_tag="i4x",
org=world.scenario_dict['COURSE'].org,
course=course_num,
category='course',
name=world.scenario_dict['COURSE'].display_name.replace(" ", "_"))
return world.scenario_dict['COURSE'].location._replace(course=course_num)
def section_location(course_num):
return Location(loc_or_tag="i4x",
org=world.scenario_dict['COURSE'].org,
course=course_num,
category='sequential',
name=world.scenario_dict['SECTION'].display_name.replace(" ", "_"))
return world.scenario_dict['SECTION'].location._replace(course=course_num)
def visit_scenario_item(item_key):
"""
Go to the courseware page containing the item stored in `world.scenario_dict`
under the key `item_key`
"""
url = django_url(reverse(
'jump_to',
kwargs={
'course_id': world.scenario_dict['COURSE'].id,
'location': str(world.scenario_dict[item_key].location),
}
))
world.browser.visit(url)
def get_courses():
......
......@@ -3,9 +3,10 @@
import os
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from lettuce import world, step
from lettuce.django import django_url
from common import course_id
from common import course_id, visit_scenario_item
from courseware.tests.factories import InstructorFactory
......@@ -111,7 +112,7 @@ def add_correct_lti_to_course(_step, fields):
metadata.update(_step.hashes[0])
world.scenario_dict['LTI'] = world.ItemFactory.create(
parent_location=world.scenario_dict['SEQUENTIAL'].location,
parent_location=world.scenario_dict['SECTION'].location,
category=category,
display_name='LTI',
metadata=metadata,
......@@ -122,19 +123,7 @@ def add_correct_lti_to_course(_step, fields):
port=world.browser.port,
))
course = world.scenario_dict["COURSE"]
chapter_name = world.scenario_dict['SECTION'].display_name.replace(
" ", "_")
section_name = chapter_name
path = "/courses/{org}/{num}/{name}/courseware/{chapter}/{section}".format(
org=course.org,
num=course.number,
name=course.display_name.replace(' ', '_'),
chapter=chapter_name,
section=section_name)
url = django_url(path)
world.browser.visit(url)
visit_scenario_item('LTI')
def create_course(course, metadata):
......@@ -180,12 +169,13 @@ def create_course(course, metadata):
)
# Add a section to the course to contain problems
world.scenario_dict['SECTION'] = world.ItemFactory.create(
world.scenario_dict['CHAPTER'] = world.ItemFactory.create(
parent_location=world.scenario_dict['COURSE'].location,
display_name='Test Section',
category='chapter',
display_name='Test Chapter',
)
world.scenario_dict['SEQUENTIAL'] = world.ItemFactory.create(
parent_location=world.scenario_dict['SECTION'].location,
world.scenario_dict['SECTION'] = world.ItemFactory.create(
parent_location=world.scenario_dict['CHAPTER'].location,
category='sequential',
display_name='Test Section',
metadata={'graded': True, 'format': 'Homework'})
......
......@@ -7,60 +7,35 @@ Steps for problem.feature lettuce tests
from lettuce import world, step
from lettuce.django import django_url
from common import i_am_registered_for_the_course
from common import i_am_registered_for_the_course, visit_scenario_item
from problems_setup import PROBLEM_DICT, answer_problem, problem_has_answer, add_problem_to_course
from nose.tools import assert_equal
@step(u'I am viewing a "([^"]*)" problem with "([^"]*)" attempt')
def view_problem_with_attempts(step, problem_type, attempts):
def _view_problem(step, problem_type, problem_settings=None):
i_am_registered_for_the_course(step, 'model_course')
# Ensure that the course has this problem type
add_problem_to_course(world.scenario_dict['COURSE'].number, problem_type, {'max_attempts': attempts})
add_problem_to_course(world.scenario_dict['COURSE'].number, problem_type, problem_settings)
# Go to the one section in the factory-created course
# which should be loaded with the correct problem
chapter_name = world.scenario_dict['SECTION'].display_name.replace(" ", "_")
section_name = chapter_name
url = django_url('/courses/%s/%s/%s/courseware/%s/%s' %
(world.scenario_dict['COURSE'].org, world.scenario_dict['COURSE'].number, world.scenario_dict['COURSE'].display_name.replace(' ', '_'),
chapter_name, section_name,))
world.browser.visit(url)
visit_scenario_item('SECTION')
@step(u'I am viewing a "([^"]*)" that shows the answer "([^"]*)"')
def view_problem_with_show_answer(step, problem_type, answer):
i_am_registered_for_the_course(step, 'model_course')
@step(u'I am viewing a "([^"]*)" problem with "([^"]*)" attempt')
def view_problem_with_attempts(step, problem_type, attempts):
_view_problem(step, problem_type, {'max_attempts': attempts})
# Ensure that the course has this problem type
add_problem_to_course('model_course', problem_type, {'showanswer': answer})
# Go to the one section in the factory-created course
# which should be loaded with the correct problem
chapter_name = world.scenario_dict['SECTION'].display_name.replace(" ", "_")
section_name = chapter_name
url = django_url('/courses/%s/%s/%s/courseware/%s/%s' %
(world.scenario_dict['COURSE'].org, world.scenario_dict['COURSE'].number, world.scenario_dict['COURSE'].display_name.replace(' ', '_'),
chapter_name, section_name,))
world.browser.visit(url)
@step(u'I am viewing a "([^"]*)" that shows the answer "([^"]*)"')
def view_problem_with_show_answer(step, problem_type, answer):
_view_problem(step, problem_type, {'showanswer': answer})
@step(u'I am viewing a "([^"]*)" problem')
def view_problem(step, problem_type):
i_am_registered_for_the_course(step, 'model_course')
# Ensure that the course has this problem type
add_problem_to_course('model_course', problem_type)
# Go to the one section in the factory-created course
# which should be loaded with the correct problem
chapter_name = world.scenario_dict['SECTION'].display_name.replace(" ", "_")
section_name = chapter_name
url = django_url('/courses/%s/%s/%s/courseware/%s/%s' %
(world.scenario_dict['COURSE'].org, world.scenario_dict['COURSE'].number, world.scenario_dict['COURSE'].display_name.replace(' ', '_'),
chapter_name, section_name,))
world.browser.visit(url)
_view_problem(step, problem_type)
@step(u'External graders respond "([^"]*)"')
......
......@@ -307,7 +307,7 @@ def problem_has_answer(problem_type, answer_class):
pass
def add_problem_to_course(course, problem_type, extraMeta=None):
def add_problem_to_course(course, problem_type, extra_meta=None):
'''
Add a problem to the course we have created using factories.
'''
......@@ -318,8 +318,8 @@ def add_problem_to_course(course, problem_type, extraMeta=None):
factory_dict = PROBLEM_DICT[problem_type]
problem_xml = factory_dict['factory'].build_xml(**factory_dict['kwargs'])
metadata = {'rerandomize': 'always'} if not 'metadata' in factory_dict else factory_dict['metadata']
if extraMeta:
metadata = dict(metadata, **extraMeta)
if extra_meta:
metadata = dict(metadata, **extra_meta)
# Create a problem item using our generated XML
# We set rerandomize=always in the metadata so that the "Reset" button
......
......@@ -7,8 +7,7 @@ from lettuce.django import django_url
@step('I register for the course "([^"]*)"$')
def i_register_for_the_course(_step, course):
cleaned_name = world.scenario_dict['COURSE'].display_name.replace(' ', '_')
url = django_url('courses/%s/%s/%s/about' % (world.scenario_dict['COURSE'].org, course, cleaned_name))
url = django_url('courses/%s/about' % world.scenario_dict['COURSE'].id)
world.browser.visit(url)
world.css_click('section.intro a.register')
......
......@@ -2,7 +2,7 @@
from lettuce import world, step
from lettuce.django import django_url
from common import i_am_registered_for_the_course, section_location
from common import i_am_registered_for_the_course, section_location, visit_scenario_item
from django.utils.translation import ugettext as _
############### ACTIONS ####################
......@@ -28,12 +28,7 @@ def view_video(_step, player_mode):
# Make sure we have a video
add_video_to_course(coursenum, player_mode.lower())
chapter_name = world.scenario_dict['SECTION'].display_name.replace(" ", "_")
section_name = chapter_name
url = django_url('/courses/%s/%s/%s/courseware/%s/%s' %
(world.scenario_dict['COURSE'].org, world.scenario_dict['COURSE'].number, world.scenario_dict['COURSE'].display_name.replace(' ', '_'),
chapter_name, section_name,))
world.browser.visit(url)
visit_scenario_item('SECTION')
def add_video_to_course(course, player_mode):
......
......@@ -4,7 +4,7 @@ from time import sleep
from lettuce import world, step
from lettuce.django import django_url
from common import i_am_registered_for_the_course, section_location
from common import i_am_registered_for_the_course, section_location, visit_scenario_item
@step('I view the word cloud and it has rendered')
......@@ -18,16 +18,7 @@ def view_word_cloud(_step):
i_am_registered_for_the_course(_step, coursenum)
add_word_cloud_to_course(coursenum)
chapter_name = world.scenario_dict['SECTION'].display_name.replace(
" ", "_")
section_name = chapter_name
url = django_url('/courses/%s/%s/%s/courseware/%s/%s' % (
world.scenario_dict['COURSE'].org,
world.scenario_dict['COURSE'].number,
world.scenario_dict['COURSE'].display_name.replace(' ', '_'),
chapter_name, section_name,)
)
world.browser.visit(url)
visit_scenario_item('SECTION')
@step('I press the Save button')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment