Example #1
0
def po_box_manager():
    base_manager = MagqlTableManager(POBox.__table__, "POBox")
    base_manager.single_query_name = "POBox"
    base_manager.many_query_name = "POBoxes"
    base_manager.magql_types["POBox"].fields["customField"] = MagqlField(
        "Int", resolve=lambda x: 1)
    return base_manager
Example #2
0
def test_generated_field(model):
    table = model.__table__
    manager = MagqlTableManager(table)
    assert isinstance(manager.create, MagqlField)
    assert isinstance(manager.update, MagqlField)
    assert isinstance(manager.delete, MagqlField)
    assert isinstance(manager.single, MagqlField)
    assert isinstance(manager.many, MagqlField)
Example #3
0
def test_generated_names(model):
    table = model.__table__
    manager = MagqlTableManager(table)

    assert manager.single_query_name == camelize(table.name, False)
    assert manager.many_query_name == camelize(pluralize(table.name), False)
    assert manager.create_mutation_name == "create" + manager.magql_name
    assert manager.update_mutation_name == "update" + manager.magql_name
    assert manager.delete_mutation_name == "delete" + manager.magql_name
Example #4
0
def test_default_table_manager(model):
    table = model.__table__
    table_name = model.__tablename__
    manager = MagqlTableManager(table)
    assert model is manager.table_class
    assert table is manager.table
    assert camelize(table_name) == manager.table_name
    assert table_name == manager.table_name
    check_magql_types(manager)
Example #5
0
def test_generated_field_resolvers(model):
    table = model.__table__
    manager = MagqlTableManager(table)

    assert isinstance(manager.single.resolve, SingleResolver)
    assert isinstance(manager.many.resolve, ManyResolver)
    assert isinstance(manager.create.resolve, CreateResolver)
    assert isinstance(manager.update.resolve, UpdateResolver)
    assert isinstance(manager.delete.resolve, DeleteResolver)
Example #6
0
def test_generated_field_name(model):
    table = model.__table__
    manager = MagqlTableManager(table)

    assert manager.single.type_name == manager.magql_name + "Payload"
    assert manager.many.type_name == manager.magql_name + "ListPayload"
    assert manager.create.type_name == manager.magql_name + "Payload"
    assert manager.update.type_name == manager.magql_name + "Payload"
    assert manager.delete.type_name == manager.magql_name + "Payload"
Example #7
0
def test_generated_field_delete_resolver_arguments(model):
    table = model.__table__
    manager = MagqlTableManager(table)

    delete = manager.delete

    assert "id" in delete.args
    assert isinstance(delete.args["id"], MagqlArgument)
    assert isinstance(delete.args["id"].type_, MagqlNonNull)
    assert delete.args["id"].type_.type_ == "Int"
Example #8
0
def test_generated_field_create_resolver_arguments(model):
    table = model.__table__
    manager = MagqlTableManager(table)

    create = manager.create

    assert "input" in create.args
    assert isinstance(create.args["input"], MagqlArgument)
    assert isinstance(create.args["input"].type_, MagqlNonNull)
    assert create.args["input"].type_.type_ == manager.magql_name + "InputRequired"
Example #9
0
def test_generated_field_update_resolver_arguments(model):
    table = model.__table__
    manager = MagqlTableManager(table)

    update = manager.update

    assert "input" in update.args
    assert isinstance(update.args["input"], MagqlArgument)
    assert isinstance(update.args["input"].type_, MagqlNonNull)
    assert update.args["input"].type_.type_ == manager.magql_name + "Input"

    assert "id" in update.args
    assert isinstance(update.args["id"], MagqlArgument)
    assert isinstance(update.args["id"].type_, MagqlNonNull)
    assert update.args["id"].type_.type_ == "Int"
Example #10
0
def test_resolver_overrides(model):
    table = model.__table__
    manager = MagqlTableManager(
        table,
        None,
        CreateResolverOverride(table),
        UpdateResolverOverride(table),
        DeleteResolverOverride(table),
        SingleResolverOverride(table),
        ManyResolverOverride(table),
    )
    assert isinstance(manager.create.resolve, CreateResolverOverride)
    assert isinstance(manager.update.resolve, UpdateResolverOverride)
    assert isinstance(manager.delete.resolve, DeleteResolverOverride)
    assert isinstance(manager.single.resolve, SingleResolverOverride)
    assert isinstance(manager.many.resolve, ManyResolverOverride)
Example #11
0
def test_generated_field_many_resolver_arguments(model):
    table = model.__table__
    manager = MagqlTableManager(table)

    many = manager.many

    assert "filter" in many.args
    assert "sort" in many.args

    assert isinstance(many.args["filter"], MagqlArgument)
    assert many.args["filter"].type_ == manager.magql_name + "Filter"

    assert isinstance(many.args["sort"], MagqlArgument)
    assert isinstance(many.args["sort"].type_, MagqlList)
    assert isinstance(many.args["sort"].type_.type_, MagqlNonNull)
    assert many.args["sort"].type_.type_.type_ == manager.magql_name + "Sort"
Example #12
0
def test_magql_name_override(model):
    table = model.__table__
    magql_name = model.__tablename__ + "Override"
    manager = MagqlTableManager(table, magql_name)
    assert magql_name == manager.magql_name
    check_magql_types(manager)