Example #1
0
def test_get_parent_resources_multi_pattern_fail():
    book = resource_pb2.ResourceDescriptor()
    book.type = 'test/Book'
    book.pattern.append("shelves/{shelf}/books/{book}")
    book.pattern.append("projects/{project}/books/{book}")

    parent = resource_pb2.ResourceDescriptor()
    parent.type = 'test/Parent'
    parent.pattern.append("shelves/{shelf}")

    book_parent = resource_pb2.ResourceDescriptor()
    book_parent.type = 'test/BookParent'
    book_parent.pattern.append("shelves/{shelf}")
    book_parent.pattern.append("projects/{project}")
    book_parent.pattern.append("projects/{project}/locations/{location}")

    pattern_map = {
        "shelves/{shelf}/books/{book}": [book],
        "projects/{project}/books/{book}": [book],
        "shelves/{shelf}": [parent],
    }
    all_resources = [book, parent]
    assert len(
        gapic_utils.get_parent_resources(book, pattern_map,
                                         all_resources)) == 0
Example #2
0
def test_get_parent_resources_single_pattern():
    book = resource_pb2.ResourceDescriptor()
    book.type = 'test/Book'
    book.pattern.append("shelves/{shelf}/books/{book}")

    shelf = resource_pb2.ResourceDescriptor()
    shelf.type = 'test/Shelf'
    shelf.pattern.append("shelves/{shelf}")

    pattern_map = {
        "shelves/{shelf}/books/{book}": [book],
        "shelves/{shelf}": [shelf]
    }
    assert shelf == gapic_utils.get_parent_resource(book, pattern_map)
Example #3
0
def test_get_parent_resources_multi_pattern():
    book = resource_pb2.ResourceDescriptor()
    book.type = 'test/Book'
    book.pattern.append("shelves/{shelf}/books/{book}")
    book.pattern.append("projects/{project}/books/{book}")

    shelf = resource_pb2.ResourceDescriptor()
    shelf.type = 'test/Shelf'
    shelf.pattern.append("shelves/{shelf}/books/{book}")

    parent = resource_pb2.ResourceDescriptor()
    parent.type = 'test/Parent'
    parent.pattern.append("shelves/{shelf}")
    parent.pattern.append("projects/{project}")

    pattern_map = {
        "shelves/{shelf}/books/{book}": [book],
        "projects/{project}/books/{book}": [book],
        "shelves/{shelf}": [parent],
        "projects/{project}": [parent]
    }
    assert parent == gapic_utils.get_parent_resource(book, pattern_map)
Example #4
0
def test_update_collections_single_pattern():
    res = resource_pb2.ResourceDescriptor()
    res.type = 'test/Book'
    res.pattern.append("shelves/{shelf}/books/{book}")

    collections = {}
    collection_oneofs = {}
    gapic_utils.update_collections(res, collections, collection_oneofs)
    assert collections == {
        'book': {
            'entity_name': 'book',
            'name_pattern': 'shelves/{shelf}/books/{book}'
        }
    }
    assert collection_oneofs == {}
Example #5
0
def test_get_parent_resources_multi_references():
    book = resource_pb2.ResourceDescriptor()
    book.type = 'test/Book'
    book.pattern.append("shelves/{shelf}/books/{book}")
    book.pattern.append("projects/{project}/books/{book}")

    shelf = resource_pb2.ResourceDescriptor()
    shelf.type = 'test/Shelf'
    shelf.pattern.append("shelves/{shelf}")

    project = resource_pb2.ResourceDescriptor()
    project.type = 'test/Project'
    project.pattern.append("projects/{project}")

    pattern_map = {
        "shelves/{shelf}/books/{book}": [book],
        "projects/{project}/books/{book}": [book],
        "shelves/{shelf}": [shelf],
        "projects/{project}": [project]
    }
    all_resources = [project, shelf, book]
    assert [project,
            shelf] == gapic_utils.get_parent_resources(book, pattern_map,
                                                       all_resources)
Example #6
0
def test_update_collections_with_deprecated_collections():
    book = resource_pb2.ResourceDescriptor()
    book.type = 'test/Book'
    book.pattern.append("shelves/{shelf}/books/{book}")
    book.pattern.append("archives/{archive}/books/{book}")

    gapic_v2 = {
        'interfaces': [{
            'deprecated_collections': [{
                'entity_name':
                'some_archive_book',
                'name_pattern':
                "archives/{archive}/books/{book}"
            }, {
                'entity_name':
                'my_shelf_book',
                'name_pattern':
                "shelves/{shelf}/books/{book}",
                'language_overrides': [{
                    'language': 'java',
                    'entity_name': 'shelf_book'
                }]
            }]
        }]
    }

    collection_oneofs = {
        'book_oneof': {
            'oneof_name': 'book_oneof',
            'collection_names': []
        }
    }
    pattern_map = {
        "archives/{archive}/books/{book}": [book],
        "shelves/{shelf}/books/{book}": [book]
    }

    gapic_utils.update_collections_with_deprecated_resources(
        gapic_v2, pattern_map, collection_oneofs)

    assert collection_oneofs == {
        'book_oneof': {
            'oneof_name': 'book_oneof',
            'collection_names': [],
            'has_deprecated_collections': True
        }
    }
Example #7
0
def test_update_collections_multi_pattern():
    res = resource_pb2.ResourceDescriptor()
    res.type = 'test/Book'
    res.pattern.append("shelves/{shelf}/books/{book}")
    res.pattern.append("archives/{archive}/books/{book}")

    collections = {}
    collection_oneofs = {}
    gapic_utils.update_collections(res, collections, collection_oneofs)
    assert collections == {}
    assert collection_oneofs == {
        'book_oneof': {
            'collection_names': [],
            'oneof_name':
            'book_oneof',
            'pattern_strings': [
                'shelves/{shelf}/books/{book}',
                'archives/{archive}/books/{book}'
            ]
        }
    }