예제 #1
0
  def test_update_indexes(self):
    metadata = """{
      "full_name": "full-name"
    }"""
    collection_library_key = Library(id='my/collection', status=Status.ready, kind='collection', metadata=metadata).put()
    collection_version_key = Version(id='v1.0.0', parent=collection_library_key, sha='sha', status=Status.ready).put()
    Content(id='bower', parent=collection_version_key, content="""{"dependencies": {
      "a": "org/element-1#1.0.0",
      "b": "org/element-2#1.0.0"
    }}""").put()
    VersionCache.update(collection_library_key)

    response = self.app.get(util.update_indexes_task('my', 'collection'), headers={'X-AppEngine-QueueName': 'default'})
    self.assertEqual(response.status_int, 200)

    # Triggers ingestions
    tasks = self.tasks.get_filtered_tasks()
    self.assertEqual([
        util.ensure_library_task('org', 'element-1'),
        util.ensure_library_task('org', 'element-2'),
    ], [task.url for task in tasks])

    # Ensures collection references
    ref1 = CollectionReference.get_by_id(id="my/collection/v1.0.0", parent=ndb.Key(Library, "org/element-1"))
    self.assertIsNotNone(ref1)

    ref2 = CollectionReference.get_by_id(id="my/collection/v1.0.0", parent=ndb.Key(Library, "org/element-2"))
    self.assertIsNotNone(ref2)

    # Validate search index
    index = search.Index('repo')
    document = index.get('my/collection')
    self.assertIsNotNone(document)
    self.assertTrue(len(document.fields) > 0)
예제 #2
0
  def test_update_indexes(self):
    metadata = """{
      "full_name": "full-name"
    }"""
    collection_library_key = Library(id='my/collection', status=Status.ready, kind='collection', metadata=metadata).put()
    collection_version_key = Version(id='v1.0.0', parent=collection_library_key, sha='sha', status=Status.ready).put()
    Content(id='bower', parent=collection_version_key, content="""{"dependencies": {
      "a": "org/element-1#1.0.0",
      "b": "org/element-2#1.0.0"
    }}""").put()
    VersionCache.update(collection_library_key)

    response = self.app.get(util.update_indexes_task('my', 'collection'), headers={'X-AppEngine-QueueName': 'default'})
    self.assertEqual(response.status_int, 200)

    # Triggers ingestions
    tasks = self.tasks.get_filtered_tasks()
    self.assertEqual([
        util.ensure_library_task('org', 'element-1'),
        util.ensure_library_task('org', 'element-2'),
    ], [task.url for task in tasks])

    # Ensures collection references
    ref1 = CollectionReference.get_by_id(id="my/collection/v1.0.0", parent=ndb.Key(Library, "org/element-1"))
    self.assertIsNotNone(ref1)

    ref2 = CollectionReference.get_by_id(id="my/collection/v1.0.0", parent=ndb.Key(Library, "org/element-2"))
    self.assertIsNotNone(ref2)
예제 #3
0
파일: manage.py 프로젝트: andymutton/v2
  def update_collection_dependencies(self, collection_version_key, bower):
    dependencies = bower.get('dependencies', {})
    for name in dependencies.keys():
      dep = Dependency.from_string(dependencies[name])
      if dep is None:
        continue
      library_key = ndb.Key(Library, Library.id(dep.owner, dep.repo))
      CollectionReference.ensure(library_key, collection_version_key, semver=dep.version)

      task_url = util.ensure_library_task(dep.owner.lower(), dep.repo.lower())
      util.new_task(task_url, target='manage')
예제 #4
0
  def update_collection_dependencies(self, collection_version_key, bower):
    dependencies = bower.get('dependencies', {})
    for name in dependencies.keys():
      dep = Dependency.from_string(dependencies[name])
      if dep is None:
        continue
      library_key = ndb.Key(Library, Library.id(dep.owner, dep.repo))
      CollectionReference.ensure(library_key, collection_version_key, semver=dep.version)

      task_url = util.ensure_library_task(dep.owner.lower(), dep.repo.lower())
      util.new_task(task_url, target='manage')
예제 #5
0
    def test_latest_matching_collection_version_is_returned(self):
        collection_key = ndb.Key(Library, 'collection/1')
        collection_v1 = Version(id='v1.0.0',
                                sha='x',
                                status=Status.ready,
                                parent=collection_key).put()
        collection_v2 = Version(id='v2.0.0',
                                sha='x',
                                status=Status.ready,
                                parent=collection_key).put()
        collection_v3 = Version(id='v3.0.0',
                                sha='x',
                                status=Status.ready,
                                parent=collection_key).put()

        element_key = ndb.Key(Library, 'ele/ment')
        element_v1 = Version(id='v1.0.0',
                             sha='x',
                             status=Status.ready,
                             parent=element_key).put()

        CollectionReference.ensure(element_key, collection_v1, '^1.0.0')
        CollectionReference.ensure(element_key, collection_v2, '^1.0.0')
        CollectionReference.ensure(element_key, collection_v3, '^2.0.0')

        collections = yield Version.collections_for_key_async(element_v1)
        collection_keys = [collection.key for collection in collections]

        # Only latest matching version of the collection should be present.
        self.assertEqual(collection_keys, [
            collection_v2,
        ])
예제 #6
0
  def test_stale_ref_is_removed(self):
    # Stale since the collection version doesn't actually exist.
    collection_v0 = ndb.Key(Library, 'collection/1', Version, 'v0.5.0')

    element_key = ndb.Key(Library, 'ele/ment')
    element_v1 = Version(id='v1.0.0', sha='x', status=Status.ready, parent=element_key).put()

    ref0 = CollectionReference.ensure(element_key, collection_v0, '^1.0.0')
    collections = yield Version.collections_for_key_async(element_v1)
    collection_keys = [collection.key for collection in collections]

    self.assertIsNone(ref0.get())
    self.assertEqual(collection_keys, [])
예제 #7
0
    def test_stale_ref_is_removed(self):
        # Stale since the collection version doesn't actually exist.
        collection_v0 = ndb.Key(Library, 'collection/1', Version, 'v0.5.0')

        element_key = ndb.Key(Library, 'ele/ment')
        element_v1 = Version(id='v1.0.0',
                             sha='x',
                             status=Status.ready,
                             parent=element_key).put()

        ref0 = CollectionReference.ensure(element_key, collection_v0, '^1.0.0')
        collections = yield Version.collections_for_key_async(element_v1)
        collection_keys = [collection.key for collection in collections]

        self.assertIsNone(ref0.get())
        self.assertEqual(collection_keys, [])
예제 #8
0
  def test_latest_matching_collection_version_is_returned(self):
    collection_key = ndb.Key(Library, 'collection/1')
    collection_v1 = Version(id='v1.0.0', sha='x', status=Status.ready, parent=collection_key).put()
    collection_v2 = Version(id='v2.0.0', sha='x', status=Status.ready, parent=collection_key).put()
    collection_v3 = Version(id='v3.0.0', sha='x', status=Status.ready, parent=collection_key).put()

    element_key = ndb.Key(Library, 'ele/ment')
    element_v1 = Version(id='v1.0.0', sha='x', status=Status.ready, parent=element_key).put()

    CollectionReference.ensure(element_key, collection_v1, '^1.0.0')
    CollectionReference.ensure(element_key, collection_v2, '^1.0.0')
    CollectionReference.ensure(element_key, collection_v3, '^2.0.0')

    collections = yield Version.collections_for_key_async(element_v1)
    collection_keys = [collection.key for collection in collections]

    # Only latest matching version of the collection should be present.
    self.assertEqual(collection_keys, [
        collection_v2,
    ])