From 3576a3154b6386f95f8a48182791e1084d093756 Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Tue, 19 Mar 2013 16:38:51 -0400 Subject: [PATCH] Repoint factory references in lettuce tests to world. --- .../features/studio-overview-togglesection.py | 21 +++++++++---------- common/djangoapps/student/tests/factories.py | 11 ++++++++-- common/djangoapps/terrain/factories.py | 10 ++++++++- lms/djangoapps/courseware/features/common.py | 9 ++++---- .../courseware/features/problems.py | 3 +-- .../django_comment_client/tests/test_utils.py | 16 +------------- 6 files changed, 34 insertions(+), 36 deletions(-) diff --git a/cms/djangoapps/contentstore/features/studio-overview-togglesection.py b/cms/djangoapps/contentstore/features/studio-overview-togglesection.py index 00aa39455d..060d592cfd 100644 --- a/cms/djangoapps/contentstore/features/studio-overview-togglesection.py +++ b/cms/djangoapps/contentstore/features/studio-overview-togglesection.py @@ -1,5 +1,4 @@ from lettuce import world, step -from terrain.factories import * from common import * from nose.tools import assert_true, assert_false, assert_equal @@ -10,15 +9,15 @@ logger = getLogger(__name__) @step(u'I have a course with no sections$') def have_a_course(step): clear_courses() - course = CourseFactory.create() + course = world.CourseFactory.create() @step(u'I have a course with 1 section$') def have_a_course_with_1_section(step): clear_courses() - course = CourseFactory.create() - section = ItemFactory.create(parent_location=course.location) - subsection1 = ItemFactory.create( + course = world.CourseFactory.create() + section = world.ItemFactory.create(parent_location=course.location) + subsection1 = world.ItemFactory.create( parent_location=section.location, template='i4x://edx/templates/sequential/Empty', display_name='Subsection One',) @@ -27,20 +26,20 @@ def have_a_course_with_1_section(step): @step(u'I have a course with multiple sections$') def have_a_course_with_two_sections(step): clear_courses() - course = CourseFactory.create() - section = ItemFactory.create(parent_location=course.location) - subsection1 = ItemFactory.create( + course = world.CourseFactory.create() + section = world.ItemFactory.create(parent_location=course.location) + subsection1 = world.ItemFactory.create( parent_location=section.location, template='i4x://edx/templates/sequential/Empty', display_name='Subsection One',) - section2 = ItemFactory.create( + section2 = world.ItemFactory.create( parent_location=course.location, display_name='Section Two',) - subsection2 = ItemFactory.create( + subsection2 = world.ItemFactory.create( parent_location=section2.location, template='i4x://edx/templates/sequential/Empty', display_name='Subsection Alpha',) - subsection3 = ItemFactory.create( + subsection3 = world.ItemFactory.create( parent_location=section2.location, template='i4x://edx/templates/sequential/Empty', display_name='Subsection Beta',) diff --git a/common/djangoapps/student/tests/factories.py b/common/djangoapps/student/tests/factories.py index 8dd70a7a61..2acc235ce2 100644 --- a/common/djangoapps/student/tests/factories.py +++ b/common/djangoapps/student/tests/factories.py @@ -1,8 +1,8 @@ from student.models import (User, UserProfile, Registration, - CourseEnrollmentAllowed) + CourseEnrollmentAllowed, CourseEnrollment) from django.contrib.auth.models import Group from datetime import datetime -from factory import Factory +from factory import Factory, SubFactory from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore from time import gmtime @@ -50,6 +50,13 @@ class UserFactory(Factory): date_joined = datetime(2011, 1, 1) +class CourseEnrollmentFactory(Factory): + FACTORY_FOR = CourseEnrollment + + user = SubFactory(UserFactory) + course_id = 'edX/toy/2012_Fall' + + class CourseEnrollmentAllowedFactory(Factory): FACTORY_FOR = CourseEnrollmentAllowed diff --git a/common/djangoapps/terrain/factories.py b/common/djangoapps/terrain/factories.py index 62b133217d..3a3381c74c 100644 --- a/common/djangoapps/terrain/factories.py +++ b/common/djangoapps/terrain/factories.py @@ -1,6 +1,6 @@ from student.tests.factories import (UserFactory, UserProfileFactory, RegistrationFactory, GroupFactory, - CourseEnrollmentAllowed, + CourseEnrollmentAllowed, CourseEnrollment, CourseFactory, ItemFactory) from lettuce import world @@ -37,6 +37,14 @@ class GroupFactory(GroupFactory): pass +@world.absorb +class CourseEnrollment(CourseEnrollment): + """ + Courses that the user is enrolled in + """ + pass + + @world.absorb class CourseEnrollmentAllowed(CourseEnrollmentAllowed): """ diff --git a/lms/djangoapps/courseware/features/common.py b/lms/djangoapps/courseware/features/common.py index 8fb2843656..bdbd952caa 100644 --- a/lms/djangoapps/courseware/features/common.py +++ b/lms/djangoapps/courseware/features/common.py @@ -5,7 +5,6 @@ from lettuce.django import django_url from django.conf import settings from django.contrib.auth.models import User from student.models import CourseEnrollment -from terrain.factories import CourseFactory, ItemFactory from xmodule.modulestore import Location from xmodule.modulestore.django import _MODULESTORES, modulestore from xmodule.templates import update_templates @@ -101,15 +100,15 @@ 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) - course = CourseFactory.create(org=TEST_COURSE_ORG, + course = world.CourseFactory.create(org=TEST_COURSE_ORG, number=course, display_name=TEST_COURSE_NAME) # Add a section to the course to contain problems - section = ItemFactory.create(parent_location=course.location, + section = world.ItemFactory.create(parent_location=course.location, display_name=TEST_SECTION_NAME) - problem_section = ItemFactory.create(parent_location=section.location, + problem_section = world.ItemFactory.create(parent_location=section.location, template='i4x://edx/templates/sequential/Empty', display_name=TEST_SECTION_NAME) @@ -131,7 +130,7 @@ def i_am_registered_for_the_course(step, course): @step(u'The course "([^"]*)" has extra tab "([^"]*)"$') def add_tab_to_course(step, course, extra_tab_name): - section_item = ItemFactory.create(parent_location=course_location(course), + section_item = world.ItemFactory.create(parent_location=course_location(course), template="i4x://edx/templates/static_tab/Empty", display_name=str(extra_tab_name)) diff --git a/lms/djangoapps/courseware/features/problems.py b/lms/djangoapps/courseware/features/problems.py index a6575c3d22..a2d37ff7d8 100644 --- a/lms/djangoapps/courseware/features/problems.py +++ b/lms/djangoapps/courseware/features/problems.py @@ -4,7 +4,6 @@ from selenium.webdriver.support.ui import Select import random import textwrap from common import i_am_registered_for_the_course, TEST_SECTION_NAME, section_location -from terrain.factories import ItemFactory from capa.tests.response_xml_factory import OptionResponseXMLFactory, \ ChoiceResponseXMLFactory, MultipleChoiceResponseXMLFactory, \ StringResponseXMLFactory, NumericalResponseXMLFactory, \ @@ -92,7 +91,7 @@ def add_problem_to_course(course, problem_type): # Create a problem item using our generated XML # We set rerandomize=always in the metadata so that the "Reset" button # will appear. - problem_item = ItemFactory.create(parent_location=section_location(course), + problem_item = world.ItemFactory.create(parent_location=section_location(course), template="i4x://edx/templates/problem/Blank_Common_Problem", display_name=str(problem_type), data=problem_xml, diff --git a/lms/djangoapps/django_comment_client/tests/test_utils.py b/lms/djangoapps/django_comment_client/tests/test_utils.py index cec006e630..fe580f1ebe 100644 --- a/lms/djangoapps/django_comment_client/tests/test_utils.py +++ b/lms/djangoapps/django_comment_client/tests/test_utils.py @@ -8,6 +8,7 @@ import factory from django.contrib.auth.models import User from student.models import UserProfile, CourseEnrollment from django_comment_client.models import Role, Permission +from student.tests.factories import UserFactory, CourseEnrollmentFactory import django_comment_client.models as models import django_comment_client.utils as utils @@ -15,21 +16,6 @@ import django_comment_client.utils as utils import xmodule.modulestore.django as django -class UserFactory(factory.Factory): - FACTORY_FOR = User - username = 'robot' - password = '123456' - email = 'robot@edx.org' - is_active = True - is_staff = False - - -class CourseEnrollmentFactory(factory.Factory): - FACTORY_FOR = CourseEnrollment - user = factory.SubFactory(UserFactory) - course_id = 'edX/toy/2012_Fall' - - class RoleFactory(factory.Factory): FACTORY_FOR = Role name = 'Student'