Commit ec308e97 by David Baumgold

Add lettuce test for transferring ownership of a course using the course team page

parent 607c06cb
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
from lettuce import world, step from lettuce import world, step
from nose.tools import assert_true from nose.tools import assert_true
from auth.authz import get_user_by_email from auth.authz import get_user_by_email, get_course_groupname_for_role
from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.keys import Keys
import time import time
from django.contrib.auth.models import Group
from logging import getLogger from logging import getLogger
logger = getLogger(__name__) logger = getLogger(__name__)
...@@ -163,18 +164,19 @@ def log_into_studio( ...@@ -163,18 +164,19 @@ def log_into_studio(
def create_a_course(): def create_a_course():
world.scenario_dict['COURSE'] = world.CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course') course = world.CourseFactory.create(org='MITx', course='999', display_name='Robot Super Course')
world.scenario_dict['COURSE'] = course
user = world.scenario_dict.get("USER")
if not user:
user = get_user_by_email('robot+studio@edx.org')
# Add the user to the instructor group of the course # Add the user to the instructor group of the course
# so they will have the permissions to see it in studio # so they will have the permissions to see it in studio
for role in ("staff", "instructor"):
course = world.GroupFactory.create(name='instructor_MITx/{}/{}'.format(world.scenario_dict['COURSE'].number, groupname = get_course_groupname_for_role(course.location, role)
world.scenario_dict['COURSE'].display_name.replace(" ", "_"))) group, __ = Group.objects.get_or_create(name=groupname)
if world.scenario_dict.get('USER') is None: user.groups.add(group)
user = world.scenario_dict['USER']
else:
user = get_user_by_email('robot+studio@edx.org')
user.groups.add(course)
user.save() user.save()
world.browser.reload() world.browser.reload()
......
...@@ -57,3 +57,17 @@ Feature: Course Team ...@@ -57,3 +57,17 @@ Feature: Course Team
Then "frank" should not be marked as an admin Then "frank" should not be marked as an admin
And he cannot add users And he cannot add users
And he cannot delete users And he cannot delete users
Scenario: Admins should be able to give course ownership to someone else
Given I have opened a new course in Studio
And the user "gina" exists
And I am viewing the course team settings
When I add "gina" to the course team
And I make "gina" a course team admin
And I remove admin rights from myself
And "gina" logs in
And she selects the new course
And she views the course team settings
And she deletes me from the course team
And I log in
Then I do not see the course on my page
...@@ -17,13 +17,20 @@ def view_grading_settings(_step, whom): ...@@ -17,13 +17,20 @@ def view_grading_settings(_step, whom):
world.css_click(link_css) world.css_click(link_css)
@step(u'the user "([^"]*)" exists( as a course admin)?$') @step(u'the user "([^"]*)" exists( as a course (admin|staff member))?$')
def create_other_user(_step, name, course_admin): def create_other_user(_step, name, has_extra_perms, role_name):
user = create_studio_user(uname=name, password=PASSWORD, email=(name + EMAIL_EXTENSION)) email = name + EMAIL_EXTENSION
if course_admin: user = create_studio_user(uname=name, password=PASSWORD, email=email)
if has_extra_perms:
location = world.scenario_dict["COURSE"].location location = world.scenario_dict["COURSE"].location
for role in ("staff", "instructor"): if role_name == "admin":
group, __ = Group.objects.get_or_create(name=get_course_groupname_for_role(location, role)) # admins get staff privileges, as well
roles = ("staff", "instructor")
else:
roles = ("staff",)
for role in roles:
groupname = get_course_groupname_for_role(location, role)
group, __ = Group.objects.get_or_create(name=groupname)
user.groups.add(group) user.groups.add(group)
user.save() user.save()
...@@ -49,6 +56,13 @@ def delete_other_user(_step, name): ...@@ -49,6 +56,13 @@ def delete_other_user(_step, name):
world.css_click(to_delete_css) world.css_click(to_delete_css)
@step(u's?he deletes me from the course team')
def other_delete_self(_step):
to_delete_css = '.user-item .item-actions a.remove-user[data-id="{email}"]'.format(
email="robot+studio@edx.org")
world.css_click(to_delete_css)
@step(u'I make "([^"]*)" a course team admin') @step(u'I make "([^"]*)" a course team admin')
def make_course_team_admin(_step, name): def make_course_team_admin(_step, name):
admin_btn_css = '.user-item[data-email="{email}"] .user-actions .add-admin-role'.format( admin_btn_css = '.user-item[data-email="{email}"] .user-actions .add-admin-role'.format(
...@@ -56,10 +70,14 @@ def make_course_team_admin(_step, name): ...@@ -56,10 +70,14 @@ def make_course_team_admin(_step, name):
world.css_click(admin_btn_css) world.css_click(admin_btn_css)
@step(u'I remove admin rights from "([^"]*)"') @step(u'I remove admin rights from ("([^"]*)"|myself)')
def remove_course_team_admin(_step, name): def remove_course_team_admin(_step, outer_capture, name):
if outer_capture == "myself":
email = world.scenario_dict["USER"].email
else:
email = name + EMAIL_EXTENSION
admin_btn_css = '.user-item[data-email="{email}"] .user-actions .remove-admin-role'.format( admin_btn_css = '.user-item[data-email="{email}"] .user-actions .remove-admin-role'.format(
email=name+EMAIL_EXTENSION) email=email)
world.css_click(admin_btn_css) world.css_click(admin_btn_css)
...@@ -68,8 +86,9 @@ def other_user_login(_step, name): ...@@ -68,8 +86,9 @@ def other_user_login(_step, name):
log_into_studio(uname=name, password=PASSWORD, email=name + EMAIL_EXTENSION) log_into_studio(uname=name, password=PASSWORD, email=name + EMAIL_EXTENSION)
@step(u'I( do not)? see the course on my page')
@step(u's?he does( not)? see the course on (his|her) page') @step(u's?he does( not)? see the course on (his|her) page')
def see_course(_step, inverted, gender): def see_course(_step, inverted, gender='self'):
class_css = 'span.class-name' class_css = 'span.class-name'
all_courses = world.css_find(class_css, wait_time=1) all_courses = world.css_find(class_css, wait_time=1)
all_names = [item.html for item in all_courses] all_names = [item.html for item in all_courses]
...@@ -89,6 +108,7 @@ def marked_as_admin(_step, name, inverted): ...@@ -89,6 +108,7 @@ def marked_as_admin(_step, name, inverted):
assert world.is_css_present(flag_css) assert world.is_css_present(flag_css)
@step(u'I can(not)? delete users')
@step(u's?he can(not)? delete users') @step(u's?he can(not)? delete users')
def can_delete_users(_step, inverted): def can_delete_users(_step, inverted):
to_delete_css = 'a.remove-user' to_delete_css = 'a.remove-user'
...@@ -98,6 +118,7 @@ def can_delete_users(_step, inverted): ...@@ -98,6 +118,7 @@ def can_delete_users(_step, inverted):
assert world.is_css_present(to_delete_css) assert world.is_css_present(to_delete_css)
@step(u'I can(not)? add users')
@step(u's?he can(not)? add users') @step(u's?he can(not)? add users')
def can_add_users(_step, inverted): def can_add_users(_step, inverted):
add_css = 'a.create-user-button' add_css = 'a.create-user-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