Skip to content

Commit 5ba44bd

Browse files
committed
- Updated test script to use todays date instead of hardcoded date
- Added test to make sure we also add flag entries for deletions - Fixed some typos in export script
1 parent da91d43 commit 5ba44bd

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

Diff for: extensions/BMO/bin/export_bmo_etl.pl

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Bugzilla::Flag;
1919
use Bugzilla::Group;
2020
use Bugzilla::User;
21+
use Bugzilla::Extension::Review::FlagStateActivity;
2122

2223
use HTTP::Headers;
2324
use HTTP::Request;
@@ -93,7 +94,7 @@
9394
process_flags();
9495
process_flag_state_activity();
9596
process_tracking_flags();
96-
proccess_keywords();
97+
process_keywords();
9798
process_see_also();
9899
process_mentors();
99100
process_dependencies();
@@ -382,7 +383,7 @@ sub process_flag_state_activity {
382383
};
383384

384385
# Store a new copy of the data for use later
385-
store_cache($obj->id, $table_name, $obj->modification_date, $data);
386+
store_cache($obj->id, $table_name, $obj->flag_when, $data);
386387
}
387388

388389
push @flags, $data;
@@ -441,7 +442,7 @@ sub process_tracking_flags {
441442
}
442443
}
443444

444-
sub proccess_keywords {
445+
sub process_keywords {
445446
my $table_name = 'keywords';
446447
my $rows = $dbh->selectall_arrayref(
447448
'SELECT bug_id, keyworddefs.name AS name

Diff for: extensions/BMO/t/bmo/bmo_etl.t

+33-16
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ BEGIN {
1919
}
2020

2121
use Capture::Tiny qw(capture);
22-
use QA::Util qw(get_config);
23-
use MIME::Base64 qw(encode_base64 decode_base64);
24-
use Mojo::JSON qw(false);
22+
use DateTime;
23+
use QA::Util qw(get_config);
24+
use MIME::Base64 qw(encode_base64 decode_base64);
25+
use Mojo::JSON qw(false);
2526
use Test::Mojo;
2627
use Test::More;
2728

@@ -30,6 +31,7 @@ my $admin_login = $config->{admin_user_login};
3031
my $admin_api_key = $config->{admin_user_api_key};
3132
my $editbugs_api_key = $config->{editbugs_user_api_key};
3233
my $url = Bugzilla->localconfig->urlbase;
34+
my $snapshot_date = DateTime->now()->strftime('%Y-%m-%d');
3335

3436
my $t = Test::Mojo->new();
3537

@@ -60,9 +62,13 @@ $t->post_ok($url
6062
my $bug_id_1 = $t->tx->res->json->{id};
6163

6264
# Clear the needinfo which will add an X entry in flag_state_activity
65+
my $needinfo_update = {
66+
comment => {body => 'This is my comment'},
67+
flags => [{name => 'needinfo', status => 'X'}],
68+
};
6369
$t->put_ok($url
6470
. "rest/bug/$bug_id_1" => {'X-Bugzilla-API-Key' => $editbugs_api_key} =>
65-
json => {comment => {body => 'This is my comment'}})->status_is(200);
71+
json => $needinfo_update)->status_is(200);
6672

6773
### Section 2: Create a new dependent bug
6874

@@ -114,19 +120,19 @@ my ($attach_id) = keys %{$t->tx->res->json->{attachments}};
114120

115121
my @cmd = (
116122
'./extensions/BMO/bin/export_bmo_etl.pl',
117-
'--verbose', '--test', '--snapshot-date', '2000-01-01'
123+
'--verbose', '--test', '--snapshot-date', $snapshot_date,
118124
);
119125

120126
my ($output, $error, $rv) = capture { system @cmd; };
121127
ok(!$rv, 'Data exported to test files without error');
122-
ok(glob(bz_locations()->{'datadir'} . '/2000-01-01-bugs-*.json'),
128+
ok(glob(bz_locations()->{'datadir'} . '/' . $snapshot_date . '-bugs-*.json'),
123129
'Export test files exist');
124130

125131
### Section 5: Export data to BigQuery test instance
126132

127133
@cmd = (
128-
'./extensions/BMO/bin/export_bmo_etl.pl', '--verbose',
129-
'--snapshot-date', '2000-01-01'
134+
'./extensions/BMO/bin/export_bmo_etl.pl',
135+
'--verbose', '--snapshot-date', $snapshot_date,
130136
);
131137

132138
($output, $error, $rv) = capture { system @cmd; };
@@ -135,7 +141,10 @@ ok(!$rv, 'Data exported to BigQuery test instance without error');
135141
### Section 6: Retrieve data from BigQuery instance and verify
136142

137143
my $query = {
138-
query => 'SELECT summary FROM test.bugzilla.bugs WHERE id = ' . $bug_id_1 . ';',
144+
query => 'SELECT summary FROM test.bugzilla.bugs WHERE id = '
145+
. $bug_id_1
146+
. ' AND snapshot_date = \''
147+
. $snapshot_date . '\';',
139148
useLegacySql => false
140149
};
141150
$t->post_ok(
@@ -144,7 +153,9 @@ $t->post_ok(
144153

145154
$query = {
146155
query => 'SELECT description FROM test.bugzilla.attachments WHERE id = '
147-
. $attach_id . ';',
156+
. $attach_id
157+
. ' AND snapshot_date = \''
158+
. $snapshot_date . '\';',
148159
useLegacySql => false
149160
};
150161
$t->post_ok(
@@ -154,7 +165,9 @@ $t->post_ok(
154165
$query = {
155166
query =>
156167
'SELECT depends_on_id FROM test.bugzilla.bug_dependencies WHERE bug_id = '
157-
. $bug_id_2 . ';',
168+
. $bug_id_2
169+
. ' AND snapshot_date = \''
170+
. $snapshot_date . '\';',
158171
useLegacySql => false
159172
};
160173
$t->post_ok(
@@ -163,7 +176,9 @@ $t->post_ok(
163176

164177
$query = {
165178
query => 'SELECT bug_id FROM test.bugzilla.flags WHERE bug_id = '
166-
. $bug_id_1 . " AND name = 'needinfo';",
179+
. $bug_id_1
180+
. ' AND name = \'needinfo\' AND value = \'X\' AND snapshot_date = \''
181+
. $snapshot_date . '\'',
167182
useLegacySql => false
168183
};
169184
$t->post_ok(
@@ -173,8 +188,10 @@ $t->post_ok(
173188
$query = {
174189
query => 'SELECT bug_id FROM test.bugzilla.flags WHERE bug_id = '
175190
. $bug_id_1
176-
. " AND name = 'review' AND attachment_id = "
177-
. $attach_id . ';',
191+
. ' AND name = \'review\' AND attachment_id = '
192+
. $attach_id
193+
. ' AND snapshot_date = \''
194+
. $snapshot_date . '\';',
178195
useLegacySql => false
179196
};
180197

@@ -185,8 +202,8 @@ $t->post_ok(
185202
### Section 7: Exporting again on the same day (with the same snapshot date) will cause the script to exit
186203

187204
@cmd = (
188-
'./extensions/BMO/bin/export_bmo_etl.pl', '--verbose',
189-
'--snapshot-date', '2000-01-01',
205+
'./extensions/BMO/bin/export_bmo_etl.pl',
206+
'--verbose', '--snapshot-date', $snapshot_date,
190207
);
191208

192209
($output, $error, $rv) = capture { system @cmd; };

0 commit comments

Comments
 (0)