示例#1
0
    def test_check_writer_consistency(self, mock_sftp):

        items_to_write = self.get_batch()
        options = self.get_writer_config()
        options['options']['check_consistency'] = True
        mock_sftp.return_value.__enter__.return_value.stat.return_value.st_size = 999

        # when:
        try:
            writer = SFTPWriter(options, meta())
            writer.write_batch(items_to_write)
            writer.flush()
        finally:
            writer.close()

        with self.assertRaisesRegexp(InconsistentWriteState, 'Wrong size for file'):
            writer.finish_writing()

        exception = IOError()
        exception.errno = errno.ENOENT
        mock_sftp.return_value.__enter__.return_value.stat.side_effect = exception
        with self.assertRaisesRegexp(InconsistentWriteState, 'is not present at destination'):
            writer.finish_writing()
示例#2
0
 def test_create(self):
     options = self.get_writer_config()
     writer = SFTPWriter(options, meta())
     self.assertEquals(22, writer.read_option('port'))
     writer.close()