App-Dochazka-CLI

 view release on metacpan or  search on metacpan

lib/App/Dochazka/CLI/Testers.pm  view on Meta::CPAN


Confirm the current priv level using the C<EMP=george PRIV> command:

    Dochazka(2016-01-27) root ADMIN> emp=george priv
    Privilege level of george (EID 5) as of now: passerby

Display george's priv history (which is still empty at this point):

    Dochazka(2016-01-27) root ADMIN> emp=george priv history
    *** Anomaly detected ***
    Status:      404 Not Found
    Explanation: No history for EID 5  (ERR)

Add a priv history record:

    Dochazka(2016-01-28) root ADMIN> emp=george active 2015-01-02
    Privilege history record (PHID 3) added

Display george's priv history again:

    Dochazka(2016-01-29) root ADMIN> emp=george priv history

lib/App/Dochazka/CLI/Testers.pm  view on Meta::CPAN

Similarly, employee schedules may change, and Dochazka has a mechanism
(schedule history) for tracking and reflecting those changes. At this point
in our testing, our employee (george) not have any schedule history
records. More importantly, there are no schedules defined. Before we can
assign george a schedule, we will need to add one.

Verify that there are no schedules:

    Dochazka(2016-01-29) george ACTIVE> schedule fetch all
    *** Anomaly detected ***
    Status:      404 Not Found
    Explanation: There are no active schedules in the database (ERR)

And that there is no schedule history:

    Dochazka(2016-01-29) george ACTIVE> schedule history
    *** Anomaly detected ***
    Status:      404 Not Found
    Explanation: No history for EID 3  (ERR)


=head2 Define a schedule

To add a new schedule to the database, we will have to be logged in as an
administrator. For now, that means "root".

    $ dochazka-cli -u root -p immutable
    ...

lib/App/Dochazka/CLI/Testers.pm  view on Meta::CPAN

inserting a schedule history record for george. 


=head2 Create schedule history record

Log in as root:

    $ dochazka-cli -u root -p immutable
    Dochazka(2016-01-30) root ADMIN> emp=george schedule history
    *** Anomaly detected ***
    Status:      404 Not Found
    Explanation: No history for EID 3  (ERR)

Schedule histories work analogously to privilege histories:

    Dochazka(2016-01-30) root ADMIN> emp=george scode=VPP-1 2015-01-02
    Schedule history record (SHID 1) added
    Dochazka(2016-01-30) root ADMIN> emp=george schedule history
    Schedule history of george (EID 3):

    SHID Effective date SID scode Remark

lib/App/Dochazka/CLI/Util.pm  view on Meta::CPAN

    die( "AH! Not an EMPLOYEE_SPEC" ) unless $ARGS{key} =~ m/=/;

    my ( $key_spec, $key ) = $ARGS{key} =~ m/^(.*)\=(.*)$/;
    my $minimal = $ARGS{minimal} ? '/minimal' : '';

    my $status;
    if ( $key_spec =~ m/^emp/i ) {
        $status = send_req( 'GET', "employee/nick/$key$minimal" );
        BREAK_OUT: {
            last BREAK_OUT if $status->not_ok and $status->payload and $status->payload->{'http_code'} == 403;
            if ( $status->not_ok and $status->payload and $status->payload->{'http_code'} == 404 ) {
                $status = send_req( 'GET', "employee/sec_id/$key$minimal" );
                if ( $status->not_ok and $status->payload and $status->payload->{'http_code'} != 500 and looks_like_number( $key ) ) {
                    $status = send_req( 'GET', "employee/eid/$key$minimal" );
                }
            }
        }
    } elsif ( $key_spec =~ m/^nic/i ) {
        $status = send_req( 'GET', "employee/nick/$key$minimal" );
    } elsif ( $key_spec =~ m/^sec/i ) {
        $status = send_req( 'GET', "employee/sec_id/$key$minimal" );

t/cmd_active/employee.t  view on Meta::CPAN

is( $rv->level, 'OK' );
like( $rv->payload, qr/Nick:\s+worker/ );

# EMPLOYEE_SPEC on a different employee => works
$cmd = "EMPLOYEE=demo PROFILE";
$rv = process_command( $cmd );
ok( ref( $rv ) eq 'App::CELL::Status' );
is( $rv->level, 'OK' );
like( $rv->payload, qr/Nick:\s+demo/ );

# EMPLOYEE_SPEC on non-existent employee => 404
$cmd = "EMPLOYEE=999999 PROFILE";
$rv = process_command( $cmd );
ok( ref( $rv ) eq 'App::CELL::Status' );
is( $rv->level, 'ERR' );
is( $rv->code, 'REST_ERROR' );
is( $rv->{'http_status'}, '404 Not Found' );

# EMPLOYEE SET SEC_ID _TERM
$cmd = "EMPLOYEE SET SEC_ID foobar";
$rv = process_command( $cmd );
ok( ref( $rv ) eq 'App::CELL::Status' );
is( $rv->level, 'ERR' );
is( $rv->code, 'REST_ERROR' );
like( $rv->payload, qr/ACL_VIOLATION/ );
is( $rv->{'http_status'}, '403 Forbidden' );

t/cmd_admin/employee.t  view on Meta::CPAN

is( $rv->level, 'OK' );
like( $rv->payload, qr/Nick:\s+worker/ );

note( 'EMPLOYEE_SPEC on non-existent employee' );
$cmd = "EMPLOYEE=99999 PROFILE";
$rv = process_command( $cmd );
ok( ref( $rv ) eq 'App::CELL::Status' );
is( $rv->level, 'ERR' );
is( $rv->code, 'REST_ERROR' );
like( $rv->payload, qr/DISPATCH_SEARCH_EMPTY/ );
is( $rv->{'http_status'}, '404 Not Found' );


#==========================================
# EMPLOYEE LIST
# EMPLOYEE LIST _TERM
#==========================================

note( 'Get list of all employee nicks' );
$cmd = "EMPLOYEE LIST";
$rv = process_command( $cmd );

t/cmd_inactive/employee.t  view on Meta::CPAN

ok( ref( $rv ) eq 'App::CELL::Status' );
is( $rv->level, 'OK' );
like( $rv->payload, qr/Nick:\s+demo/ );

# EMPLOYEE_SPEC on non-existent employee => 403
$cmd = "EMPLOYEE=999999 PROFILE";
$rv = process_command( $cmd );
ok( ref( $rv ) eq 'App::CELL::Status' );
is( $rv->level, 'ERR' );
is( $rv->code, 'REST_ERROR' );
is( $rv->{'http_status'}, '404 Not Found' );

done_testing;



( run in 2.755 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )