113
118
# The sample data already contains one submission.
114
119
submissions = loop.getUnprocessedSubmissions(2)
115
120
self.assertEqual([submission2], submissions)
122
def test_run_reprocessing_script_no_params(self):
123
# cronscripts/reprocess-hwdb-submissions.py needs at least the
124
# parameter --start-file
125
retcode, stdout, stderr = run_script(
126
'cronscripts/reprocess-hwdb-submissions.py', [])
128
stderr, Contains('Option --start-file not specified.'))
130
def test_run_reprocessing_script_startfile_does_not_exist(self):
131
# If the specified start file does not exist,
132
# cronscripts/reprocess-hwdb-submissions.py reports an error.
133
does_not_exist = mktemp()
134
retcode, stdout, stderr = run_script(
135
'cronscripts/reprocess-hwdb-submissions.py',
136
['--start-file', does_not_exist])
138
stderr, Contains('Cannot access file %s' % does_not_exist))
140
def test_run_reprocessing_script_startfile_without_integer(self):
141
# If the specified start file contains any non-integer string,
142
# cronscripts/reprocess-hwdb-submissions.py reports an error.
143
start_file_name = mktemp()
144
start_file = open(start_file_name, 'w')
145
start_file.write('nonsense')
147
retcode, stdout, stderr = run_script(
148
'cronscripts/reprocess-hwdb-submissions.py',
149
['--start-file', start_file_name])
152
Contains('%s must contain only an integer' % start_file_name))
154
def test_run_reprocessing_script_startfile_with_negative_integer(self):
155
# If the specified start file contains any non-integer string,
156
# cronscripts/reprocess-hwdb-submissions.py reports an error.
157
start_file_name = mktemp()
158
start_file = open(start_file_name, 'w')
159
start_file.write('-1')
161
retcode, stdout, stderr = run_script(
162
'cronscripts/reprocess-hwdb-submissions.py',
163
['--start-file', start_file_name])
166
Contains('%s must contain a positive integer' % start_file_name))
168
def test_run_reprocessing_script_max_submission_not_integer(self):
169
# If the parameter --max-submissions is not an integer,
170
# cronscripts/reprocess-hwdb-submissions.py reports an error.
171
retcode, stdout, stderr = run_script(
172
'cronscripts/reprocess-hwdb-submissions.py',
173
['--max-submissions', 'nonsense'])
174
expected = "Invalid value for --max_submissions specified: 'nonsense'"
175
self.assertThat(stderr, Contains(expected))
177
def test_run_reprocessing_script_two_batches(self):
178
# cronscripts/reprocess-hwdb-submissions.py begings to process
179
# submissions with IDs starting at the value stored in the
180
# file given as the parameter --start-file. When is has
181
# finished processing the number of submissions specified by
182
# --max-submissions, it stores the ID of the last prcessed
183
# submission in start-file.
185
for count in range(5):
186
new_submissions.append(
187
self.factory.makeHWSubmission(
188
status=HWSubmissionProcessingStatus.INVALID))
190
start_file_name = mktemp()
191
start_file = open(start_file_name, 'w')
192
start_file.write('%i' % new_submissions[1].id)
195
Store.of(new_submissions[0]).invalidate()
197
retcode, stdout, stderr = run_script(
198
'cronscripts/reprocess-hwdb-submissions.py',
199
['--max-submissions', '2', '--start-file', start_file_name])
201
# We started with the ID of the second submission created abvoe,
202
# so the first submission still has the status INVALID.
204
HWSubmissionProcessingStatus.INVALID,
205
new_submissions[0].status)
206
# We processed two submissions, they now have the status
209
HWSubmissionProcessingStatus.PROCESSED,
210
new_submissions[1].status)
212
HWSubmissionProcessingStatus.PROCESSED,
213
new_submissions[2].status)
214
# The following submissions were not yet touched,
216
HWSubmissionProcessingStatus.INVALID,
217
new_submissions[3].status)
219
HWSubmissionProcessingStatus.INVALID,
220
new_submissions[4].status)
222
# The start file now contains the ID of the 4th submission.
223
new_start = int(open(start_file_name).read())
224
self.assertEqual(new_submissions[3].id, new_start)
226
# When we run the script again, for only one submission,
227
# the 4th submission is processed.
229
Store.of(new_submissions[0]).invalidate()
230
retcode, stdout, stderr = run_script(
231
'cronscripts/reprocess-hwdb-submissions.py',
232
['--max-submissions', '1', '--start-file', start_file_name])
234
HWSubmissionProcessingStatus.PROCESSED,
235
new_submissions[3].status)
237
HWSubmissionProcessingStatus.INVALID,
238
new_submissions[4].status)