Skip to content

Commit

Permalink
Merge pull request #61 from pstaabp/tests-on-separate-db
Browse files Browse the repository at this point in the history
Tests on separate db
  • Loading branch information
drgrice1 authored Nov 19, 2021
2 parents 8b760f7 + 835ba26 commit bde43c9
Show file tree
Hide file tree
Showing 22 changed files with 24,124 additions and 132 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:
env:
HARNESS_PERL_SWITCHES: -MDevel::Cover
run: |
sed 's/\/opt\/webwork\//\/__w\/webwork3\//g' conf/webwork3.dist.yml > conf/webwork3.yml
cp conf/webwork3.dist.yml conf/webwork3.yml
cp conf/ww3-dev.dist.yml conf/ww3-dev.yml
perl t/db/build_db.pl
prove -r t
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pnpm-debug.log*
# Project files
sample_db.sqlite
conf/webwork3.yml
conf/ww3-dev.yml
conf/apache2/webwork3-apache2.conf
conf/apache2/webwork3.service
conf/apache2/renderer.service
Expand Down
8 changes: 2 additions & 6 deletions conf/webwork3.dist.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
---
secrets:
- 3cdf63327fcf77deaed1d200df4b9fee66af2326
webwork3_home: /opt/webwork/webwork3

# If ignore_permissions is set to true, all routes can be executed.
# This should only be used in development.
ignore_permissions: true
webwork3_home: .

# Database settings

# For the sqlite database
database_dsn: dbi:SQLite:/opt/webwork/webwork3/t/db/sample_db.sqlite
database_dsn: dbi:SQLite:./t/db/sample_db.sqlite
# For mysql or mariadb
#database_dsn: dbi:mysql:dbname=webwork3

Expand Down
22 changes: 22 additions & 0 deletions conf/ww3-dev.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
secrets:
- 3cdf63327fcf77deaed1d200df4b9fee66af2326
webwork3_home: .

# Database settings

# These settings are used for running unit_tests. You should choose a database
# that is separate from any either production or other testing database. The
# sqlite one is recommended. If you choose another full-featured DB, select a
# database that is different than others.

# For the sqlite database
database_dsn: dbi:SQLite:./t/db/sample_db.sqlite
# For mysql or mariadb
# note: choose a database
#database_dsn: dbi:mysql:dbname=webwork3_test

# Database credentials for mysql or mariadb.
# These are ignored if the 'sqlite' database is used.
database_user: webworkWrite
database_password: password
9 changes: 0 additions & 9 deletions lib/DB/TestUtils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,4 @@ sub filterBySetType {
return @filtered_sets;
}

sub loadSchema {
# load some configuration for the database:

my $config = LoadFile("$main::lib_dir/../conf/webwork3.yml");

# Load the database
return DB::Schema->connect($config->{database_dsn}, $config->{database_user}, $config->{database_password});
}

1;
23,890 changes: 23,890 additions & 0 deletions super-linter.log

Large diffs are not rendered by default.

20 changes: 13 additions & 7 deletions t/db/001_courses.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ use strict;
BEGIN {
use File::Basename qw/dirname/;
use Cwd qw/abs_path/;
$main::test_dir = abs_path(dirname(__FILE__));
$main::lib_dir = dirname(dirname($main::test_dir)) . '/lib';
$main::ww3_dir = abs_path(dirname(__FILE__)) . '/../..';
}

use lib "$main::lib_dir";
use lib "$main::ww3_dir/lib";

use List::MoreUtils qw(uniq);

use Test::More;
use Test::Exception;
use YAML::XS qw/LoadFile/;

use DB::WithParams;
use DB::WithDates;
Expand All @@ -27,16 +27,22 @@ use DB::TestUtils qw/loadCSV removeIDs loadSchema/;

# load some configuration for the database:

my $schema = loadSchema();
my $config_file = "$main::ww3_dir/conf/ww3-dev.yml";
die "The file $config_file does not exist. Did you make a copy of it from ww3-dev.dist.yml ?"
unless (-e $config_file);

my $config = LoadFile($config_file);

my $schema =
DB::Schema->connect($config->{database_dsn}, $config->{database_user}, $config->{database_password});

# $schema->storage->debug(1); # print out the SQL commands.

my $course_rs = $schema->resultset("Course");

## get a list of courses from the CSV file

my @courses = loadCSV("$main::test_dir/sample_data/courses.csv");

my @courses = loadCSV("$main::ww3_dir/t/db/sample_data/courses.csv");
for my $course (@courses) {
delete $course->{course_params};
}
Expand Down Expand Up @@ -147,7 +153,7 @@ for my $user_course (@user_courses) {
removeIDs($user_course);
}

my @students = loadCSV("$main::test_dir/sample_data/students.csv");
my @students = loadCSV("$main::ww3_dir/t/db/sample_data/students.csv");

my @user_courses_from_csv = grep { $_->{username} eq "lisa" } @students;

Expand Down
18 changes: 11 additions & 7 deletions t/db/002_course_settings.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ use strict;
BEGIN {
use File::Basename qw/dirname/;
use Cwd qw/abs_path/;
$main::test_dir = abs_path(dirname(__FILE__));
$main::webwork_home = dirname(dirname($main::test_dir));
$main::lib_dir = "$main::webwork_home/lib";
$main::ww3_dir = abs_path(dirname(__FILE__)) . '/../..';
}

use lib "$main::lib_dir";
use lib "$main::ww3_dir/lib";

use Data::Dump qw/dd/;
use Data::Dumper;
use List::MoreUtils qw(uniq);

use Test::More;
Expand All @@ -27,14 +25,20 @@ use DB::WithParams;
use DB::WithDates;
use DB::Schema;

# use WeBWorK3::Utils::Settings qw/checkSettings/;
use WeBWorK3::Utils::Settings qw/getDefaultCourseSettings getDefaultCourseValues
validateSettingsConfFile validateSingleCourseSetting validateSettingConfig
isInteger isTimeString isTimeDuration isDecimal mergeCourseSettings/;

use DB::TestUtils qw/loadCSV removeIDs loadSchema/;

my $schema = loadSchema();
my $config_file = "$main::ww3_dir/conf/ww3-dev.yml";
die "The file $config_file does not exist. Did you make a copy of it from ww3-dev.dist.yml ?"
unless (-e $config_file);

my $config = LoadFile($config_file);

my $schema =
DB::Schema->connect($config->{database_dsn}, $config->{database_user}, $config->{database_password});

# $schema->storage->debug(1); # print out the SQL commands.

Expand Down
21 changes: 15 additions & 6 deletions t/db/003_users.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ use strict;
BEGIN {
use File::Basename qw/dirname/;
use Cwd qw/abs_path/;
$main::test_dir = abs_path(dirname(__FILE__));
$main::lib_dir = dirname(dirname($main::test_dir)) . '/lib';
$main::ww3_dir = abs_path(dirname(__FILE__)) . '/../..';
}

use lib "$main::lib_dir";
use lib "$main::ww3_dir/lib";

use Text::CSV qw/csv/;
use Data::Dump qw/dd/;
use Data::Dumper;
use Test::More;
use Test::Exception;
use Try::Tiny;
Expand All @@ -25,8 +24,18 @@ use DB::WithParams;
use DB::WithDates;
use DB::Schema;
use DB::TestUtils qw/loadCSV removeIDs loadSchema/;
use YAML qw/LoadFile/;

my $config;
my $config_file = "$main::ww3_dir/conf/ww3-dev.yml";
if (-e $config_file) {
$config = LoadFile($config_file);
} else {
die "The file $config_file does not exist. Did you make a copy of it from ww3-dev.dist.yml ?";
}

my $schema = loadSchema();
my $schema =
DB::Schema->connect($config->{database_dsn}, $config->{database_user}, $config->{database_password});

# $schema->storage->debug(1); # print out the SQL commands.

Expand All @@ -37,7 +46,7 @@ my $maggie = $users_rs->find({ username => "maggie" });
$maggie->delete if defined($maggie);

## get a list of users from the CSV file
my @students = loadCSV("$main::test_dir/sample_data/students.csv");
my @students = loadCSV("$main::ww3_dir/t/db/sample_data/students.csv");

# remove duplicates
my %seen = ();
Expand Down
17 changes: 12 additions & 5 deletions t/db/004_course_users.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ use strict;
BEGIN {
use File::Basename qw/dirname/;
use Cwd qw/abs_path/;
$main::test_dir = abs_path(dirname(__FILE__));
$main::lib_dir = dirname(dirname($main::test_dir)) . '/lib';
$main::ww3_dir = abs_path(dirname(__FILE__)) . '/../..';
}

use lib "$main::lib_dir";
use lib "$main::ww3_dir/lib";

use Text::CSV qw/csv/;
use List::Util qw(uniq);
Expand All @@ -27,15 +26,23 @@ use DB::Schema;
use DB::TestUtils qw/loadCSV removeIDs loadSchema/;
use DB::Utils qw/removeLoginParams/;

my $schema = loadSchema();
my $config_file = "$main::ww3_dir/conf/ww3-dev.yml";
die "The file $config_file does not exist. Did you make a copy of it from ww3-dev.dist.yml ?"
unless (-e $config_file);

my $config = LoadFile($config_file);

my $schema =
DB::Schema->connect($config->{database_dsn}, $config->{database_user}, $config->{database_password});

# $schema->storage->debug(1); # print out the SQL commands.

my $course_rs = $schema->resultset("Course");
my $user_rs = $schema->resultset("User");
my $cu_rs = $schema->resultset("CourseUser");

