[Bps-public-commit] r15579 - in sd/branches/sd-trunk: lib/App/SD/Replica/rt t

jesse at bestpractical.com jesse at bestpractical.com
Wed Aug 27 21:25:35 EDT 2008


Author: jesse
Date: Wed Aug 27 21:25:24 2008
New Revision: 15579

Added:
   sd/branches/sd-trunk/t/no-foreign-sync.t
Modified:
   sd/branches/sd-trunk/   (props changed)
   sd/branches/sd-trunk/lib/App/SD/Replica/rt/PullEncoder.pm
   sd/branches/sd-trunk/t/sd-rt-hm.t
   sd/branches/sd-trunk/t/sd-rt-permission.t
   sd/branches/sd-trunk/t/sd-rt.t

Log:
 r44650 at 192:  jesse | 2008-08-27 18:19:00 -0700
  r44639 at 192 (orig r15562):  sartak | 2008-08-27 12:10:34 -0700
   r70601 at onn:  sartak | 2008-08-27 15:10:21 -0400
   some reindentation for clarity
  
  r44640 at 192 (orig r15563):  sartak | 2008-08-27 12:46:29 -0700
   r70603 at onn:  sartak | 2008-08-27 15:46:14 -0400
   A failing test for pushing a ticket when we have no write right
  
  r44641 at 192 (orig r15564):  sartak | 2008-08-27 13:42:23 -0700
   r70605 at onn:  sartak | 2008-08-27 16:42:17 -0400
   Failing tests to confirm that Prophet does screw up when merging to a foreign replica fails :(
  
  r44642 at 192 (orig r15565):  sartak | 2008-08-27 14:47:25 -0700
   r70607 at onn:  sartak | 2008-08-27 17:47:18 -0400
   Disappearing ticket tests
  
  r44643 at 192 (orig r15566):  sartak | 2008-08-27 16:35:26 -0700
   r70609 at onn:  sartak | 2008-08-27 19:35:19 -0400
   Add tests for the no-foreign-sync CF/tag
  
  r44644 at 192 (orig r15567):  sartak | 2008-08-27 16:48:16 -0700
   r70611 at onn:  sartak | 2008-08-27 19:48:10 -0400
   Failing test for pushing a ticket to RT (??)
  
  r44645 at 192 (orig r15568):  sartak | 2008-08-27 16:55:38 -0700
   r70613 at onn:  sartak | 2008-08-27 19:55:33 -0400
   Case fix, doesn't change the test outcome though
  
 


Modified: sd/branches/sd-trunk/lib/App/SD/Replica/rt/PullEncoder.pm
==============================================================================
--- sd/branches/sd-trunk/lib/App/SD/Replica/rt/PullEncoder.pm	(original)
+++ sd/branches/sd-trunk/lib/App/SD/Replica/rt/PullEncoder.pm	Wed Aug 27 21:25:24 2008
@@ -25,8 +25,7 @@
     my $tickets = {};
     my @transactions;
 
-    $self->sync_source->log( "Finding tickets matching " . $args{'query'} );
-    my @tickets = $self->find_matching_tickets( $args{'query'} );
+    my @tickets =  $self->find_matching_tickets( $args{'query'} );
 
     $self->sync_source->log("No tickets found.") if @tickets == 0;
 
@@ -42,34 +41,30 @@
         $self->sync_source->log(
             "Fetching ticket $id - $counter of " . scalar @tickets );
         $tickets->{$id}->{ticket} = $self->_translate_final_ticket_state(
-            $self->sync_source->rt->show( type => 'ticket', id => $id ) );
-        push @transactions,
-            @{
+            $self->sync_source->rt->show( type => 'ticket', id => $id )
+        );
+        push @transactions, @{
             $self->find_matching_transactions(
                 ticket               => $id,
                 starting_transaction => $first_rev
             )
-            };
+        };
     }
+
     my $txn_counter = 0;
     my @changesets;
     for my $txn ( sort { $b->{'id'} <=> $a->{'id'} } @transactions ) {
         $txn_counter++;
-        $self->sync_source->log(
-            "Transcoding transaction  @{[$txn->{'id'}]} - $txn_counter of "
-                . scalar @transactions );
-        my $changeset = $self->transcode_one_txn( $txn,
-            $tickets->{ $txn->{Ticket} }->{ticket} );
+        $self->sync_source->log("Transcoding transaction  @{[$txn->{'id'}]} - $txn_counter of ". scalar @transactions);
+        my $changeset = $self->transcode_one_txn( $txn, $tickets->{ $txn->{Ticket} }->{ticket} );
         next unless $changeset->has_changes;
         unshift @changesets, $changeset;
     }
 
