示例#1
0
文件: test_files.py 项目: loum/itt
    def test_dummy_filesystem(self):
        """Test the creation of the dummy filesystem.
        """
        temp_fs = dummy_filesystem('bananas')

        content = None
        with open(temp_fs.name) as fh:
            content = fh.read()

        msg = ''
        received = content
        expected = 'bananas'
        self.assertEqual(received, expected, msg)
示例#2
0
    def setUpClass(cls):
        # Set up the FTP server filesystem with some content.
        cls._test_content = 'FTP stuff'
        cls._temp_fs = dummy_filesystem(content=cls._test_content)

        # Given our dummy filesystem, make note of the directory and file
        # that will be presented by the FTP server.
        cls._test_dir = os.path.dirname(cls._temp_fs.name)
        cls._test_filename = os.path.basename(cls._temp_fs.name)

        # Start the FTP server.
        cls._server = itt.FtpServer(root=cls._test_dir)
        cls._server.start()
示例#3
0
    def test_start_with_existing_pid_file(self):
        """Test start with existing PID file.
        """
        # Open local instance of a PID file to simulate existing file.
        # PID file contents are empty.
        temp_fs = dummy_filesystem()
        pid_file = temp_fs.name

        # Attempt to set up the daemon.
        with self.assertRaisesRegexp(itt.utils.DaemonError,
                                     'Error reading PID file: *'):
            DummyDaemon(pidfile=pid_file)

        # Clean up.
        temp_fs.close()
示例#4
0
    def test_stop_non_existent_pid(self):
        """Test stop of an non-existent PID file.
        """
        # Open local instance of a PID file to simulate empty file.
        # This file will be deleted by the stop() method make it persist
        # on the filesystem so that temporary file doesn't barf.
        temp_fs = dummy_filesystem(content='999999')
        temp_fs.delete = False
        pid_file = temp_fs.name

        # Set up the daemon.
        daemon = DummyDaemon(pidfile=pid_file)
        msg = 'Daemon stop status dodgy PID should be False'
        self.assertFalse(daemon.stop(), msg)

        # Check that the PID file was removed.
        msg = 'PID file "%s" was not removed after dodgy PID' % pid_file
        self.assertFalse(os.path.exists(pid_file), msg)
示例#5
0
    def setUp(self):
        self.test_content = 'temp TFTP stuff'
        self.temp_fs = dummy_filesystem(content=self.test_content)
        self.test_dir = os.path.dirname(self.temp_fs.name)

        # Default port.
        tftp = itt.TftpServer(root=self.test_dir)
        expected = 6969
        received = tftp.port
        msg = ('Default TFTP port should be 6969 - received %s' %
               str(received))
        self.assertEqual(received, expected, msg)
        tftp = None

        # Overriden port.
        received = port_to_use = 6970
        tftp = itt.TftpServer(root=self.test_dir, port=port_to_use)
        expected = tftp.port
        msg = ('Overriden port value should be 6970 - received %s' %
               str(received))
        self.assertEqual(received, expected, msg)
        tftp = None
示例#6
0
 def setUp(self):
     # Create a location for our PID.
     self._temp_fs = dummy_filesystem()
     self._pid_file = self._temp_fs.name
     self._temp_fs.close()
示例#7
0
文件: test_files.py 项目: loum/itt
 def test_is_writable_valid(self):
     """Test access to a writable file.
     """
     temp_fs = dummy_filesystem()
     fs = is_writable(temp_fs.name)
     self.assertNotEqual(fs, None)