Merge "[tests] Add printing of sample and template paths"
This commit is contained in:
@@ -376,24 +376,12 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
|||||||
self.assertEqual(exp_code, response.status_code, message)
|
self.assertEqual(exp_code, response.status_code, message)
|
||||||
response_data = response.content
|
response_data = response.content
|
||||||
response_data = pretty_data(response_data)
|
response_data = pretty_data(response_data)
|
||||||
if not os.path.exists(self._get_template(name,
|
template_path = self._get_template(name, self.microversion)
|
||||||
self.microversion)):
|
if not os.path.exists(template_path):
|
||||||
self._write_template(name, response_data)
|
self._write_template(name, response_data)
|
||||||
template_data = response_data
|
template_data = response_data
|
||||||
else:
|
else:
|
||||||
template_data = self._read_template(name)
|
template_data = self._read_template(name)
|
||||||
if (self.generate_samples and
|
|
||||||
not os.path.exists(self._get_sample(
|
|
||||||
name, self.microversion))):
|
|
||||||
|
|
||||||
self._write_sample(name, response_data)
|
|
||||||
sample_data = response_data
|
|
||||||
else:
|
|
||||||
with open(self._get_sample(name,
|
|
||||||
self.microversion)) as sample:
|
|
||||||
sample_data = sample.read()
|
|
||||||
if update_links:
|
|
||||||
sample_data = self._update_links(sample_data)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
template_data = objectify(template_data)
|
template_data = objectify(template_data)
|
||||||
@@ -403,11 +391,20 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
|||||||
except NoMatch as e:
|
except NoMatch as e:
|
||||||
raise NoMatch("\nFailed to match Template to Response: \n%s\n"
|
raise NoMatch("\nFailed to match Template to Response: \n%s\n"
|
||||||
"Template: %s\n\n"
|
"Template: %s\n\n"
|
||||||
|
"Template Path: %s\n\n"
|
||||||
"Response: %s\n\n" %
|
"Response: %s\n\n" %
|
||||||
(e,
|
(e, pp.pformat(template_data), template_path,
|
||||||
pp.pformat(template_data),
|
|
||||||
pp.pformat(response_data)))
|
pp.pformat(response_data)))
|
||||||
|
|
||||||
|
sample_path = self._get_sample(name, self.microversion)
|
||||||
|
if (self.generate_samples and not os.path.exists(sample_path)):
|
||||||
|
self._write_sample(name, response_data)
|
||||||
|
sample_data = response_data
|
||||||
|
else:
|
||||||
|
with open(sample_path) as sample:
|
||||||
|
sample_data = sample.read()
|
||||||
|
if update_links:
|
||||||
|
sample_data = self._update_links(sample_data)
|
||||||
try:
|
try:
|
||||||
# NOTE(danms): replace some of the subs with patterns for the
|
# NOTE(danms): replace some of the subs with patterns for the
|
||||||
# doc/api_samples check, which won't have things like the
|
# doc/api_samples check, which won't have things like the
|
||||||
@@ -426,12 +423,13 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase):
|
|||||||
except NoMatch as e:
|
except NoMatch as e:
|
||||||
raise NoMatch("\nFailed to match Template to Sample: \n%s\n"
|
raise NoMatch("\nFailed to match Template to Sample: \n%s\n"
|
||||||
"Template: %s\n\n"
|
"Template: %s\n\n"
|
||||||
|
"Template Path: %s\n\n"
|
||||||
"Sample: %s\n\n"
|
"Sample: %s\n\n"
|
||||||
|
"sample Path: %s\n\n"
|
||||||
"Hint: does your test need to override "
|
"Hint: does your test need to override "
|
||||||
"ApiSampleTestBase.generalize_subs()?" %
|
"ApiSampleTestBase.generalize_subs()?" %
|
||||||
(e,
|
(e, pp.pformat(template_data), template_path,
|
||||||
pp.pformat(template_data),
|
pp.pformat(response_data), sample_path))
|
||||||
pp.pformat(sample_data)))
|
|
||||||
|
|
||||||
def _get_host(self):
|
def _get_host(self):
|
||||||
return 'http://openstack.example.com'
|
return 'http://openstack.example.com'
|
||||||
|
Reference in New Issue
Block a user