-    my $cs_counter = 0 ;
-    for (@changesets) {
-        $self->sync_source->log( "Applying changeset "
-                . ++$cs_counter . " of "
-                . scalar @changesets );
-        $args{callback}->($_);
+    my $cs_counter = 0;
+    for ( @changesets ) {
+        $self->sync_source->log("Applying changeset ".++$cs_counter . " of ".scalar @changesets); 
+        $args{callback}->($_)
     }
 
 }

Added: sd/branches/sd-trunk/t/no-foreign-sync.t
==============================================================================
--- (empty file)
+++ sd/branches/sd-trunk/t/no-foreign-sync.t	Wed Aug 27 21:25:24 2008
@@ -0,0 +1,189 @@
+#!/usr/bin/env perl
+
+# to run:
+#
+# RT_DBA_USER=root RT_DBA_PASSWORD= prove -lv -I/Users/clkao/work/bps/rt-3.7/lib t/sd-rt.t
+use strict;
+use warnings;
+no warnings 'once';
+
+# setup for rt
+use Prophet::Test;
+use App::SD::Test;
+
+BEGIN {
+    unless (eval 'use RT::Test (); 1') {
+        diag $@;
+        plan skip_all => 'requires 3.7 to run tests.';
+    }
+}
+
+BEGIN {
+    unless ( $ENV{'JIFTY_APP_ROOT'} ) {
+        plan skip_all => "You must define a JIFTY_APP_ROOT environment variable which points to your hiveminder source tree";
+    }
+    require File::Temp;
+    eval "use Jifty;";
+    push @INC, File::Spec->catdir( Jifty::Util->app_root, "lib" );
+}
+
+plan tests => 11;
+
+RT::Test->import;
+use RT::Client::REST;
+use RT::Client::REST::Ticket;
+
+RT::Handle->InsertData( $RT::EtcPath . '/initialdata' );
+
+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";
+
+ok( 1, "Loaded the test script" );
+
+my ( $url, $m ) = RT::Test->started_ok;
+diag("RT server started at $url");
+
+my $CF = RT::Test->load_or_create_custom_field(
+    Name  => 'sd:no-foreign-sync',
+    Queue => 'General',
+    Type  => 'SelectSingle',
+);
+$CF->AddValue(
+    Name        => 'ForbidForeignSync',
+    Description => 'Using this flag will forbid syncing the ticket to other foreign replicas',
+);
+$CF->AddValue(
+    Name        => 'AllowForeignSync',
+    Description => 'Using this flag will allow syncing the ticket to other foreign replicas',
+);
+
+my $rt = RT::Client::REST->new( server => $url );
+$rt->login( username => 'root', password => 'password' );
+
+$url =~ s|http://|http://root:password@|;
+my $sd_rt_url = "rt:$url|General|Status!='resolved'";
+
+my $ticket = RT::Client::REST::Ticket->new(
+    rt      => $rt,
+    queue   => 'General',
+    status  => 'new',
+    subject => 'Fly Man',
+    cf      => {
+        'sd:no-foreign-sync' => 'ForbidForeignSync',
+    },
+)->store( text => "Ticket Comment" );
+
+# setup for hm
+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 );
+my $GOODUSER = BTDT::CurrentUser->new( email => 'onlooker at example.com' );
+$GOODUSER->user_object->set_accepted_eula_version( Jifty->config->app('EULAVersion') );
+my $task = BTDT::Model::Task->new( current_user => $GOODUSER );
+$task->create(
+    summary     => "YATTA",
+    description => '',
+    tags        => 'sd:no-foreign-sync',
+);
+
+my ( $bob_yatta_id, $bob_flyman_id, $flyman_uuid, $yatta_uuid, $alice_yatta_id, $alice_flyman_id );
+my ( $ret, $out, $err );
+
+# now the tests, bob syncs with rt, alice syncs with hm
+as_alice {
+    local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_hm_url ] );
+    diag($err) if ($err);
+    run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [qr/^(.*?)(?{ $alice_yatta_id = $1 }) YATTA .*/] );
+    $yatta_uuid = get_uuid_for_luid($alice_yatta_id);
+};
+
+as_bob {
+    local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
+    run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [] );
+
+    diag("Bob pulling from RT");
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', $sd_rt_url ] );
+    diag($err) if ($err);
+    run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ], [qr/^(.*?)(?{ $bob_flyman_id = $1 }) Fly Man new/] );
+
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', repo_uri_for('alice'), '--force' ] );
+
+    $flyman_uuid = get_uuid_for_luid($bob_flyman_id);
+    my $bob_yatta_id = get_luid_for_uuid($yatta_uuid);
+
+    run_output_matches_unordered(
+        'sd',
+        [ 'ticket',                             'list', '--regex', '.' ],
+        [ reverse sort "$bob_yatta_id YATTA (no status)", "$bob_flyman_id Fly Man new" ]
+    );
+
+
+    diag("Bob pushing to RT");
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] );
+    diag($err) if ($err);
+};
+
+as_alice {
+    local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'pull', '--from', repo_uri_for('bob'), '--force' ] );
+
+
+    $alice_flyman_id = get_luid_for_uuid($flyman_uuid);
+
+    run_output_matches_unordered(
+        'sd',
+        [ 'ticket',                             'list', '--regex', '.' ],
+        [ sort "$alice_yatta_id YATTA (no status)", "$alice_flyman_id Fly Man new" ]
+    );
+};
+
+# try pushing Fly Man to Hiveminder
+as_bob {
+    local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
+
+    diag("Bob pushing to Hiveminder");
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_hm_url ] );
+    diag($err) if ($err);
+};
+
+as_alice {
+    local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
+
+    diag("Alice pushing to Hiveminder");
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_hm_url ] );
+    diag($err) if ($err);
+};
+
+ok(!$task->load_by_cols(summary => "Fly Man"), "no 'Fly Man' ticket on HM because RT had the no-foreign-sync custom field");
+
+# try pushing YATTA to RT
+as_bob {
+    local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
+
+    diag("Bob pushing to RT");
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] );
+    diag($err) if ($err);
+};
+
+as_alice {
+    local $ENV{SD_REPO} = $ENV{'PROPHET_REPO'};
+
+    diag("Alice pushing to RT");
+    ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] );
+    diag($err) if ($err);
+};
+
+my @ids = $rt->search(
+    type => 'ticket',
+    query => "Subject LIKE 'YATTA'",
+);
+is(@ids, 0, "no YATTA ticket (from HM) in RT");
+

