diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-08-26 07:55:24 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-08-26 07:55:24 +0200 |
commit | 9263f397e701f25af395e8cdee48c87ee3327157 (patch) | |
tree | cc7f6b6beef8947090a108701ca34316a5c8edb8 /t | |
parent | 23b94e8410d90e9e15584d3a9220b6bb214f4220 (diff) | |
parent | d57aefa118802606ea7cc424aaa62173be9eec41 (diff) | |
download | bugzilla-9263f397e701f25af395e8cdee48c87ee3327157.tar.gz bugzilla-9263f397e701f25af395e8cdee48c87ee3327157.tar.xz |
Merge remote-tracking branch 'bmo/mojo'
Diffstat (limited to 't')
-rw-r--r-- | t/mock-db.t | 45 | ||||
-rw-r--r-- | t/mock-params.t | 25 | ||||
-rw-r--r-- | t/phabbugz.t | 243 | ||||
-rw-r--r-- | t/sqlite-memory.t | 89 |
4 files changed, 159 insertions, 243 deletions
diff --git a/t/mock-db.t b/t/mock-db.t new file mode 100644 index 000000000..54ceef100 --- /dev/null +++ b/t/mock-db.t @@ -0,0 +1,45 @@ +#!/usr/bin/perl +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +use 5.10.1; +use strict; +use warnings; +use lib qw( . lib local/lib/perl5 ); +use Test::More; +use Try::Tiny; + +use ok 'Bugzilla::Test::MockDB'; +use ok 'Bugzilla::Test::Util', qw(create_user); + +try { + Bugzilla::Test::MockDB->import(); + pass('made fake in-memory db'); +} +catch { + diag $_; + fail('made fake in-memory db'); +}; + +try { + create_user('bob@pants.gov', '*'); + ok( Bugzilla::User->new({name => 'bob@pants.gov'})->id, 'create a user' ); +} +catch { + fail('create a user'); +}; + +try { + my $rob = create_user('rob@pants.gov', '*'); + Bugzilla::User->check({id => $rob->id}); + pass('rob@pants.gov checks out'); +} +catch { + diag $_; + fail('rob@pants.gov fails'); +}; + +done_testing; diff --git a/t/mock-params.t b/t/mock-params.t new file mode 100644 index 000000000..7c2318130 --- /dev/null +++ b/t/mock-params.t @@ -0,0 +1,25 @@ +#!/usr/bin/perl +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +use 5.10.1; +use strict; +use warnings; +use lib qw( . lib local/lib/perl5 ); +use Test::More; +use Test2::Tools::Mock qw(mock); +use Bugzilla::Test::MockParams ( + phabricator_auth_callback_url => 'http://pants.gov/', +); + +is(Bugzilla->params->{phabricator_auth_callback_url}, 'http://pants.gov/', 'import default params'); + +Bugzilla::Test::MockParams->import(phabricator_api_key => 'FAKE-KEY'); + +is(Bugzilla->params->{phabricator_api_key}, 'FAKE-KEY', 'set key'); + + +done_testing; diff --git a/t/phabbugz.t b/t/phabbugz.t deleted file mode 100644 index ba2f35e1d..000000000 --- a/t/phabbugz.t +++ /dev/null @@ -1,243 +0,0 @@ -#!/usr/bin/perl -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -# This Source Code Form is "Incompatible With Secondary Licenses", as -# defined by the Mozilla Public License, v. 2.0. -use strict; -use warnings; -use 5.10.1; -use lib qw( . lib local/lib/perl5 ); -use Bugzilla; - -BEGIN { Bugzilla->extensions }; - -use Test::More; -use Test2::Tools::Mock; -use Data::Dumper; -use JSON::MaybeXS; -use Carp; -use Try::Tiny; - -use ok 'Bugzilla::Extension::PhabBugz::Feed'; -use ok 'Bugzilla::Extension::PhabBugz::Util', qw( get_attachment_revisions ); -can_ok('Bugzilla::Extension::PhabBugz::Feed', 'group_query'); - -our @group_members; -our @project_members; - - -my $User = mock 'Bugzilla::Extension::PhabBugz::User' => ( - add_constructor => [ - 'fake_new' => 'hash', - ], - override => [ - 'match' => sub { [ mock() ] }, - ], -); - -my $Feed = mock 'Bugzilla::Extension::PhabBugz::Feed' => ( - override => [ - get_group_members => sub { - return [ map { Bugzilla::Extension::PhabBugz::User->fake_new(%$_) } @group_members ]; - } - ] -); - -my $Project = mock 'Bugzilla::Extension::PhabBugz::Project' => ( - override_constructor => [ - new_from_query => 'ref_copy', - ], - override => [ - 'members' => sub { - return [ map { Bugzilla::Extension::PhabBugz::User->fake_new(%$_) } @project_members ]; - } - ] -); - -local Bugzilla->params->{phabricator_enabled} = 1; -local Bugzilla->params->{phabricator_api_key} = 'FAKE-API-KEY'; -local Bugzilla->params->{phabricator_base_uri} = 'http://fake.fabricator.tld'; - -my $Bugzilla = mock 'Bugzilla' => ( - override => [ - 'dbh' => sub { mock() }, - 'user' => sub { Bugzilla::User->new({ name => 'phab-bot@bmo.tld' }) }, - ], -); - -my $BugzillaGroup = mock 'Bugzilla::Group' => ( - add_constructor => [ - 'fake_new' => 'hash', - ], - override => [ - 'match' => sub { [ Bugzilla::Group->fake_new(id => 1, name => 'firefox-security' ) ] }, - ], -); - -my $BugzillaUser = mock 'Bugzilla::User' => ( - add_constructor => [ - 'fake_new' => 'hash', - ], - override => [ - 'new' => sub { - my ($class, $hash) = @_; - if ($hash->{name} eq 'phab-bot@bmo.tld') { - return $class->fake_new( id => 8_675_309, login_name => 'phab-bot@bmo.tld', realname => 'Fake PhabBot' ); - } - else { - } - }, - 'match' => sub { [ mock() ] }, - ], -); - - -my $feed = Bugzilla::Extension::PhabBugz::Feed->new; - -# Same members in both -do { - my $UserAgent = mock 'LWP::UserAgent' => ( - override => [ - 'post' => sub { - my ($self, $url, $params) = @_; - my $data = decode_json($params->{params}); - is_deeply($data->{transactions}, [], 'no-op'); - return mock({is_error => 0, content => '{}'}); - }, - ], - ); - local @group_members = ( - { phid => 'foo' }, - ); - local @project_members = ( - { phid => 'foo' }, - ); - $feed->group_query; -}; - -# Project has members not in group -do { - my $UserAgent = mock 'LWP::UserAgent' => ( - override => [ - 'post' => sub { - my ($self, $url, $params) = @_; - my $data = decode_json($params->{params}); - my $expected = [ { type => 'members.remove', value => ['foo'] } ]; - is_deeply($data->{transactions}, $expected, 'remove foo'); - return mock({is_error => 0, content => '{}'}); - }, - ] - ); - local @group_members = (); - local @project_members = ( - { phid => 'foo' }, - ); - $feed->group_query; -}; - -# Group has members not in project -do { - my $UserAgent = mock 'LWP::UserAgent' => ( - override => [ - 'post' => sub { - my ($self, $url, $params) = @_; - my $data = decode_json($params->{params}); - my $expected = [ { type => 'members.add', value => ['foo'] } ]; - is_deeply($data->{transactions}, $expected, 'add foo'); - return mock({is_error => 0, content => '{}'}); - }, - ] - ); - local @group_members = ( - { phid => 'foo' }, - ); - local @project_members = ( - ); - $feed->group_query; -}; - -do { - my $Revision = mock 'Bugzilla::Extension::PhabBugz::Revision' => ( - override => [ - 'update' => sub { 1 }, - ], - ); - my $UserAgent = mock 'LWP::UserAgent' => ( - override => [ - 'post' => sub { - my ($self, $url, $params) = @_; - if ($url =~ /differential\.revision\.search/) { - my $content = <<JSON; -{ - "error_info": null, - "error_code": null, - "result": { - "data": [ - { - "id": 9999, - "type": "DREV", - "phid": "PHID-DREV-uozm3ggfp7e7uoqegmc3", - "fields": { - "title": "Added .arcconfig", - "summary": "Added .arcconfig", - "authorPHID": "PHID-USER-4wigy3sh5fc5t74vapwm", - "dateCreated": 1507666113, - "dateModified": 1508514027, - "policy": { - "view": "public", - "edit": "admin" - }, - "bugzilla.bug-id": "23", - "status": { - "value": "needs-review", - "name": "Needs Review", - "closed": false, - "color.ansi": "magenta" - } - }, - "attachments": { - "reviewers": { - "reviewers": [] - }, - "subscribers": { - "subscriberPHIDs": [], - "subscriberCount": 0, - "viewerIsSubscribed": true - }, - "projects": { - "projectPHIDs": [] - } - } - } - ] - } -} -JSON - return mock { is_error => 0, content => $content }; - } - else { - return mock { is_error => 1, message => "bad request" }; - } - }, - ], - ); - my $bug = mock { - bug_id => 23, - attachments => [ - mock { - contenttype => 'text/x-phabricator-request', - filename => 'phabricator-D9999-url.txt', - }, - ] - }; - my $revisions = get_attachment_revisions($bug); - is(ref($revisions), 'ARRAY', 'it is an array ref'); - isa_ok($revisions->[0], 'Bugzilla::Extension::PhabBugz::Revision'); - is($revisions->[0]->bug_id, 23, 'Bugzila ID is 23'); - ok( try { $revisions->[0]->update }, 'update revision'); - -}; - -done_testing;
\ No newline at end of file diff --git a/t/sqlite-memory.t b/t/sqlite-memory.t new file mode 100644 index 000000000..66f8e5d29 --- /dev/null +++ b/t/sqlite-memory.t @@ -0,0 +1,89 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. +use 5.10.1; +use strict; +use warnings; +use lib qw( . lib local/lib/perl5 ); +use Test::More; +use Test2::Tools::Mock; +use Try::Tiny; +use Capture::Tiny qw(capture_merged); +use Bugzilla::Test::MockParams; + +BEGIN { + $ENV{LOCALCONFIG_ENV} = 'BMO'; + $ENV{BMO_db_driver} = 'sqlite'; + $ENV{BMO_db_name} = ':memory:'; +}; +use Bugzilla; +BEGIN { Bugzilla->extensions }; + + +isa_ok(Bugzilla->dbh, 'Bugzilla::DB::Sqlite'); + +use ok 'Bugzilla::Install'; +use ok 'Bugzilla::Install::DB'; + +my $lives_ok = sub { + my ($desc, $code) = @_; + my $output; + try { + $output = capture_merged { $code->() }; + pass($desc); + } catch { + diag $_; + fail($desc); + } finally { + diag "OUTPUT: $output" if $output; + }; +}; + +my $output = ''; +$lives_ok->('bz_setup_database' => sub { + Bugzilla->dbh->bz_setup_database +}); + +$lives_ok->('bz_populate_enum_tables' => sub { + # Populate the tables that hold the values for the <select> fields. + Bugzilla->dbh->bz_populate_enum_tables(); +}); + +$lives_ok->('update_fielddefs_definition' => sub { + Bugzilla::Install::DB::update_fielddefs_definition(); +}); + +$lives_ok->('populate_field_definitions' => sub { + Bugzilla::Field::populate_field_definitions(); +}); + +$lives_ok->('init_workflow' => sub { + Bugzilla::Install::init_workflow(); +}); + +$lives_ok->('update_table_definitions' => sub { + Bugzilla::Install::DB->update_table_definitions({}); +}); + +$lives_ok->('update_system_groups' => sub { + Bugzilla::Install::update_system_groups(); +}); + +# "Log In" as the fake superuser who can do everything. +Bugzilla->set_user(Bugzilla::User->super_user); + +$lives_ok->('update_settings' => sub { + Bugzilla::Install::update_settings(); +}); + +SKIP: { + skip 'default product cannot be created without default assignee', 1; + $lives_ok->('create_default_product' => sub { + Bugzilla::Install::create_default_product(); + }); +} + +done_testing; |