Exemplo n.º 1
0
def test_compiler_chained_mutations(patch, magic, tree):
    patch.object(Objects, 'mutation_fragment')
    mutation = magic()
    tree.find_data.return_value = [mutation]
    result = JSONCompiler(story=None).chained_mutations(tree)
    Objects.mutation_fragment.assert_called_with(mutation.mutation_fragment)
    assert result == [Objects.mutation_fragment()]
Exemplo n.º 2
0
def test_compiler_mutation_block_nested(patch, compiler, lines, tree):
    patch.many(Objects, ['expression', 'mutation_fragment'])
    patch.object(JSONCompiler, 'chained_mutations', return_value=['chained'])
    tree.path = None
    compiler.mutation_block(tree, None)
    JSONCompiler.chained_mutations.assert_called_with(tree.nested_block)
    args = [Objects.expression(), Objects.mutation_fragment(),
            'chained', 'chained']
    kwargs = {'args': args, 'parent': None}
    lines.append.assert_called_with('mutation', tree.position(), **kwargs)
Exemplo n.º 3
0
def test_compiler_mutation_block_from_service(patch, compiler, lines, tree):
    patch.many(Objects, ['path', 'mutation_fragment'])
    patch.object(JSONCompiler, 'chained_mutations', return_value=['chained'])
    tree.nested_block = None
    tree.data = 'mutation_block'
    compiler.mutation_block(tree, None)
    Objects.path.assert_called_with(tree.path)
    Objects.mutation_fragment.assert_called_with(tree.mutation_fragment)
    JSONCompiler.chained_mutations.assert_called_with(tree)
    args = [Objects.path(), Objects.mutation_fragment(), 'chained']
    kwargs = {'args': args, 'parent': None}
    lines.append.assert_called_with('mutation', tree.position(), **kwargs)
Exemplo n.º 4
0
def test_compiler_mutation_block_from_service(patch, compiler, lines, tree):
    patch.many(Objects, ["path", "mutation_fragment"])
    patch.object(JSONCompiler, "chained_mutations", return_value=["chained"])
    tree.nested_block = None
    tree.data = "mutation_block"
    compiler.mutation_block(tree, None)
    Objects.path.assert_called_with(tree.path)
    Objects.mutation_fragment.assert_called_with(tree.mutation_fragment)
    JSONCompiler.chained_mutations.assert_called_with(tree)
    args = [Objects.path(), Objects.mutation_fragment(), "chained"]
    kwargs = {"args": args, "parent": None}
    lines.append.assert_called_with("mutation", tree.position(), **kwargs)
Exemplo n.º 5
0
def test_compiler_mutation_block_nested(patch, compiler, lines, tree):
    patch.many(Objects, ["expression", "mutation_fragment"])
    patch.object(JSONCompiler, "chained_mutations", return_value=["chained"])
    tree.path = None
    compiler.mutation_block(tree, None)
    JSONCompiler.chained_mutations.assert_called_with(tree.nested_block)
    args = [
        Objects.expression(),
        Objects.mutation_fragment(),
        "chained",
        "chained",
    ]
    kwargs = {"args": args, "parent": None}
    lines.append.assert_called_with("mutation", tree.position(), **kwargs)
Exemplo n.º 6
0
def test_compiler_mutation_block(patch, compiler, lines, tree):
    patch.many(Objects, ['primary_expression', 'mutation_fragment'])
    patch.object(JSONCompiler, 'chained_mutations', return_value=['chained'])
    tree.path = None
    tree.nested_block = None
    compiler.mutation_block(tree, None)
    expr = tree.mutation.primary_expression
    Objects.primary_expression.assert_called_with(expr)
    Objects.mutation_fragment.assert_called_with(
        tree.mutation.mutation_fragment)
    JSONCompiler.chained_mutations.assert_called_with(tree.mutation)
    args = [
        Objects.primary_expression(),
        Objects.mutation_fragment(), 'chained'
    ]
    kwargs = {'args': args, 'parent': None}
    lines.append.assert_called_with('mutation', tree.line(), **kwargs)
Exemplo n.º 7
0
def test_compiler_extract_values_mutation(patch, tree):
    patch.many(Objects, ['values', 'mutation_fragment'])
    result = JSONCompiler(story=None).extract_values(tree)
    Objects.values.assert_called_with(tree.expression.values)
    Objects.mutation_fragment.assert_called_with(tree.expression.mutation)
    assert result == [Objects.values(), Objects.mutation_fragment()]