def test_service_name_colliding_modules():
    service = make_service(name='ThingDoer', methods=(
        get_method('DoThing', 'foo.bar.ThingRequest', 'foo.bar.ThingResponse'),
        get_method('Jump', 'bacon.bar.JumpRequest', 'bacon.bar.JumpResponse'),
        get_method('Yawn', 'a.b.v1.c.YawnRequest', 'a.b.v1.c.YawnResponse'),
    ))
    expected_names = {'ThingDoer', 'ThingDoerClient', 'ThingDoerAsyncClient',
                      'do_thing', 'jump', 'yawn', 'bar'}
    assert service.names == expected_names
Пример #2
0
def test_has_pagers():
    paged = make_field(name='foos', message=make_message('Foo'), repeated=True)
    input_msg = make_message(
        name='ListFoosRequest',
        fields=(
            make_field(name='parent', type=9),  # str
            make_field(name='page_size', type=5),  # int
            make_field(name='page_token', type=9),  # str
        ),
    )
    output_msg = make_message(
        name='ListFoosResponse',
        fields=(
            paged,
            make_field(name='next_page_token', type=9),  # str
        ),
    )
    method = make_method(
        'ListFoos',
        input_message=input_msg,
        output_message=output_msg,
    )

    service = make_service(
        name="Fooer",
        methods=(method, ),
    )
    assert service.has_pagers

    other_service = make_service(
        name="Unfooer",
        methods=(get_method("Unfoo", "foo.bar.UnfooReq",
                            "foo.bar.UnFooResp"), ),
    )
    assert not other_service.has_pagers
Пример #3
0
def test_service_python_modules():
    service = make_service(methods=(
        get_method('DoThing', 'foo.bar.ThingRequest', 'foo.baz.ThingResponse'),
        get_method('Jump', 'foo.bacon.JumpRequest', 'foo.bacon.JumpResponse'),
        get_method('Yawn', 'a.b.v1.c.YawnRequest', 'x.y.v1.z.YawnResponse'),
    ))
    imports = {
        i.ident.python_import
        for m in service.methods.values() for i in m.ref_types
    }
    assert imports == {
        imp.Import(package=('a', 'b', 'v1'), module='c'),
        imp.Import(package=('foo', ), module='bacon'),
        imp.Import(package=('foo', ), module='bar'),
        imp.Import(package=('foo', ), module='baz'),
        imp.Import(package=('x', 'y', 'v1'), module='z'),
    }