def test_create_file_attribute_no_default(self, open_mock): open_mock.side_effect = IOError() setting = { "type": "file", "from_filepath": "test.txt", "to_attribute": "other_value", } with self.assertRaises(EnvironmentSettingNotFoundException): output = EnvironmentConfig.create_file_attribute(setting)
def test_create_file_attribute_use_default(self, open_mock): open_mock.side_effect = IOError() setting = { "type": "file", "from_filepath": "test.txt", "to_attribute": "other_value", "default": "another_value", } output = EnvironmentConfig.create_file_attribute(setting) self.assertEqual(output, "another_value")
def test_create_file_attribute_dont_use_default(self, open_mock): mock_context = Mock() mock_enter = Mock() mock_exit = Mock() mock_file_obj = Mock() mock_file_obj.read.return_value = "some_value" mock_enter.return_value = mock_file_obj setattr(mock_context, '__enter__', mock_enter) setattr(mock_context, '__exit__', mock_exit) open_mock.return_value = mock_context setting = { "type": "file", "from_filepath": "test.txt", "to_attribute": "other_value", "default": "another_value", } output = EnvironmentConfig.create_file_attribute(setting) self.assertEqual(output, "some_value")