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

    fs = creator.GetBranch('1500')
    # Offline file system should raise a FileNotFoundError if read is attempted.
    self.assertRaises(FileNotFoundError, fs.ReadSingle(self._idle_path).Get)
Ejemplo n.º 2
0
 def CreateHostFileSystemProvider(self,
                                 object_store_creator,
                                 max_trunk_revision=None):
   def constructor(branch=None, revision=None):
     file_system = self._create_file_system(revision)
     self.file_systems.append(file_system)
     return file_system
   return HostFileSystemProvider(object_store_creator,
                                 max_trunk_revision=max_trunk_revision,
                                 constructor_for_test=constructor)
    def setUp(self):
        def host_file_system_constructor(branch, **optargs):
            return TestFileSystem(deepcopy(
                CANNED_API_FILE_SYSTEM_DATA[branch]))

        host_file_system_provider = HostFileSystemProvider(
            ObjectStoreCreator.ForTest(),
            constructor_for_test=host_file_system_constructor)
        self._branch_utility = TestBranchUtility.CreateWithCannedData()
        self._iterator = HostFileSystemIterator(host_file_system_provider,
                                                self._branch_utility)
Ejemplo n.º 4
0
    def CreateHostFileSystemProvider(self,
                                     object_store_creator,
                                     pinned_commit=None):
        def constructor(branch=None, commit=None):
            file_system = self._create_file_system(commit)
            self.file_systems.append(file_system)
            return file_system

        return HostFileSystemProvider(object_store_creator,
                                      pinned_commit=pinned_commit,
                                      constructor_for_test=constructor)
Ejemplo n.º 5
0
  def testWithCaching(self):
    creator = HostFileSystemProvider(
        ObjectStoreCreator.ForTest(),
        constructor_for_test=self._constructor_for_test)

    fs = creator.GetBranch('1500')
    first_read = fs.ReadSingle(self._idle_path).Get()
    self._canned_data['1500']['api']['idle.json'] = 'blah blah blah'
    second_read = fs.ReadSingle(self._idle_path).Get()

    self.assertEqual(first_read, second_read)
Ejemplo n.º 6
0
def _CreateServerInstance(commit):
    '''Creates a ServerInstance based on origin/master.
  '''
    object_store_creator = ObjectStoreCreator(
        start_empty=False, store_type=PersistentObjectStoreFake)
    branch_utility = BranchUtility.Create(object_store_creator)
    host_file_system_provider = HostFileSystemProvider(object_store_creator,
                                                       pinned_commit=commit)
    gcs_file_system_provider = CloudStorageFileSystemProvider(
        object_store_creator)
    return ServerInstance(object_store_creator,
                          CompiledFileSystem.Factory(object_store_creator),
                          branch_utility, host_file_system_provider,
                          gcs_file_system_provider)
Ejemplo n.º 7
0
  def testDetectInline(self):
    schema = {
      'types': [
        {
          'id': 'Key',
          'items': {
            '$ref': 'Value'
          }
        },
        {
          'id': 'Value',
          'marker': True
        }
      ]
    }

    expected_schema = {
      'types': [
        {
          'id': 'Key',
          'items': {
            'marker': True,
          }
        }
      ]
    }

    object_store_creator = ObjectStoreCreator(start_empty=False)
    host_file_system_provider = HostFileSystemProvider(object_store_creator)
    schema_processor = SchemaProcessor(_FakeReferenceResolver(),
                                       _FakeAPIModels(),
                                       _FakeFeaturesBundle(),
                                       CompiledFileSystem.Factory(
                                           object_store_creator),
                                       host_file_system_provider.GetMaster(),
                                       False)
    schema_processor._DetectInlineableTypes(schema)
    schema_processor._InlineDocs(schema)
    self.assertEqual(expected_schema, schema)
 def CreateHostFileSystemProvider(self, object_store_creator,
                                  **optargs):
     return HostFileSystemProvider(object_store_creator, **optargs)
Ejemplo n.º 9
0
    def testInstanceMethods(self):
        test_data = {
            'server2': {
                'app.yaml': _GenerateAppYaml('1-0'),
                'app_yaml_helper.py': 'Copyright notice etc'
            }
        }

        updates = []
        # Pass a specific file system at head to the HostFileSystemProvider so that
        # we know it's always going to be backed by a MockFileSystem. The Provider
        # may decide to wrap it in caching etc.
        file_system_at_head = MockFileSystem(TestFileSystem(test_data))

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

        def host_file_system_constructor(branch, revision=None):
            self.assertEqual('trunk', branch)
            self.assertTrue(revision is not None)
            return MockFileSystem.Create(TestFileSystem(test_data),
                                         updates[:revision])

        object_store_creator = ObjectStoreCreator.ForTest()
        host_file_system_provider = HostFileSystemProvider(
            object_store_creator,
            default_trunk_instance=file_system_at_head,
            constructor_for_test=host_file_system_constructor)
        helper = AppYamlHelper('server2/app.yaml', object_store_creator,
                               host_file_system_provider)

        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.º 10
