Reuse course creator user in bok-choy tests and have them not be global staff
This commit is contained in:
@@ -3,6 +3,7 @@ Fixture to create a course and course components (XBlocks).
|
||||
"""
|
||||
|
||||
import json
|
||||
import re
|
||||
import datetime
|
||||
import requests
|
||||
from textwrap import dedent
|
||||
@@ -24,6 +25,9 @@ class StudioApiFixture(object):
|
||||
"""
|
||||
Base class for fixtures that use the Studio restful API.
|
||||
"""
|
||||
def __init__(self):
|
||||
# Info about the auto-auth user used to create the course.
|
||||
self.user = {}
|
||||
|
||||
@lazy
|
||||
def session(self):
|
||||
@@ -37,6 +41,14 @@ class StudioApiFixture(object):
|
||||
|
||||
# Return the session from the request
|
||||
if response.ok:
|
||||
# auto_auth returns information about the newly created user
|
||||
# capture this so it can be used by by the testcases.
|
||||
user_pattern = re.compile('Logged in user {0} \({1}\) with password {2} and user_id {3}'.format(
|
||||
'(?P<username>\S+)', '(?P<email>[^\)]+)', '(?P<password>\S+)', '(?P<user_id>\d+)'))
|
||||
user_matches = re.match(user_pattern, response.text)
|
||||
if user_matches:
|
||||
self.user = user_matches.groupdict()
|
||||
|
||||
return session
|
||||
|
||||
else:
|
||||
@@ -238,6 +250,8 @@ class CourseFixture(StudioApiFixture):
|
||||
self._upload_assets()
|
||||
self._create_xblock_children(self._course_location, self._children)
|
||||
|
||||
return self
|
||||
|
||||
@property
|
||||
def _course_key(self):
|
||||
"""
|
||||
|
||||
@@ -32,7 +32,6 @@ class XBlockAcidBase(WebAppTest):
|
||||
'display_name': 'Test Course ' + self.unique_id
|
||||
}
|
||||
|
||||
self.auth_page = AutoAuthPage(self.browser, staff=True)
|
||||
self.outline = CourseOutlinePage(
|
||||
self.browser,
|
||||
self.course_info['org'],
|
||||
@@ -44,6 +43,13 @@ class XBlockAcidBase(WebAppTest):
|
||||
|
||||
self.setup_fixtures()
|
||||
|
||||
self.auth_page = AutoAuthPage(
|
||||
self.browser,
|
||||
staff=False,
|
||||
username=self.user.get('username'),
|
||||
email=self.user.get('email'),
|
||||
password=self.user.get('password')
|
||||
)
|
||||
self.auth_page.visit()
|
||||
|
||||
def validate_acid_block_preview(self, acid_block):
|
||||
@@ -112,6 +118,8 @@ class XBlockAcidNoChildTest(XBlockAcidBase):
|
||||
)
|
||||
).install()
|
||||
|
||||
self.user = course_fix.user
|
||||
|
||||
|
||||
class XBlockAcidParentBase(XBlockAcidBase):
|
||||
"""
|
||||
@@ -167,6 +175,8 @@ class XBlockAcidEmptyParentTest(XBlockAcidParentBase):
|
||||
)
|
||||
).install()
|
||||
|
||||
self.user = course_fix.user
|
||||
|
||||
|
||||
class XBlockAcidChildTest(XBlockAcidParentBase):
|
||||
"""
|
||||
@@ -197,6 +207,9 @@ class XBlockAcidChildTest(XBlockAcidParentBase):
|
||||
)
|
||||
).install()
|
||||
|
||||
self.user = course_fix.user
|
||||
|
||||
|
||||
@skip('This will fail until we fix support of children in pure XBlocks')
|
||||
def test_acid_block_preview(self):
|
||||
super(XBlockAcidChildTest, self).test_acid_block_preview()
|
||||
|
||||
@@ -25,7 +25,6 @@ class ContainerBase(UniqueCourseTest):
|
||||
# Ensure that the superclass sets up
|
||||
super(ContainerBase, self).setUp()
|
||||
|
||||
self.auth_page = AutoAuthPage(self.browser, staff=True)
|
||||
self.outline = CourseOutlinePage(
|
||||
self.browser,
|
||||
self.course_info['org'],
|
||||
@@ -58,6 +57,13 @@ class ContainerBase(UniqueCourseTest):
|
||||
|
||||
self.setup_fixtures()
|
||||
|
||||
self.auth_page = AutoAuthPage(
|
||||
self.browser,
|
||||
staff=False,
|
||||
username=self.user.get('username'),
|
||||
email=self.user.get('email'),
|
||||
password=self.user.get('password')
|
||||
)
|
||||
self.auth_page.visit()
|
||||
|
||||
def setup_fixtures(self):
|
||||
@@ -88,6 +94,8 @@ class ContainerBase(UniqueCourseTest):
|
||||
)
|
||||
).install()
|
||||
|
||||
self.user = course_fix.user
|
||||
|
||||
def go_to_container_page(self, make_draft=False):
|
||||
unit = self.go_to_unit_page(make_draft)
|
||||
container = unit.components[0].go_to_container()
|
||||
|
||||
@@ -77,14 +77,26 @@ class CoursePagesTest(UniqueCourseTest):
|
||||
"""
|
||||
super(CoursePagesTest, self).setUp()
|
||||
|
||||
CourseFixture(
|
||||
course_fix = CourseFixture(
|
||||
self.course_info['org'],
|
||||
self.course_info['number'],
|
||||
self.course_info['run'],
|
||||
self.course_info['display_name']
|
||||
).install()
|
||||
)
|
||||
|
||||
self.auth_page = AutoAuthPage(self.browser, staff=True)
|
||||
course_fix.install()
|
||||
|
||||
# Log in as the user that created the course, and also make it
|
||||
# so that they are no longer global staff.
|
||||
# They will have been given instructor access to the course
|
||||
# and enrolled in it when they created it.
|
||||
self.auth_page = AutoAuthPage(
|
||||
self.browser,
|
||||
staff=False,
|
||||
username=course_fix.user.get('username'),
|
||||
email=course_fix.user.get('email'),
|
||||
password=course_fix.user.get('password')
|
||||
)
|
||||
|
||||
self.pages = [
|
||||
clz(self.browser, self.course_info['org'], self.course_info['number'], self.course_info['run'])
|
||||
@@ -116,7 +128,8 @@ class DiscussionPreviewTest(UniqueCourseTest):
|
||||
|
||||
def setUp(self):
|
||||
super(DiscussionPreviewTest, self).setUp()
|
||||
CourseFixture(**self.course_info).add_children(
|
||||
|
||||
course_fix = CourseFixture(**self.course_info).add_children(
|
||||
XBlockFixtureDesc("chapter", "Test Section").add_children(
|
||||
XBlockFixtureDesc("sequential", "Test Subsection").add_children(
|
||||
XBlockFixtureDesc("vertical", "Test Unit").add_children(
|
||||
@@ -127,9 +140,19 @@ class DiscussionPreviewTest(UniqueCourseTest):
|
||||
)
|
||||
)
|
||||
)
|
||||
).install()
|
||||
)
|
||||
|
||||
course_fix.install()
|
||||
|
||||
self.auth_page = AutoAuthPage(
|
||||
self.browser,
|
||||
staff=False,
|
||||
username=course_fix.user.get('username'),
|
||||
email=course_fix.user.get('email'),
|
||||
password=course_fix.user.get('password')
|
||||
)
|
||||
self.auth_page.visit()
|
||||
|
||||
AutoAuthPage(self.browser, staff=True).visit()
|
||||
cop = CourseOutlinePage(
|
||||
self.browser,
|
||||
self.course_info['org'],
|
||||
|
||||
Reference in New Issue
Block a user