Modified: sd/branches/sd-trunk/t/sd-rt-hm.t
==============================================================================
--- sd/branches/sd-trunk/t/sd-rt-hm.t	(original)
+++ sd/branches/sd-trunk/t/sd-rt-hm.t	Wed Aug 27 21:25:24 2008
@@ -25,7 +25,7 @@
     push @INC, File::Spec->catdir( Jifty::Util->app_root, "lib" );
 }
 
-plan tests => 10;
+plan tests => 11;
 
 RT::Test->import();
 
@@ -112,7 +112,11 @@
     ( $ret, $out, $err ) = run_script( 'sd', [ 'push', '--to', $sd_rt_url ] );
     diag($err) if ($err);
 
-    # XXX: to check YATTA ticket created in RT.
+    my @ids = $rt->search(
+        type => 'ticket',
+        query => "Subject LIKE 'YATTA'",
+    );
+    is(@ids, 1, "pushed YATTA ticket to RT");
 };
 
 as_alice {

Modified: sd/branches/sd-trunk/t/sd-rt-permission.t
==============================================================================
--- sd/branches/sd-trunk/t/sd-rt-permission.t	(original)
+++ sd/branches/sd-trunk/t/sd-rt-permission.t	Wed Aug 27 21:25:24 2008
@@ -6,9 +6,6 @@
 use warnings;
 no warnings 'once';
 
-# create a ticket as root, then try to pull it as someone who doesn't have the
-# rights to see it
-
 use Test::More;
 
 BEGIN {
@@ -24,29 +21,38 @@
     diag "export SD_REPO=".$ENV{'PROPHET_REPO'} ."\n";
 }
 
-use Prophet::Test tests => 2;
+use Prophet::Test tests => 22;
 use App::SD::Test;
 use RT::Client::REST;
 use RT::Client::REST::Ticket;
 
 RT::Handle->InsertData( $RT::EtcPath . '/initialdata' );
 
+my ($ret, $out, $err);
 my ( $url, $m ) = RT::Test->started_ok;
 
-my $user = RT::Test->load_or_create_user(
+my $alice = RT::Test->load_or_create_user(
     Name     => 'alice',
     Password => 'AlicesPassword',
 );
 
+my $refuge = RT::Test->load_or_create_queue(
+    Name => 'Ticket Refuge',
+);
+
 my $root = RT::Client::REST->new( server => $url );
 $root->login( username => 'root', password => 'password' );
 
+diag("create a ticket as root, then try to pull it as someone who doesn't have the rights to see it");
+
 my $ticket = RT::Client::REST::Ticket->new(
-    rt      => $root,
-    queue   => 'General',
-    status  => 'new',
-    subject => 'Fly Man',
-)->store( text => "Ticket Comment" );
+    rt       => $root,
+    queue    => 'General',
+    status   => 'new',
+    subject  => 'Fly Man',
+    priority => 10,
+)->store(text => "Ticket Comment");
+my $ticket_id = $ticket->id;
 
 my $root_url = $url;
 $root_url =~ s|http://|http://root:password@|;
@@ -57,11 +63,117 @@
 my $sd_alice_url = "rt:$alice_url|General|Status!='resolved'";
 
 as_alice {
-    run_output_matches( 'sd', [ 'pull', '--from',  $sd_alice_url ],
-        [
-            qr/^Pulling from rt:/,
-            "No new changesets.",
-        ],
+    ($ret, $out, $err) = run_script('sd', ['pull', '--from',  $sd_alice_url]);
+    ok($ret);
+    like($out, qr/No new changesets/);
+
+    TODO: {
+        local $TODO = "not coming through for some reason";
+        like($err, qr/No tickets found/);
+    }
+};
+
+diag("grant read rights, ensure we can pull it");
+
+my $queue = RT::Queue->new($RT::SystemUser);
+$queue->Load('General');
+
+$alice->PrincipalObj->GrantRight(Right => 'SeeQueue',   Object => $queue);
+$alice->PrincipalObj->GrantRight(Right => 'ShowTicket', Object => $queue);
+
+my $flyman_id;
+as_alice {
+    ($ret, $out, $err) = run_script('sd', ['pull', '--from',  $sd_alice_url]);
+    ok($ret);
+    like($out, qr/Merged one changeset/);
+
+    run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ],
+        [qr/(.*?)(?{ $flyman_id = $1 }) Fly Man new/] );
+};
+
+diag("without write rights, ensure that trying to push it gives a sane error");
+
+as_alice {
+    run_output_matches('sd', ['ticket', 'update', $flyman_id, '--', 'priority=20'],
+        [qr/ticket .*$flyman_id.* updated/],
     );
+
+    ($ret, $out, $err) = run_script('sd', ['push', '--to',  $sd_alice_url]);
+    ok($ret);
+    like($err, qr/You are not allowed to modify ticket $ticket_id/);
+
+    TODO: {
+        local $TODO = "we report success even though it failed";
+        unlike($out, qr/Merged one changeset/);
+    }
 };
 
