class SubversionFileSystemTest(unittest.TestCase):
    def setUp(self):
        self._base_path = os.path.join(sys.path[0], 'test_data', 'file_system')
        fetcher = FakeUrlFetcher(self._base_path)
        self._file_system = SubversionFileSystem(fetcher, fetcher)

    def _ReadLocalFile(self, filename):
        with open(os.path.join(self._base_path, filename), 'r') as f:
            return f.read()

    def testReadFiles(self):
        expected = {
            'test1.txt': 'test1\n',
            'test2.txt': 'test2\n',
            'test3.txt': 'test3\n',
        }
        self.assertEqual(
            expected,
            self._file_system.Read(['test1.txt', 'test2.txt',
                                    'test3.txt']).Get())

    def testListDir(self):
        expected = ['dir/']
        for i in range(7):
            expected.append('file%d.html' % i)
        self.assertEqual(expected,
                         sorted(self._file_system.ReadSingle('list/')))

    def testStat(self):
        stat_info = self._file_system.Stat('stat/')
        self.assertEquals('151113', stat_info.version)
        self.assertEquals(json.loads(self._ReadLocalFile('stat_result.json')),
                          stat_info.child_versions)
Example #2
0
    def testRevisions(self):
        # This is a super hacky test. Record the path that was fetched then exit the
        # test. Compare.
        class ValueErrorFetcher(object):
            def __init__(self):
                self.last_fetched = None

            def FetchAsync(self, path):
                class ThrowsValueError(object):
                    def Get(self):
                        raise ValueError()

                self.last_fetched = path
                return ThrowsValueError()

            def Fetch(self, path, **kwargs):
                self.last_fetched = path
                raise ValueError()

        file_fetcher = ValueErrorFetcher()
        stat_fetcher = ValueErrorFetcher()
        svn_path = 'svn:'

        svn_file_system = SubversionFileSystem(file_fetcher,
                                               stat_fetcher,
                                               svn_path,
                                               revision=42)

        self.assertRaises(FileSystemError,
                          svn_file_system.ReadSingle('dir/file').Get)
        self.assertEqual('dir/file?p=42', file_fetcher.last_fetched)
        # Stat() will always stat directories.
        self.assertRaises(FileSystemError, svn_file_system.Stat, 'dir/file')
        self.assertEqual('dir?pathrev=42', stat_fetcher.last_fetched)

        self.assertRaises(FileSystemError,
                          svn_file_system.ReadSingle('dir/').Get)
        self.assertEqual('dir/?p=42', file_fetcher.last_fetched)
        self.assertRaises(FileSystemError, svn_file_system.Stat, 'dir/')
        self.assertEqual('dir?pathrev=42', stat_fetcher.last_fetched)