Ejemplo n.º 1
0
  def testWithOffline(self):
    creator = HostFileSystemCreator(ObjectStoreCreator.ForTest(),
                                    offline=True,
                                    constructor_for_test=ConstructorForTest)

    fs = creator.Create('trunk')
    # Offline file system should raise a FileNotFoundError if read is attempted.
    self.assertRaises(FileNotFoundError, fs.ReadSingle, self._idle_path)
Ejemplo n.º 2
0
  def testWithCaching(self):
    creator = HostFileSystemCreator(ObjectStoreCreator.ForTest(),
                                    constructor_for_test=ConstructorForTest)

    fs = creator.Create('trunk')
    firstRead = fs.ReadSingle(self._idle_path)
    CANNED_API_FILE_SYSTEM_DATA['trunk']['api']['idle.json'] = 'blah blah blah'
    secondRead = fs.ReadSingle(self._idle_path)

    self.assertEqual(firstRead, secondRead)
 def ForTest(file_system):
     object_store_creator = ObjectStoreCreator.ForTest()
     return ServerInstance(
         object_store_creator, file_system, EmptyDirFileSystem(), '',
         CompiledFileSystem.Factory(file_system, object_store_creator),
         TestBranchUtility.CreateWithCannedData(),
         HostFileSystemCreator.ForTest(file_system, object_store_creator))
Ejemplo n.º 4
0
    def CreateHostFileSystemCreator(self, object_store_creator):
        def constructor(branch=None, revision=None):
            file_system = self._create_file_system(revision)
            self.file_systems.append(file_system)
            return file_system

        return HostFileSystemCreator(object_store_creator,
                                     constructor_for_test=constructor)
 def ForLocal():
     object_store_creator = ObjectStoreCreator(start_empty=False,
                                               store_type=TestObjectStore)
     host_file_system_creator = HostFileSystemCreator.ForLocal(
         object_store_creator)
     trunk_file_system = host_file_system_creator.Create()
     return ServerInstance(
         object_store_creator, trunk_file_system, EmptyDirFileSystem(), '',
         CompiledFileSystem.Factory(trunk_file_system,
                                    object_store_creator),
         TestBranchUtility.CreateWithCannedData(), host_file_system_creator)
 def CreateHostFileSystemCreator(self, object_store_creator):
     return HostFileSystemCreator(object_store_creator)
Ejemplo n.º 7
0
    def testInstanceMethods(self):
        test_data = {
            'server2': {
                'app.yaml': _GenerateAppYaml('1-0'),
                'app_yaml_helper.py': 'Copyright notice etc'
            }
        }

        updates = []

        file_system_at_head = MockFileSystem(TestFileSystem(test_data))

        def apply_update(update):
            file_system_at_head.Update(update)
            updates.append(update)

        def constructor(branch, revision=None):
            return MockFileSystem.Create(TestFileSystem(test_data),
                                         updates[:revision])

        host_file_system_creator = HostFileSystemCreator(
            ObjectStoreCreator.ForTest(), constructor_for_test=constructor)
        helper = AppYamlHelper(
            'server2/app.yaml', file_system_at_head,
            ObjectStoreCreator.ForTest(disable_wrappers=False),
            host_file_system_creator)

        def assert_is_up_to_date(version):
            self.assertTrue(helper.IsUpToDate(version),
                            '%s is not up to date' % version)
            self.assertRaises(ValueError, helper.GetFirstRevisionGreaterThan,
                              version)

        self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
        assert_is_up_to_date('1-0-0')
        assert_is_up_to_date('1-5-0')

        # Revision 1.
        apply_update({'server2': {'app.yaml': _GenerateAppYaml('1-5-0')}})

        self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
        self.assertEqual(1, helper.GetFirstRevisionGreaterThan('1-0-0'))
        assert_is_up_to_date('1-5-0')
        assert_is_up_to_date('2-5-0')

        # Revision 2.
        apply_update({'server2': {'app_yaml_helper.py': 'fixed a bug'}})

        self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
        self.assertEqual(1, helper.GetFirstRevisionGreaterThan('1-0-0'))
        assert_is_up_to_date('1-5-0')
        assert_is_up_to_date('2-5-0')

        # Revision 3.
        apply_update({'server2': {'app.yaml': _GenerateAppYaml('1-6-0')}})

        self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
        self.assertEqual(1, helper.GetFirstRevisionGreaterThan('1-0-0'))
        self.assertEqual(3, helper.GetFirstRevisionGreaterThan('1-5-0'))
        assert_is_up_to_date('2-5-0')

        # Revision 4.
        apply_update({'server2': {'app.yaml': _GenerateAppYaml('1-8-0')}})
        # Revision 5.
        apply_update({'server2': {'app.yaml': _GenerateAppYaml('2-0-0')}})
        # Revision 6.
        apply_update({'server2': {'app.yaml': _GenerateAppYaml('2-2-0')}})
        # Revision 7.
        apply_update({'server2': {'app.yaml': _GenerateAppYaml('2-4-0')}})
        # Revision 8.
        apply_update({'server2': {'app.yaml': _GenerateAppYaml('2-6-0')}})

        self.assertEqual(0, helper.GetFirstRevisionGreaterThan('0-5-0'))
        self.assertEqual(1, helper.GetFirstRevisionGreaterThan('1-0-0'))
        self.assertEqual(3, helper.GetFirstRevisionGreaterThan('1-5-0'))
        self.assertEqual(5, helper.GetFirstRevisionGreaterThan('1-8-0'))
        self.assertEqual(6, helper.GetFirstRevisionGreaterThan('2-0-0'))
        self.assertEqual(6, helper.GetFirstRevisionGreaterThan('2-1-0'))
        self.assertEqual(7, helper.GetFirstRevisionGreaterThan('2-2-0'))
        self.assertEqual(7, helper.GetFirstRevisionGreaterThan('2-3-0'))
        self.assertEqual(8, helper.GetFirstRevisionGreaterThan('2-4-0'))
        self.assertEqual(8, helper.GetFirstRevisionGreaterThan('2-5-0'))
        assert_is_up_to_date('2-6-0')
        assert_is_up_to_date('2-7-0')
Ejemplo n.º 8
0
 def CreateHostFileSystemCreator(self, object_store_creator):
     return HostFileSystemCreator.ForTest(FailOnAccessFileSystem(),
                                          object_store_creator)