+$ticket = RT::Client::REST::Ticket->new(
+    rt      => $root,
+    id      => $ticket_id,
+)->retrieve;
+
+is($ticket->priority, 10, "ticket not updated");
+
+diag("give write rights, try to push again");
+
+$alice->PrincipalObj->GrantRight(Right => 'ModifyTicket', Object => $queue);
+
+as_alice {
+    ($ret, $out, $err) = run_script('sd', ['push', '--to',  $sd_alice_url]);
+    ok($ret);
+    TODO: {
+        local $TODO = "Prophet thinks it already merged this changeset!";
+        like($out, qr/Merged one changeset/);
+    }
+};
+
+$ticket = RT::Client::REST::Ticket->new(
+    rt      => $root,
+    id      => $ticket_id,
+)->retrieve;
+
+TODO: {
+    local $TODO = "ticket is NOT updated!";
+    is($ticket->priority, 20, "ticket updated");
+}
+
+diag("move the ticket, ensure it doesn't just disappear");
+$ticket = RT::Client::REST::Ticket->new(
+    rt       => $root,
+    id       => $ticket_id,
+    queue    => $refuge->Id,
+    status   => 'stalled',
+)->store;
+
+as_alice {
+    ($ret, $out, $err) = run_script('sd', ['pull', '--from',  $sd_alice_url]);
+    ok($ret);
+    like($out, qr/No new changesets/);
+
+    run_output_matches( 'sd', [ 'ticket', 'list', '--regex', '.' ],
+        [qr/Fly Man new/] );
+};
+
+diag("update the moved ticket");
+$alice->PrincipalObj->GrantRight(Right => 'ModifyTicket', Object => $refuge);
+$alice->PrincipalObj->GrantRight(Right => 'SeeQueue',     Object => $refuge);
+$alice->PrincipalObj->GrantRight(Right => 'ShowTicket',   Object => $refuge);
+
+as_alice {
+    run_output_matches('sd', ['ticket', 'resolve', $flyman_id],
+        [qr/ticket .*$flyman_id.* updated/],
+    );
+
+    ($ret, $out, $err) = run_script('sd', ['push', '--to',  $sd_alice_url]);
+    ok($ret);
+    like($out, qr/Merged one changeset/, "pushed the 'resolve' changeset");
+};
+
+$ticket = RT::Client::REST::Ticket->new(
+    rt       => $root,
+    id       => $ticket_id,
+)->retrieve;
+
+is($ticket->status, 'resolved', "ticket is updated");
+

Modified: sd/branches/sd-trunk/t/sd-rt.t
==============================================================================
--- sd/branches/sd-trunk/t/sd-rt.t	(original)
+++ sd/branches/sd-trunk/t/sd-rt.t	Wed Aug 27 21:25:24 2008
@@ -257,8 +257,8 @@
     my @attachments;
     while (my $att = &$iterator) { 
         if ( $att->file_name ) {
-        push @attachments, $att ;
-    }
+            push @attachments, $att ;
+        }
     }
     return @attachments
 }



More information about the Bps-public-commit mailing list