NAME
App::Dochazka::REST::Test - Test helper functions
DESCRIPTION
This module provides helper code for unit tests.
EXPORTS
PACKAGE VARIABLES
FUNCTIONS
initialize_regression_test
Perform the boilerplate tasks that have to be done at the beginning of every test file that communicates with the Web::MREST server and/or the PostgreSQL database. Since both Web::MREST and PostgreSQL are external resources, tests that make use of them are more than mere unit tests
While some test files do not need *all* of these initialization steps, there is no harm in running them.
The t/unit/ subdirectory is reserved for test files that need *none* of these initialization steps. Having them in a separate subdirectory enables them to be run separately.
status_from_json
App::Dochazka::REST is designed to return status objects in the HTTP response body. These, of course, are sent in JSON format. This simple routine takes a JSON string and blesses it, thereby converting it back into a status object.
FIXME: There may be some encoding issues here!
req
Assemble and process a HTTP request. Takes the following positional arguments:
* Plack::Test object
* expected HTTP result code
* user to authenticate with (can be 'root', 'demo', or 'active')
* HTTP method
* resource string
* optional JSON string
If the HTTP result code is 200, the return value will be a status object, undef otherwise.
dbi_err
Wrapper for 'req' intended to eliminate duplicated code on tests that are expected to return DOCHAZKA_DBI_ERR. In addition to the arguments expected by 'req', takes one additional argument, which should be:
qr/error message subtext/
(i.e. a regex quote by which to test the $status->text)
docu_check
Check that the resource has on-line documentation (takes Plack::Test object and resource name without quotes)
create_bare_employee
For use in tests only. Spawns an employee object and inserts it into the database.
Takes PROPLIST which is passed through unmunged to the employee spawn method.
Returns the new Employee object.
delete_bare_employee
Takes a single argument: the EID.
Loads the EID into a new Employee object and calls that object's delete method.
create_active_employee
Create a testing employee with 'active' privilege. The employee will get an 'active' privhistory record with date 1892-01-01.
create_inactive_employee
Create a testing employee with 'inactive' privilege. The employee will get an 'inactive' privhistory record with date 1892-01-01.
delete_employee_by_nick
Delete testing employee (takes Plack::Test object and nick)
create_testing_activity
Tests will need to set up and tear down testing activities
delete_testing_activity
Tests will need to set up and tear down testing activities
create_testing_interval
Tests will need to set up and tear down testing intervals
delete_testing_interval
Tests will need to set up and tear down testing intervals
create_testing_component
Tests will need to set up and tear down testing components
delete_testing_component
Tests will need to set up and tear down testing components
test_schedule_model
Creates and returns a testing schedule without needing a Plack::Test object.
create_testing_schedule
Tests will need to set up and tear down testing schedules. Takes a Plack::Test object as its only argument.
delete_testing_schedule
Tests will need to set up and tear down testing schedule. Takes a SID as its only argument.
delete_all_attendance_data
Wipe out all attendance data by deleting all rows from all tables (in the correct order).
To be called like this:
$status = delete_all_attendance_data();
BAIL_OUT(0) unless $status->ok;