## get a list of users from the CSV file
my @students = loadCSV("$main::test_dir/sample_data/students.csv");
my @students = loadCSV("$main::ww3_dir/t/db/sample_data/students.csv");
for my $student (@students) {
$student->{is_admin} = 0;
}
Expand Down
20 changes: 13 additions & 7 deletions t/db/005_hwsets.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ use strict;
BEGIN {
use File::Basename qw/dirname/;
use Cwd qw/abs_path/;
$main::test_dir = abs_path(dirname(__FILE__));
$main::lib_dir = dirname(dirname($main::test_dir)) . '/lib';
$main::ww3_dir = abs_path(dirname(__FILE__)) . '/../..';
}

use lib "$main::lib_dir";
use lib "$main::ww3_dir/lib";

use Text::CSV qw/csv/;
use List::MoreUtils qw(uniq);
Expand All @@ -30,7 +29,14 @@ use DB::WithDates;
use DB::Schema;
use DB::TestUtils qw/loadCSV removeIDs filterBySetType loadSchema/;

my $schema = loadSchema();
my $config_file = "$main::ww3_dir/conf/ww3-dev.yml";
die "The file $config_file does not exist. Did you make a copy of it from ww3-dev.dist.yml ?"
unless (-e $config_file);

my $config = LoadFile($config_file);

my $schema =
DB::Schema->connect($config->{database_dsn}, $config->{database_user}, $config->{database_password});

my $strp = DateTime::Format::Strptime->new(pattern => '%FT%T', on_error => 'croak');

Expand All @@ -44,7 +50,7 @@ my $course_rs = $schema->resultset("Course");
my $user_rs = $schema->resultset("User");

# load HW sets from CSV file
my @hw_sets = loadCSV("$main::test_dir/sample_data/hw_sets.csv");
my @hw_sets = loadCSV("$main::ww3_dir/t/db/sample_data/hw_sets.csv");
for my $set (@hw_sets) {
$set->{set_type} = "HW";
for my $date (keys %{ $set->{set_dates} }) {
Expand All @@ -53,7 +59,7 @@ for my $set (@hw_sets) {
}
$set->{set_params} = {} unless defined $set->{set_params};
}
my @quizzes = loadCSV("$main::test_dir/sample_data/quizzes.csv");
my @quizzes = loadCSV("$main::ww3_dir/t/db/sample_data/quizzes.csv");
for my $quiz (@quizzes) {
$quiz->{set_type} = "QUIZ";
for my $date (keys %{ $quiz->{set_dates} }) {
Expand All @@ -63,7 +69,7 @@ for my $quiz (@quizzes) {
$quiz->{set_params} = {} unless defined $quiz->{set_params};
}

my @review_sets = loadCSV("$main::test_dir/sample_data/review_sets.csv");
my @review_sets = loadCSV("$main::ww3_dir/t/db/sample_data/review_sets.csv");
for my $set (@review_sets) {
$set->{set_type} = "REVIEW";
for my $date (keys %{ $set->{set_dates} }) {
Expand Down
20 changes: 14 additions & 6 deletions t/db/006_quizzes.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ use strict;
BEGIN {
use File::Basename qw/dirname/;
use Cwd qw/abs_path/;
$main::test_dir = abs_path(dirname(__FILE__));
$main::lib_dir = dirname(dirname($main::test_dir)) . '/lib';
$main::ww3_dir = abs_path(dirname(__FILE__)) . '/../..';
}

use lib "$main::lib_dir";
use lib "$main::ww3_dir/lib";

use Text::CSV qw/csv/;
use Test::More;
Expand All @@ -28,8 +27,17 @@ use DB::WithDates;
use DB::Schema;
use DB::TestUtils qw/loadCSV removeIDs filterBySetType loadSchema/;

my $schema = loadSchema();
my $strp = DateTime::Format::Strptime->new(pattern => '%FT%T', on_error => 'croak');
# load the database
my $config_file = "$main::ww3_dir/conf/ww3-dev.yml";
die "The file $config_file does not exist. Did you make a copy of it from ww3-dev.dist.yml ?"
unless (-e $config_file);

my $config = LoadFile($config_file);

my $schema =
DB::Schema->connect($config->{database_dsn}, $config->{database_user}, $config->{database_password});

my $strp = DateTime::Format::Strptime->new(pattern => '%FT%T', on_error => 'croak');

# $schema->storage->debug(1); # print out the SQL commands.

Expand All @@ -42,7 +50,7 @@ my $user_rs = $schema->resultset("User");

my @all_problem_sets; # stores all problem_sets

my @quizzes = loadCSV("$main::test_dir/sample_data/quizzes.csv");
my @quizzes = loadCSV("$main::ww3_dir/t/db/sample_data/quizzes.csv");
for my $quiz (@quizzes) {
$quiz->{type} = 2;
$quiz->{set_type} = "QUIZ";
Expand Down
Loading

0 comments on commit bde43c9

Please sign in to comment.