[Bps-public-commit] r17115 - sd/trunk/t/sd-hm

ruz at bestpractical.com ruz at bestpractical.com
Fri Dec 5 08:46:12 EST 2008


Author: ruz
Date: Fri Dec  5 08:46:11 2008
New Revision: 17115

Added:
   sd/trunk/t/sd-hm/push-reporter-not-pro.t

Log:
* add tests around requester field

Added: sd/trunk/t/sd-hm/push-reporter-not-pro.t
==============================================================================
--- (empty file)
+++ sd/trunk/t/sd-hm/push-reporter-not-pro.t	Fri Dec  5 08:46:11 2008
@@ -0,0 +1,111 @@
+#!/usr/bin/env perl
+use warnings;
+use strict;
+use Prophet::Test;
+use App::SD::Test;
+
+BEGIN {
+    if ( $ENV{'JIFTY_APP_ROOT'} ) {
+        plan tests => 22;
+        require File::Temp;
+        $ENV{'PROPHET_REPO'} = $ENV{'SD_REPO'} = File::Temp::tempdir( CLEANUP => 0 ) . '/_svb';
+        diag $ENV{'PROPHET_REPO'};
+        eval "use Jifty";
+        push @INC, File::Spec->catdir( Jifty::Util->app_root, "lib" );
+    } else {
+        plan skip_all => "You must define a JIFTY_APP_ROOT environment variable which points to your hiveminder source tree";
+    }
+}
+
+eval 'use BTDT::Test; 1;' or die "$@";
+
+my $server = BTDT::Test->make_server;
+my $URL    = $server->started_ok;
+$URL =~ s|http://|http://onlooker\@example.com:something@|;
+my $sd_hm_url = "hm:$URL";
+
+my $GOODUSER;
+{
+    my $root = BTDT::CurrentUser->superuser;
+    my $as_root = BTDT::Model::User->new( current_user => $root );
+    $as_root->load_by_cols( email => 'onlooker at example.com' );
+    my ( $val, $msg ) = $as_root->set_accepted_eula_version( Jifty->config->app('EULAVersion') );
+    ok( $val, $msg );
+    $GOODUSER = BTDT::CurrentUser->new( email => 'onlooker at example.com' );
+    $GOODUSER->user_object->set_accepted_eula_version( Jifty->config->app('EULAVersion') );
+}
+
+diag($sd_hm_url);
+
+diag("non pro have no right to set requestor");
+{
+    flush_sd();
+    my ($luid, $uuid) = create_ticket_ok(qw(--summary YATTA --status new --reporter test at localhost));
+
+    my ($ret, $out, $err) = run_script( 'sd', ['push', '--to', $sd_hm_url] );
+    diag $out;
+    diag $err;
+
+    my $task = load_new_hm_task();
+    is $task->requestor->email, 'onlooker at example.com', 'correct email';
+
+    my $comments = $task->comments;
+    is( $comments->count, 2, "there are two comments" );
+    my $comment = do { $comments->next; $comments->next->formatted_body };
+    like( $comment, qr/test\@localhost/, "there is comment" );
+}
+
+diag("non pro have no right to change requestor");
+{
+    flush_sd();
+    my ($luid, $uuid) = create_ticket_ok(qw(--summary YATTA --status new --reporter onlooker at example.com));
+    update_ticket_ok($uuid, qw(--reporter test at localhost));
+    my ($ret, $out, $err) = run_script( 'sd', ['push', '--to', $sd_hm_url] );
+    diag $err;
+
+    my $task = load_new_hm_task();
+    is $task->requestor->email, 'onlooker at example.com', 'correct email';
+
+    my $comments = $task->comments;
+    is( $comments->count, 2, "there are two comments" );
+    my $comment = do { $comments->next; $comments->next->formatted_body };
+    like( $comment, qr/test\@localhost/, "there is comment" );
+}
+
+diag("only one requestor");
+{
+    flush_sd();
+    my ($luid, $uuid) = create_ticket_ok(qw(--summary YATTA --status new --reporter onlooker at example.com,test at localhost));
+    my ($ret, $out, $err) = run_script( 'sd', ['push', '--to', $sd_hm_url] );
+
+    like $err, qr/A ticket has more than one requestor when HM supports only one/, 'warning issued';
+
+    my $task = load_new_hm_task();
+    is $task->requestor->email, 'onlooker at example.com', 'correct email';
+
+    my $comments = $task->comments;
+    is( $comments->count, 2, "there are two comments" );
+    my $comment = do { $comments->next; $comments->next->formatted_body };
+    like( $comment, qr/test\@localhost/, "there is comment" );
+}
+
+sub flush_sd {
+    use File::Path qw(rmtree);
+    rmtree( $ENV{'SD_REPO'} );
+    run_script( 'sd', ['init'] );
+}
+
+{ my %seen;
+sub load_new_hm_task {
+    my $tasks = BTDT::Model::TaskCollection->new( current_user => $GOODUSER );
+    $tasks->limit( column => 'summary', value => 'YATTA' );
+    $tasks->order_by( { column => 'id', order => 'desc' } );
+
+    my $res = $tasks->first;
+    my $hm_tid = $res->id;
+    ok $hm_tid, "loaded hm task #$hm_tid";
+    ok !$seen{$hm_tid}++, "not seen #$hm_tid";
+
+    return $res;
+} }
+



More information about the Bps-public-commit mailing list