Fix helm charts tests for DebianOS

1) Cannot JSON serialize MagicMock objects.
Instead of letting the test environment create MagicMock objects,
create custom objects.

2) A transition from PyYAML 3.13 to PyYAML 5.3.1 is made for DebianOS.
The default value of 'default_flow_style' was changed to 'False' in
PyYAML 5.1.1.
For backwards compatibility we now need to explicitly assign the
'None' value where default_flow_style is not populated.

Story 2009101
Task: 42976
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Change-Id: Ide1b8b593dafa4680b204f50168ed898625b3b40
(cherry picked from commit bbe77385d6)
This commit is contained in:
Dan Voiculeasa 2021-08-09 19:11:09 +03:00 committed by Dan Voiculeasa
parent 2cd10430d1
commit a2d3e896b9
2 changed files with 8 additions and 1 deletions

View File

@ -83,7 +83,8 @@ class HelmChartsController(rest.RestController):
try:
system_overrides = pecan.request.rpcapi.get_helm_chart_overrides(
pecan.request.context, app_name, name, namespace)
system_overrides = yaml.safe_dump(system_overrides) \
system_overrides = yaml.safe_dump(system_overrides,
default_flow_style=None) \
if system_overrides else None
except Exception as e:
raise wsme.exc.ClientSideError(_("Unable to get the helm chart overrides "

View File

@ -172,6 +172,8 @@ class ApiHelmChartShowTestSuiteMixin(ApiHelmChartTestCaseMixin):
def test_no_system_override(self):
self.fake_system_app.return_value = False
self.fake_merge_overrides.return_value = {}
url = self.get_single_url_helm_override('platform-integ-apps',
'ceph-pools-audit', 'kube-system')
response = self.get_json(url)
@ -264,6 +266,7 @@ class ApiHelmChartShowTestSuiteMixin(ApiHelmChartTestCaseMixin):
self.fake_helm_apps.return_value = ['platform-integ-apps']
# Return helm chart overrides
self.fake_override.return_value = {"enabled": True}
self.fake_merge_overrides.return_value = {}
url = self.get_single_url_helm_override('platform-integ-apps',
'ceph-pools-audit', 'kube-system')
@ -294,6 +297,7 @@ class ApiHelmChartDeleteTestSuiteMixin(ApiHelmChartTestCaseMixin):
# Test that a valid DELETE operation is successful
def test_delete_helm_override_success(self):
self.fake_system_app.return_value = False
self.fake_merge_overrides.return_value = {}
# Verify that user override exists initially
url = self.get_single_url_helm_override('platform-integ-apps',
@ -502,6 +506,8 @@ class ApiHelmChartPatchTestSuiteMixin(ApiHelmChartTestCaseMixin):
headers=self.API_HEADERS,
expect_errors=True)
self.fake_system_app.return_value = False
self.fake_merge_overrides.return_value = {}
response = self.get_json(url, expect_errors=True)
self.assertEqual(response.status_code, http_client.OK)
# Verify the values of the response with the values in database