[LON-CAPA-cvs] cvs: modules /jerf/tests Utils.pm utils_courseTest.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Mon, 07 Jul 2003 15:41:34 -0000
bowersj2 Mon Jul 7 11:41:34 2003 EDT
Modified files:
/modules/jerf/tests Utils.pm utils_courseTest.pm
Log:
Now tests adding roles by section as well.
Index: modules/jerf/tests/Utils.pm
diff -u modules/jerf/tests/Utils.pm:1.6 modules/jerf/tests/Utils.pm:1.7
--- modules/jerf/tests/Utils.pm:1.6 Thu Jul 3 14:41:01 2003
+++ modules/jerf/tests/Utils.pm Mon Jul 7 11:41:34 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# testing utilities
#
-# $Id: Utils.pm,v 1.6 2003/07/03 18:41:01 bowersj2 Exp $
+# $Id: Utils.pm,v 1.7 2003/07/07 15:41:34 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -272,25 +272,6 @@
return 1;
}
-# FIXME: Document; selects the DC role for the user, if any
-# pass $r that has the user logged in.
-#sub selectRoleDC {
-# my $self = shift;
-# my $request = shift;
-
-# my $postcontent = { "dc./" . $Data::testDomain . "/" => 'Select',
-# 'selectrole' => 1 };
-# my $r = ApacheRequest->new({postcontent => $postcontent,
-# env => $request->{env},
-# 'handler_list' => ['Apache::lonacc'],
-# headers => $request->{headers},
-# uri => "/adm/roles"});
-# $r->doHandler("Apache::lonroles");
-
- # FIXME: Return 0 if the role does not exist.
-# return 1;
-#}
-
=pod
=item I<selectRole>($request, $roleType, $domainAndCourse, $section): Selects
@@ -430,10 +411,16 @@
sub revokeRole {
my $self = shift;
- (my $userName, my $role, my $delete) = @_;
+ (my $userName, my $role, my $section, my $delete) = @_;
+
+ my $url = $self->{courseId};
+ if (defined($section)) {
+ $url .= "/$section";
+ }
my $call = sub { return &Apache::lonnet::assignrole($self->{domain}, $userName,
- $self->{courseId}, $role, time(), 0, $delete); };
+ $url, $role, time(), 0,
+ $delete); };
my $result = $self->{request}->execInEnv($call);
return $result eq 'ok';
@@ -453,10 +440,15 @@
sub addRole {
my $self = shift;
- (my $userName, my $role) = @_;
+ (my $userName, my $role, my $section) = @_;
+
+ my $url = $self->{courseId};
+ if (defined($section)) {
+ $url .= "/$section";
+ }
my $call = sub { &Apache::lonnet::assignrole($self->{domain}, $userName,
- $self->{courseId}, $role, undef,
+ $url, $role, undef,
time() - 1); };
my $result = $self->{request}->execInEnv($call);
Index: modules/jerf/tests/utils_courseTest.pm
diff -u modules/jerf/tests/utils_courseTest.pm:1.3 modules/jerf/tests/utils_courseTest.pm:1.4
--- modules/jerf/tests/utils_courseTest.pm:1.3 Thu Jul 3 14:41:01 2003
+++ modules/jerf/tests/utils_courseTest.pm Mon Jul 7 11:41:34 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# testing the course object
#
-# $Id: utils_courseTest.pm,v 1.3 2003/07/03 18:41:01 bowersj2 Exp $
+# $Id: utils_courseTest.pm,v 1.4 2003/07/07 15:41:34 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -58,21 +58,21 @@
# Test *basic* creation and deletion
# Log a user in create the course
my $user = Utils::User->new($Data::testDomain, $Data::dcName,
- $Data::dcPassword);
+ $Data::dcPassword);
my $r = ApacheRequest->new({user=>$user});
$user->login($r);
$user->selectRole($r, 'dc');
# Now create a new course
my $course = Utils::Course->new($r, "Test Course, should never see this", '',
- $Data::dcName);
+ $Data::dcName);
$self->assert($course->{courseId}); # having this pretty much guarentees it worked
my $courseDir = $course->courseDirectory();
$self->assert($courseDir);
# Delete the CC role; this should be done in "test_course_adding_other_roles"
# in theory but we can't wait that long; this course object will be gone by then.
- $course->revokeRole($Data::dcName, 'cc', 1);
+ $course->revokeRole($Data::dcName, 'cc', undef, 1);
# assert the directory exists
$self->assert(-e $courseDir);
@@ -92,48 +92,62 @@
# This login will remain the DC for controlling roles.
my $user = Utils::User->new($Data::testDomain, $Data::dcName,
- $Data::dcPassword);
+ $Data::dcPassword);
my $r = ApacheRequest->new({user=>$user});
$user->login($r);
$user->selectRole($r, 'dc');
# This login will be used to change to the user roles
my $targetUser = Utils::User->new($Data::testDomain, $Data::testName,
- $Data::testPassword);
+ $Data::testPassword);
my $targetRequest = ApacheRequest->new({user=>$targetUser});
# If the user exists, wipe it out so we know the state
if ($targetUser->{exists}) {
- print "Deleted " . $Data::testName . ":" . $Data::testDomain . "\n";
- $targetUser->delete();
+ print "Deleted " . $Data::testName . ":" . $Data::testDomain . "\n";
+ $targetUser->delete();
}
- $user->login($r);
- $user->selectRole($r, 'dc');
$self->assert($targetUser->create($r));
my $course = Utils::Course->new($r, "Test Course, should never see this", '',
- $Data::dcName);
+ $Data::dcName);
# Remove the cc role for the DC
- $self->assert($course->revokeRole($Data::dcName, 'cc', 1));
+ $self->assert($course->revokeRole($Data::dcName, 'cc', undef, 1));
# Add roles w/o section to the $targetUser and make sure it can log in to
# the role
# FIXME: login failure checking, please
for my $role (@Data::courseRoles) {
- # Add the role to the target user
- print "Testing adding role '$role' to course... ";
- $self->assert($course->addRole($Data::testName, $role),
- "Couldn't add $role to $Data::testName");
- $targetUser->login($targetRequest);
- $self->assert($targetUser->selectRole($targetRequest, $role,
- $course->{courseId}));
- print "revoke $role... ";
- $self->assert($course->revokeRole($Data::testName, $role, 1),
- "Couldn't remove $role from $Data::testName");
- print "done.\n";
+ # Add the role to the target user
+ print "Testing adding role '$role' to course... ";
+ $self->assert($course->addRole($Data::testName, $role),
+ "Couldn't add $role to $Data::testName\n");
+ $targetUser->login($targetRequest);
+ $self->assert($targetUser->selectRole($targetRequest, $role,
+ $course->{courseId}));
+ print "revoke $role... ";
+ $self->assert($course->revokeRole($Data::testName, $role, undef, 1),
+ "Couldn't remove $role from $Data::testName\n");
+ print "done.\n";
+ }
+
+ # Add roles w/ section to the $targetUser
+ my $section = '001';
+ for my $role (@Data::sectionRoles) {
+ print "Testing adding role '$role' in section to course... ";
+ $self->assert($course->addRole($Data::testName, $role, $section),
+ "Couldn't add $role in section to $Data::testName\n");
+ $targetUser->login($targetRequest);
+ $self->assert($targetUser->selectRole($targetRequest, $role,
+ $course->{courseId}, $section));
+ print "revoke $role... ";
+ $self->assert($course->revokeRole($Data::testName, $role, $section, 1),
+ "Couldn't remove $role from $Data::testName\n");
+ print "done.\n";
}
+ $targetUser->delete();
}
1;