def test_course_namespace_and_management_handling(self, mockHook, mockGetHelm, mockYAML): """Assure that course replaces strings with object settings for chart repository settings""" course = mockYAML.load.return_value = self.course_yaml course['namespace'] = "test-namespace" course['namespace_management'] = { "default": { "metadata": { "annotations": { "a-one": "a1", "a-two": "a2" }, "labels": { "l-one": "l1", "l-two": "l2", } }, "settings": { "overwrite": True } } } # Mock out the repository helm client with mock.patch('reckoner.repository.HelmClient', mockGetHelm): # Run the course to convert the chart['first-chart']['repository'] reference c = Course(None) # Assert the chart namespace is string self.assertIsInstance(course['namespace'], str) # Assert that the dict for the namespace manager is the same after course loads self.assertDictEqual( c.namespace_management, { "metadata": { "annotations": { "a-one": "a1", "a-two": "a2" }, "labels": { "l-one": "l1", "l-two": "l2", } }, "settings": { "overwrite": True } } ) # expect the first chart install to bubble up an error chart = mock.MagicMock() c.install_charts([chart]) chart.install.assert_called_with( context=c.context, default_namespace=c.namespace, default_namespace_management=c.namespace_management )
def test_chart_install_logic(self, mockHook, mockGetHelm, mockYAML): mockYAML.load.return_value = { 'charts': { 'first-chart': {}, 'second-chart': {} } } # expect the first chart install to bubble up an error chart = mock.MagicMock() chart.result = None chart.install.side_effect = Exception("Second command has an error") course = Course(None) self.assertEqual(len(course.install_charts([chart, chart])), 1) course.config.continue_on_error = True self.assertEqual(len(course.install_charts([chart, chart])), 2)
def test_course_namespace_and_without_namespace_management_handling( self, mockHook, mockGetHelm, mockYAML): """Assure that course replaces strings with object settings for chart repository settings""" course = mockYAML.load.return_value = self.course_yaml course['namespace'] = "test-namespace" # Mock out the repository helm client with mock.patch('reckoner.repository.HelmClient', mockGetHelm): # Run the course to convert the chart['first-chart']['repository'] reference c = Course(None) # Assert the chart namespace is string self.assertIsInstance(course['namespace'], str) # Assert that the dict for the namespace manager is the same after course loads # expect the first chart install to bubble up an error chart = mock.MagicMock() c.install_charts([chart]) chart.install.assert_called_with( context=c.context, default_namespace=c.namespace, default_namespace_management=c.namespace_management)