0
 def CreateHostFileSystemProvider(self,
                                  object_store_creator,
                                  max_trunk_revision=None):
     return HostFileSystemProvider(
         object_store_creator, max_trunk_revision=max_trunk_revision)
Ejemplo n.º 11
0
 def CreateHostFileSystemProvider(self,
                                  object_store_creator,
                                  pinned_commit=None):
     return HostFileSystemProvider(object_store_creator,
                                   pinned_commit=pinned_commit)
Ejemplo n.º 12
0
  def testRemoveNoDocs(self):
    expected_nodoc = [
      {
        'name': 'B',
        'list': [
          {
            'name': 'B2'
          }
        ]
      },
      {
        'name': 'D',
        'nodoc': False
      },
      {
        'name': 'E',
        'items1': [
          {
            'name': 'E1',
            'items': [
              {
                'name': 'E1.3'
              }
            ]
          },
          {
            'name': 'E2'
          }
        ]
      }
    ]

    nodoc_data = [
      {
        'name': 'A',
        'nodoc': True
      },
      {
        'name': 'B',
        'list': [
          {
            'name': 'B1',
            'nodoc': True
          },
          {
            'name': 'B2'
          },
          {
            'name': 'B3',
            'nodoc': True
          }
        ]
      },
      {
        'name': 'C',
        'nodoc': True
      },
      {
        'name': 'D',
        'nodoc': False
      },
      {
        'name': 'E',
        'dict': {
          'name': 'Ed',
          'nodoc': True
        },
        'items1': [
          {
            'name': 'E1',
            'items': [
              {
                'name': 'E1.1',
                'nodoc': True
              },
              {
                'name': 'E1.2',
                'nodoc': True
              },
              {
                'name': 'E1.3'
              }
            ]
          },
          {
            'name': 'E2'
          },
          {
            'name': 'E3',
            'nodoc': True
          }
        ]
      }
    ]

    object_store_creator = ObjectStoreCreator(start_empty=False)
    host_file_system_provider = HostFileSystemProvider(object_store_creator)
    schema_processor = SchemaProcessor(_FakeReferenceResolver(),
                                       _FakeAPIModels(),
                                       _FakeFeaturesBundle(),
                                       CompiledFileSystem.Factory(
                                           object_store_creator),
                                       host_file_system_provider.GetMaster(),
                                       True)
    schema_processor._RemoveNoDocs(nodoc_data)
    self.assertEquals(expected_nodoc, nodoc_data)
Ejemplo n.º 13
0
  def testInlineDocs(self):
    schema = {
      'namespace': 'storage',
      'properties': {
        'key2': {
          'description': 'second key',
          '$ref': 'Key'
        },
        'key1': {
          'description': 'first key',
          '$ref': 'Key'
        }
      },
      'types': [
        {
          'inline_doc': True,
          'type': 'string',
          'id': 'Key',  # Should be inlined into both properties and be removed
                        # from types.
          'description': 'This is a key.',  # This description should disappear.
          'marker': True  # This should appear three times in the output.
        },
        {
          'items': {
            '$ref': 'Key'
          },
          'type': 'array',
          'id': 'KeyList',
          'description': 'A list of keys'
        }
      ]
    }

    expected_schema = {
      'namespace': 'storage',
      'properties': {
        'key2': {
          'marker': True,
          'type': 'string',
          'description': 'second key'
        },
        'key1': {
          'marker': True,
          'type': 'string',
          'description': 'first key'
        }
      },
      'types': [
        {
          'items': {
            'marker': True,
            'type': 'string'
          },
          'type': 'array',
          'id': 'KeyList',
          'description': 'A list of keys'
        }
      ]
    }

    object_store_creator = ObjectStoreCreator(start_empty=False)
    host_file_system_provider = HostFileSystemProvider(object_store_creator)
    schema_processor = SchemaProcessor(_FakeReferenceResolver(),
                                       _FakeAPIModels(),
                                       _FakeFeaturesBundle(),
                                       CompiledFileSystem.Factory(
                                           object_store_creator),
                                       host_file_system_provider.GetMaster(),
                                       False)
    inlined_schema = deepcopy(schema)
    schema_processor._InlineDocs(inlined_schema)
    self.assertEqual(expected_schema, inlined_schema)