diff options
Diffstat (limited to 'perllib/FixMyStreet/TestMech.pm')
-rw-r--r-- | perllib/FixMyStreet/TestMech.pm | 56 |
1 files changed, 43 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm index 7f81c0fc2..be8f004a5 100644 --- a/perllib/FixMyStreet/TestMech.pm +++ b/perllib/FixMyStreet/TestMech.pm @@ -87,8 +87,8 @@ sub log_in_ok { my $user = $mech->create_user_ok($email); - # store the old password and then change it - my $old_password = $user->password; + # remember the old password and then change it to a known one + my $old_password = $user->password || ''; $user->update( { password => 'secret' } ); # log in @@ -99,7 +99,19 @@ sub log_in_ok { $mech->logged_in_ok; # restore the password (if there was one) - $user->update( { password => $old_password } ) if $old_password; + if ($old_password) { + + # Use store_column and then make_column_dirty to bypass the filters that + # would hash the password, otherwise the password required ito log in + # would be the hash of the previous one. + $user->store_column("password", $old_password); + $user->make_column_dirty("password"); + $user->update(); + + # Belt and braces, check that the password has been correctly saved. + die "password not correctly restored after log_in_ok" + if $user->password ne $old_password; + } return $user; } @@ -243,7 +255,7 @@ sub import_errors { my @errors = # grep { $_ } # map { s{^ERROR:\s*(.*)$}{$1}g ? $_ : undef; } # - split m/\n+/, $mech->response->content; + split m/\n+/, $mech->content; return \@errors; } @@ -296,7 +308,7 @@ sub extract_location { $meta = $mech->extract_problem_meta; -Returns the problem meta information ( submitted by, at etc ) from a +Returns the problem meta information ( submitted by, at etc ) from a problem report page =cut @@ -519,11 +531,11 @@ sub get_ok_json { return decode_json( $res->content ); } -sub delete_problems_for_council { +sub delete_problems_for_body { my $mech = shift; - my $council = shift; + my $body = shift; - my $reports = FixMyStreet::App->model('DB::Problem')->search( { council => $council } ); + my $reports = FixMyStreet::App->model('DB::Problem')->search( { bodies_str => $body } ); if ( $reports ) { for my $r ( $reports->all ) { $r->comments->delete; @@ -532,8 +544,26 @@ sub delete_problems_for_council { } } -sub create_problems_for_council { - my ( $mech, $count, $council, $title, $params ) = @_; +sub create_body_ok { + my $self = shift; + my ( $id, $name ) = @_; + + my $params = { id => $id, name => $name }; + my $body = FixMyStreet::App->model('DB::Body')->find_or_create($params); + $body->update($params); # Make sure + ok $body, "found/created user for $id $name"; + + FixMyStreet::App->model('DB::BodyArea')->find_or_create({ + area_id => $id, + body_id => $id, + }); + + return $body; + +} + +sub create_problems_for_body { + my ( $mech, $count, $body, $title, $params ) = @_; my $dt = $params->{dt} || DateTime->now(); @@ -549,11 +579,11 @@ sub create_problems_for_council { while ($count) { my $default_params = { postcode => 'SW1A 1AA', - council => $council, + bodies_str => $body, areas => ',105255,11806,11828,2247,2504,', category => 'Other', - title => "$title Test $count for $council", - detail => "$title Test $count for $council Detail", + title => "$title Test $count for $body", + detail => "$title Test $count for $body Detail", used_map => 't', name => 'Test User', anonymous => 'f', |