Exemple #1
0
 def testDelete(self, mock_urlopen):
     """Tests that local files can be deleted."""
     file_util.RemoteFileHandle('file:///root/path').Delete()
     request = mock_urlopen.call_args[0][0]
     self.assertEqual('DELETE', request.get_method())
     self.assertEqual('http://file_server:8006/file/path',
                      request.get_full_url())
Exemple #2
0
    def testListFiles(self, mock_urlopen):
        """Tests that nested files can be listed."""
        data = json.dumps([
            {
                'name': 'foo',
                'path': 'path/foo',
                'size': 4096,
                'type': 'DIRECTORY',
                'update_time': 631152000000
            },
            {
                'name': 'bar',
                'path': 'path/bar',
                'size': 123456,
                'type': 'FILE',
                'update_time': 946684800000
            },
        ])
        mock_urlopen.return_value = io.BytesIO(six.ensure_binary(data))

        files = file_util.RemoteFileHandle('file:///root/path').ListFiles()
        mock_urlopen.assert_called_with('http://file_server:8006/dir/path')
        self.assertEqual(files, [
            file_util.FileInfo(url='file:///root/path/foo',
                               is_file=False,
                               total_size=4096,
                               timestamp=datetime.datetime(1990, 1, 1)),
            file_util.FileInfo(url='file:///root/path/bar',
                               is_file=True,
                               total_size=123456,
                               timestamp=datetime.datetime(2000, 1, 1))
        ])
Exemple #3
0
 def testUrlWithHostname(self):
     """Tests that bytes can be written using HTTP requests."""
     handle = file_util.RemoteFileHandle('file://test.hostname/root/path')
     self.assertEqual('/path', handle.path)
     self.assertEqual('http://test.hostname:8006/file/path',
                      handle.file_url)
     self.assertEqual('http://test.hostname:8006/dir/path', handle.dir_url)
Exemple #4
0
 def testWriteBytes_partial(self, mock_urlopen):
     """Tests that partial content can be written using HTTP requests."""
     handle = file_util.RemoteFileHandle('file:///root/path')
     stream = handle.Open(
         mode='w').detach()  # Detach to test underlying stream
     stream.WriteBytes(offset=5, data='hello\nworld', finish=False)
     request = mock_urlopen.call_args[0][0]
     self.assertEqual('http://file_server:8006/file/path',
                      request.get_full_url())
     self.assertEqual('hello\nworld', request.data)
     self.assertEqual('bytes 5-15/*', request.get_header('Content-range'))
Exemple #5
0
 def testListFiles_notFound(self, mock_urlopen):
     """Tests that file not found errors are handled when listing files."""
     mock_urlopen.side_effect = urllib.error.HTTPError(
         None, 404, None, None, None)
     files = file_util.RemoteFileHandle('file:///root/path').ListFiles()
     self.assertIsNone(files)
Exemple #6
0
 def Run(cls):
   """Check local file server availability."""
   files = file_util.RemoteFileHandle('file:///').ListFiles()
   if files is None:
     raise RuntimeError('File server root directory not found')