Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using the Test2::Suite and Test2::MojoX modules for unit tests. #119

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

drgrice1
Copy link
Member

Note that is important for the unit tests to have the got argument first and the expected argument second in an is test. Test2::Tools::Compare converts the second expected argument into a Test2::Tools object which is important for strict checks.

Also remove the incomplete t/db/test_course_user.pl file.

Note that this depends on #117.

@drgrice1
Copy link
Member Author

Note that this requires version 0.000139 or newer of Test2::Suite since it uses check_isa in the tests. The version on Ubuntu 20.04 is 0.000129, so an install from cpan is needed there. The version on Ubuntu 22.04 is 0.000144, and so is new enough. I need to upgrade.

@drgrice1 drgrice1 force-pushed the perl-unit-tests-with-test2-suite branch 2 times, most recently from 17ea746 to d2d5888 Compare August 29, 2022 11:30
dies {
$user_rs->addCourseUser(
info => { course_name => 'Topology', username => 'quimby' },
params => { role => 'student', course_user_params => { useMathQuill => 0 } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useMathQuill is supposed to be a boolean. Switch to false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supposed to be 0. That is the point of this test. It is checking that an invalid field is passed in the parameters. If this is switched to false an exception will not be thrown because that is valid.

@@ -124,8 +124,8 @@ $t->get_ok('/webwork3/api/courses/4/settings')->status_is(200)->content_type_is(
$t->post_ok('/webwork3/api/courses' => json => $new_course)->status_is(403)->json_is('/has_permission' => 0);

$t->put_ok('/webwork3/api/courses/4' => json => { course_name => 'XXX' })->status_is(403)
->json_is('/has_permission' => false);
->json_is('/has_permission' => 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like this should be a boolean and can then this with a switch on line 95 in WeBWorK3::Controller::Permission to has_permission => false.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would then affect almost all of the other mojolicious tests as well though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not going to change this in this pull request. This was changed to 0 because currently the method returns a numeric (not boolean) value. That is a TODO for later.

params => {
course_name => 'Precalculus',
set_name => 'HW #11',
set_dates => { open => 100, due => 140, answer => 200, enable_reduced_scoring => 0 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable_reduced_scoring => false

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, this needs to be 0. That is the point of this test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, it seems that set_params => { hide_hint => 0 } should be false instead of 0 in this test so that the enable_reduced_scoring value is appropriately tested (the previous test already checks the set_params values.

@pstaabp
Copy link
Member

pstaabp commented Aug 29, 2022

Overall, this looks great. Good cleanup and improved functionality. Just added a couple of minor items in the code.

@drdrew42
Copy link
Member

It sounds like we will need a separate PR that standardizes the use of booleans (and corresponding cleanup to the DB to ensure that our boolean fields are properly typed). I'll add this to #110

@drgrice1
Copy link
Member Author

I can make the change to permissions in this pull request if you want me to. However, the objective of this pull request was to make the switch to Test2::Suite and Test2::MojoX, and not to change the current behavior. I had observed that the has_permission method was returning a numeric value, and not a boolean. I was going to point this out, and suggest that it be changed. @pstaabp clearly noticed this as well. So the more strict tests have already revealed something needed!

@pstaabp
Copy link
Member

pstaabp commented Aug 31, 2022

I'm fine merging in and then doing some cleanup, especially with booleans. That's probably the better way to go.

@drgrice1 drgrice1 force-pushed the perl-unit-tests-with-test2-suite branch 5 times, most recently from 1bac71e to 5644c16 Compare November 2, 2022 16:18
This uses Ubuntu 22.04 for the runner and docker image.
@drgrice1 drgrice1 force-pushed the perl-unit-tests-with-test2-suite branch 4 times, most recently from 1d70fe2 to dd8303e Compare November 2, 2022 21:14
…sts.

Note that is important for the unit tests to have the `got` argument
first and the `expected` argument second in an `is` test.
Test2::Tools::Compare converts the second `expected` argument into a
Test2::Tools object which is important for strict checks.

Also remove the incomplete t/db/test_course_user.pl file.
@drgrice1 drgrice1 force-pushed the perl-unit-tests-with-test2-suite branch from dd8303e to eec4b19 Compare November 3, 2022 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants