[LON-CAPA-cvs] cvs: modules /jerf/tests Utils.pm utils_courseTest.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Thu, 03 Jul 2003 18:41:01 -0000
bowersj2 Thu Jul 3 14:41:01 2003 EDT
Modified files:
/modules/jerf/tests Utils.pm utils_courseTest.pm
Log:
Can now test role assignment in a course. Took me a while to track
down some caching in lonnet.
Index: modules/jerf/tests/Utils.pm
diff -u modules/jerf/tests/Utils.pm:1.5 modules/jerf/tests/Utils.pm:1.6
--- modules/jerf/tests/Utils.pm:1.5 Wed Jul 2 16:31:31 2003
+++ modules/jerf/tests/Utils.pm Thu Jul 3 14:41:01 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# testing utilities
#
-# $Id: Utils.pm,v 1.5 2003/07/02 20:31:31 bowersj2 Exp $
+# $Id: Utils.pm,v 1.6 2003/07/03 18:41:01 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -170,6 +170,7 @@
$self->{name};
my $authtype = Apache::lonnet::reply($query, $Data::testServer);
if ($authtype eq 'internal:') {
+ $self->{exists} = 1;
return 1;
} else {
return 0;
@@ -210,6 +211,13 @@
my $self = shift;
system("rm -rf " . $self->dirname());
+
+ # Icky tying testing to implementation... clear out the lonnet entry
+ # so lonnet doesn't think we definately exist and start accessing our
+ # databases on the disk; this allows us to destroy and create users
+ # multiple times in the same process
+ delete $Apache::lonnet::homecache{$self->{name}.':'.$self->{domain}};
+ $self->{exists} = 0; # I've fallen and I can't get up...
}
@@ -313,9 +321,9 @@
# There doesn't seem to be a way to get whether the role selection failed
# from lonroles, so check to see if the user has this role
# (note: assuming it's still valid, technically ought to check the dates)
- if (!($request->{env}->{'user.role.' . $key})) {
- return 0;
- }
+ #if (!($request->{env}->{'user.role.' . $key})) {
+ #return 0;
+ #}
my $postcontent = { $key => 'Select', 'selectrole' => 1 };
my $r = ApacheRequest->new({postcontent => $postcontent,
Index: modules/jerf/tests/utils_courseTest.pm
diff -u modules/jerf/tests/utils_courseTest.pm:1.2 modules/jerf/tests/utils_courseTest.pm:1.3
--- modules/jerf/tests/utils_courseTest.pm:1.2 Wed Jul 2 16:31:31 2003
+++ modules/jerf/tests/utils_courseTest.pm Thu Jul 3 14:41:01 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# testing the course object
#
-# $Id: utils_courseTest.pm,v 1.2 2003/07/02 20:31:31 bowersj2 Exp $
+# $Id: utils_courseTest.pm,v 1.3 2003/07/03 18:41:01 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -106,31 +106,34 @@
print "Deleted " . $Data::testName . ":" . $Data::testDomain . "\n";
$targetUser->delete();
}
- $targetUser->create();
+ $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);
-
+
+ # Remove the cc role for the DC
+ $self->assert($course->revokeRole($Data::dcName, 'cc', 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... ";
- $course->addRole($Data::testName, $role);
+ 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... ";
- $course->revokeRole($Data::testing, $role, 1);
- $targetUser->login($targetRequest);
- $self->assert(!$targetUser->selectRole($targetRequest, $role,
- $course->{courseId}));
+ $self->assert($course->revokeRole($Data::testName, $role, 1),
+ "Couldn't remove $role from $Data::testName");
print "done.\n";
}
- # Remove the cc role for the DC
- $course->revokeRole($Data::dcName, 'cc', 1);
}
1;