示例#1
0
 def test_raises_when_could_not_read(self):
     assert_raise_library_error(
         lambda: env_file.RealFile("some role", MISSING_PATH).read(),
         (severities.ERROR, report_codes.FILE_IO_ERROR, {
             "reason":
             "No such file or directory: '{0}'".format(MISSING_PATH),
         }))
示例#2
0
 def test_existence_is_required(self, _):
     assert_raise_library_error(
         lambda: env_file.RealFile("some role", FILE_PATH).remove(),
         (severities.ERROR, report_codes.FILE_IO_ERROR, {
             'reason': "File does not exist",
             'file_role': 'some role',
             'file_path': '/path/to.file'
         }))
示例#3
0
 def test_raise_library_error_when_remove_failed(self, _, dummy):
     assert_raise_library_error(
         lambda: env_file.RealFile("some role", FILE_PATH).remove(),
         (severities.ERROR, report_codes.FILE_IO_ERROR, {
             'reason': "mock remove failed: '/path/to.file'",
             'file_role': 'some role',
             'file_path': '/path/to.file'
         }))
示例#4
0
 def test_success_write_content_to_path(self):
     mock_open = mock.mock_open()
     mock_file_operation = mock.Mock()
     with patch_env_file("open", mock_open, create=True):
         env_file.RealFile("some role", CONF_PATH).write(
             "config content", file_operation=mock_file_operation)
         mock_open.assert_called_once_with(CONF_PATH, "w")
         mock_open().write.assert_called_once_with("config content")
         mock_file_operation.assert_called_once_with(CONF_PATH)
示例#5
0
 def test_success_binary(self):
     mock_open = mock.mock_open()
     mock_file_operation = mock.Mock()
     with patch_env_file("open", mock_open, create=True):
         env_file.RealFile("some role", CONF_PATH, is_binary=True).write(
             "config content".encode("utf-8"),
             file_operation=mock_file_operation,
         )
         mock_open.assert_called_once_with(CONF_PATH, "wb")
         mock_open().write.assert_called_once_with(
             "config content".encode("utf-8"))
         mock_file_operation.assert_called_once_with(CONF_PATH)
示例#6
0
 def check(self, report_processor, can_overwrite_existing=False):
     real_file = env_file.RealFile("some role", CONF_PATH)
     real_file.assert_no_conflict_with_existing(report_processor,
                                                can_overwrite_existing)
示例#7
0
 def test_return_false_if_file_does_not_exist(self, exists):
     self.assertFalse(env_file.RealFile("some role", FILE_PATH).exists)
示例#8
0
 def test_return_true_if_file_exists(self, exists):
     self.assertTrue(env_file.RealFile("some role", FILE_PATH).exists)
示例#9
0
 def test_noexistent_can_be_silenced(self, _):
     env_file.RealFile("some role",
                       FILE_PATH).remove(silence_no_existence=True)
示例#10
0
 def test_success_remove_file(self, _, mock_remove):
     env_file.RealFile("some role", FILE_PATH).remove()
     mock_remove.assert_called_once_with(FILE_PATH)
示例#11
0
 def test_success_read_content_from_binary_file(self):
     self.assert_read_in_correct_mode(env_file.RealFile("some role",
                                                        FILE_PATH,
                                                        is_binary=True),
                                      mode="rb")