Skip to content

Commit d5cfdfd

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "[tests] Add printing of sample and template paths"
2 parents 3dbbe83 + e2adef4 commit d5cfdfd

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

nova/tests/functional/api_samples_test_base.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,12 @@ def _verify_response(self, name, subs, response, exp_code,
376376
self.assertEqual(exp_code, response.status_code, message)
377377
response_data = response.content
378378
response_data = pretty_data(response_data)
379-
if not os.path.exists(self._get_template(name,
380-
self.microversion)):
379+
template_path = self._get_template(name, self.microversion)
380+
if not os.path.exists(template_path):
381381
self._write_template(name, response_data)
382382
template_data = response_data
383383
else:
384384
template_data = self._read_template(name)
385-
if (self.generate_samples and
386-
not os.path.exists(self._get_sample(
387-
name, self.microversion))):
388-
389-
self._write_sample(name, response_data)
390-
sample_data = response_data
391-
else:
392-
with open(self._get_sample(name,
393-
self.microversion)) as sample:
394-
sample_data = sample.read()
395-
if update_links:
396-
sample_data = self._update_links(sample_data)
397385

398386
try:
399387
template_data = objectify(template_data)
@@ -403,11 +391,20 @@ def _verify_response(self, name, subs, response, exp_code,
403391
except NoMatch as e:
404392
raise NoMatch("\nFailed to match Template to Response: \n%s\n"
405393
"Template: %s\n\n"
394+
"Template Path: %s\n\n"
406395
"Response: %s\n\n" %
407-
(e,
408-
pp.pformat(template_data),
396+
(e, pp.pformat(template_data), template_path,
409397
pp.pformat(response_data)))
410398

399+
sample_path = self._get_sample(name, self.microversion)
400+
if (self.generate_samples and not os.path.exists(sample_path)):
401+
self._write_sample(name, response_data)
402+
sample_data = response_data
403+
else:
404+
with open(sample_path) as sample:
405+
sample_data = sample.read()
406+
if update_links:
407+
sample_data = self._update_links(sample_data)
411408
try:
412409
# NOTE(danms): replace some of the subs with patterns for the
413410
# doc/api_samples check, which won't have things like the
@@ -426,12 +423,13 @@ def _verify_response(self, name, subs, response, exp_code,
426423
except NoMatch as e:
427424
raise NoMatch("\nFailed to match Template to Sample: \n%s\n"
428425
"Template: %s\n\n"
426+
"Template Path: %s\n\n"
429427
"Sample: %s\n\n"
428+
"sample Path: %s\n\n"
430429
"Hint: does your test need to override "
431430
"ApiSampleTestBase.generalize_subs()?" %
432-
(e,
433-
pp.pformat(template_data),
434-
pp.pformat(sample_data)))
431+
(e, pp.pformat(template_data), template_path,
432+
pp.pformat(response_data), sample_path))
435433

436434
def _get_host(self):
437435
return 'http://openstack.example.com'

0 commit comments

Comments
 (0)