summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/server2/github_file_system_test.py
blob: 65a6928b05e0c3a3f264afb58076397ebe4022d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import json
import os
import sys
import unittest

from appengine_blobstore import AppEngineBlobstore
from appengine_url_fetcher import AppEngineUrlFetcher
from appengine_wrappers import files
from fake_fetchers import ConfigureFakeFetchers
from github_file_system import GithubFileSystem
from object_store_creator import ObjectStoreCreator
import url_constants

class GithubFileSystemTest(unittest.TestCase):
  def setUp(self):
    ConfigureFakeFetchers()
    self._base_path = os.path.join(sys.path[0],
                                   'test_data',
                                   'github_file_system')
    self._file_system = GithubFileSystem(
        AppEngineUrlFetcher(url_constants.GITHUB_URL),
        AppEngineBlobstore(),
        ObjectStoreCreator.ForTest())

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

  def testList(self):
    self.assertEqual(json.loads(self._ReadLocalFile('expected_list.json')),
                     self._file_system.Read(['/']).Get())

  def testRead(self):
   self.assertEqual(self._ReadLocalFile('expected_read.txt'),
                    self._file_system.ReadSingle('/analytics/launch.js'))

  def testStat(self):
    self.assertEqual(0, self._file_system.Stat('zipball').version)

  def testKeyGeneration(self):
    self.assertEqual(0, len(files.GetBlobKeys()))
    self._file_system.ReadSingle('/analytics/launch.js')
    self.assertEqual(1, len(files.GetBlobKeys()))
    self._file_system.ReadSingle('/analytics/main.css')
    self.assertEqual(1, len(files.GetBlobKeys()))

if __name__ == '__main__':
  unittest.main()