def test_create_json_file_attribute_no_default(self, open_mock):

        open_mock.side_effect = IOError()

        setting = {
            "type": "json_file",
             "from_filepath": "test.txt",
             "to_attribute": "other_value",
        }

        with self.assertRaises(EnvironmentSettingNotFoundException):
            output = EnvironmentConfig.create_json_file_attribute(setting)
Пример #2
0
    def test_create_json_file_attribute_no_default(self, open_mock):

        open_mock.side_effect = IOError()

        setting = {
            "type": "json_file",
            "from_filepath": "test.txt",
            "to_attribute": "other_value",
        }

        with self.assertRaises(EnvironmentSettingNotFoundException):
            output = EnvironmentConfig.create_json_file_attribute(setting)
    def test_create_json_file_attribute_use_default(self, open_mock):

        open_mock.side_effect = IOError()

        setting = {
            "type": "json_file",
             "from_filepath": "test.txt",
             "to_attribute": "other_value",
             "default": {"another_value": None},
        }

        output = EnvironmentConfig.create_json_file_attribute(setting)
        self.assertEqual(output, {"another_value": None})
Пример #4
0
    def test_create_json_file_attribute_use_default(self, open_mock):

        open_mock.side_effect = IOError()

        setting = {
            "type": "json_file",
            "from_filepath": "test.txt",
            "to_attribute": "other_value",
            "default": {
                "another_value": None
            },
        }

        output = EnvironmentConfig.create_json_file_attribute(setting)
        self.assertEqual(output, {"another_value": None})
    def test_create_json_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 = json.dumps({"some_value": None})
        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": "json_file",
             "from_filepath": "test.txt",
             "to_attribute": "other_value",
             "default": {"another_value": None},
        }

        output = EnvironmentConfig.create_json_file_attribute(setting)
        self.assertEqual(output, {"some_value": None})
Пример #6
0
    def test_create_json_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 = json.dumps({"some_value": None})
        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": "json_file",
            "from_filepath": "test.txt",
            "to_attribute": "other_value",
            "default": {
                "another_value": None
            },
        }

        output = EnvironmentConfig.create_json_file_attribute(setting)
        self.assertEqual(output, {"some_value": None})