[LON-CAPA-cvs] cvs: modules /jerf/tests Utils.pm utils_authorTest.pm
bowersj2
lon-capa-cvs@mail.lon-capa.org
Wed, 09 Jul 2003 21:04:22 -0000
bowersj2 Wed Jul 9 17:04:22 2003 EDT
Modified files:
/modules/jerf/tests Utils.pm utils_authorTest.pm
Log:
Tracked down some problems I was having with metadata checking.
Getting ready to commit some tests that will detect the metadata troubles
we had with .99.2-ish if they ever come back.
Index: modules/jerf/tests/Utils.pm
diff -u modules/jerf/tests/Utils.pm:1.9 modules/jerf/tests/Utils.pm:1.10
--- modules/jerf/tests/Utils.pm:1.9 Tue Jul 8 16:44:06 2003
+++ modules/jerf/tests/Utils.pm Wed Jul 9 17:04:21 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# testing utilities
#
-# $Id: Utils.pm,v 1.9 2003/07/08 20:44:06 bowersj2 Exp $
+# $Id: Utils.pm,v 1.10 2003/07/09 21:04:21 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -338,6 +338,9 @@
=cut
+# We need the tags to get registered
+use Apache::lonhomework;
+
sub getResourceSpaceDir {
my $self = shift;
return '/home/' . $self->{name} . '/public_html/';
@@ -384,7 +387,7 @@
}
# Does this user have authoring privileges?
- if ($self->isAuthor($r)) {
+ if (!$self->isAuthor($r)) {
return 0;
}
@@ -497,6 +500,12 @@
postcontent => $paramHash,
handler_list => ['Apache::lonacc']});
$secondRequest->doHandler("Apache::lonpublisher");
+
+ my $result = $secondRequest->getOutputString();
+ # Basic check that we succeeded: Does the final page correctly mention
+ # "Copied source file"? This is probably not an adequate check but
+ # it's better then nothing.
+ return $result =~ /Copied source file/;
}
=pod
Index: modules/jerf/tests/utils_authorTest.pm
diff -u modules/jerf/tests/utils_authorTest.pm:1.1 modules/jerf/tests/utils_authorTest.pm:1.2
--- modules/jerf/tests/utils_authorTest.pm:1.1 Tue Jul 8 14:15:15 2003
+++ modules/jerf/tests/utils_authorTest.pm Wed Jul 9 17:04:21 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# testing the course and user objects w.r.t. authoring
#
-# $Id: utils_authorTest.pm,v 1.1 2003/07/08 18:15:15 bowersj2 Exp $
+# $Id: utils_authorTest.pm,v 1.2 2003/07/09 21:04:21 bowersj2 Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -81,7 +81,7 @@
my $self = shift;
# This tests that publication of a simple HTML resource from the data
- # directory
+ # directory, and a simple problem
# Create the author and log in, choosing the author role
my $user = Utils::User->new($Data::testDomain, $Data::authorName);
@@ -89,7 +89,63 @@
$user->login($r);
$self->assert($user->selectRole($r, 'au'));
+ $user->initializeResourceSpace();
+
+ my $testResource = $Data::HTMLResources[0];
+ $user->copyResource($testResource);
+ $self->assert($user->publishResource($r, $testResource));
+ print Dumper(%Apache::lonpublisher::metadatakeys) . "\n";
+
+ $testResource = "radio.problem";
+ $user->copyResource($testResource);
+ $self->assert($user->publishResource($r, $testResource));
+ print Dumper(%Apache::lonpublisher::metadatakeys) . "\n";
+}
+
+sub test_metadata_publication {
+ my $self = shift;
+
+ # This tests the generation of metadata for each of the problems
+ # we have stored in the data directory and described in Data::simpleProblems
+ # and Data::multipartProblems.
+ # Create the author and log in, choosing the author role
+ my $user = Utils::User->new($Data::testDomain, $Data::authorName);
+ my $r = ApacheRequest->new({user=>'user'});
+ $user->login($r);
+ $self->assert($user->selectRole($r, 'au'));
+
+ $user->initializeResourceSpace();
+
+ for my $type, my $source (each %Data::simpleProblems) {
+ $user->copyResource($source);
+ $self->assert($user->publishResource($r, $source));
+
+ my %metadata = %Apache::lonpublisher::metadatakeys;
+ my %comparision = ();
+ # Construct the comparision metadata keys
+ for (keys %{$Data::metadata{simple}}) {
+ my $destKey = $_;
+ $destKey =~ s/PROBLEMTYPE/$type/g;
+ $comparision{$destKey} = $Data::metadata{simple}->{$_};
+ }
+ # Add any problem-type-specific overlays
+ for (keys %{$Data::metadata{$type}}) {
+ $comparision{$destKey} = $Data::metadata{$type}->{$_};
+ }
+
+ $self->assert(scalar(keys(%comparision)) == scalar(keys(%metadata)),
+ "Publishing problem type $type had mismatched metadata: ".
+ "\nMetadata from lonpublisher:\n" . Dumper(%metadata) .
+ "\nMetadata from Data.pm:\n" . Dumper(%comparision));
+ for (keys(%metadata)) {
+ $self->assert($metadata{$_} eq $comparision{$_},
+ "Metadata key $_ not equal in the Data.pm hash while ".
+ "publishing.\nValue from lonpublisher: " .
+ $metadata{$_} . "\nValue from Data.pm: " .
+ $comparision{$_});
+ }
+ }
}
1;