예제 #1
0
def test_tokenizer_parser_test_2():
    query = '''
        query Sample {
            id
            tube {
                name [* == 'only-this-tube']
                self_tube {
                    name [* == 'only-this-tube-self-tube']
                }
            }
            self_sample {
                name [* == 'only-this-self-sample']
                tube {
                    self_tube {
                        name [* == 'only-this-self-sample-tube-self-tube']
                    }
                }
            }
        }
    '''
    assert tuple(tokenize(query)) == (
        Toks.RootQueryToken(query_model='Sample'),
        Toks.AttributeToken(attribute_name='id'),
        Toks.OpenObjectToken(rel='tube'),
        Toks.AttributeToken(attribute_name='name'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*', op='==', val='only-this-tube'),
        Toks.FilterEndToken(),
        Toks.OpenObjectToken(rel='self_tube'),
        Toks.AttributeToken(attribute_name='name'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*', op='==', val='only-this-tube-self-tube'),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
        Toks.CloseObjectToken(),
        Toks.OpenObjectToken(rel='self_sample'),
        Toks.AttributeToken(attribute_name='name'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*', op='==', val='only-this-self-sample'),
        Toks.FilterEndToken(),
        Toks.OpenObjectToken(rel='tube'),
        Toks.OpenObjectToken(rel='self_tube'),
        Toks.AttributeToken(attribute_name='name'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*',
                             op='==',
                             val='only-this-self-sample-tube-self-tube'),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
        Toks.CloseObjectToken(),
        Toks.CloseObjectToken(),
        Toks.CloseObjectToken(),
    )
예제 #2
0
def test_tokenizer_filters5():
    query = '''
       query Sample {
         field1 [((* == 4) and (* <= 3)) or (* != 9)]
       }
    '''
    assert tuple(tokenize(query)) == (
        Toks.RootQueryToken(query_model='Sample'),
        Toks.AttributeToken(attribute_name='field1'),
        Toks.FilterStartToken(),
        Toks.FilterOpenParanToken(),
        Toks.FilterOpenParanToken(),
        Toks.FilterBoolToken(sel='*', op='==', val=4),
        Toks.FilterCloseParanToken(),
        Toks.FilterBinaryLogicToken(logic_op='and'),
        Toks.FilterOpenParanToken(),
        Toks.FilterBoolToken(sel='*', op='<=', val=3),
        Toks.FilterCloseParanToken(),
        Toks.FilterCloseParanToken(),
        Toks.FilterBinaryLogicToken(logic_op='or'),
        Toks.FilterOpenParanToken(),
        Toks.FilterBoolToken(sel='*', op='!=', val=9),
        Toks.FilterCloseParanToken(),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
    )
예제 #3
0
def test_tokenizer_parser_test_1():
    query = '''
        query Sample {
            id
            tube {
                name
                type [any in ['a', 'b'] or all != 'c']
            }
            date [((* < '3/9/2017') or * == '3/3/2017') and ((* > '3/10/2017'))]
        }
    '''
    assert tuple(tokenize(query)) == (
        Toks.RootQueryToken(query_model='Sample'),
        Toks.AttributeToken(attribute_name='id'),
        Toks.OpenObjectToken(rel='tube'),
        Toks.AttributeToken(attribute_name='name'),
        Toks.AttributeToken(attribute_name='type'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='any', op='in', val=['a', 'b']),
        Toks.FilterBinaryLogicToken(logic_op='or'),
        Toks.FilterBoolToken(sel='all', op='!=', val='c'),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
        Toks.AttributeToken(attribute_name='date'),
        Toks.FilterStartToken(),
        Toks.FilterOpenParanToken(),
        Toks.FilterOpenParanToken(),
        Toks.FilterBoolToken(sel='*', op='<', val='3/9/2017'),
        Toks.FilterCloseParanToken(),
        Toks.FilterBinaryLogicToken(logic_op='or'),
        Toks.FilterBoolToken(sel='*', op='==', val='3/3/2017'),
        Toks.FilterCloseParanToken(),
        Toks.FilterBinaryLogicToken(logic_op='and'),
        Toks.FilterOpenParanToken(),
        Toks.FilterOpenParanToken(),
        Toks.FilterBoolToken(sel='*', op='>', val='3/10/2017'),
        Toks.FilterCloseParanToken(),
        Toks.FilterCloseParanToken(),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
    )
예제 #4
0
def test_tokenizer_filters1():
    query = '''
       query Sample {
         field1 [* == 'hi']
       }
    '''
    assert tuple(tokenize(query)) == (
        Toks.RootQueryToken(query_model='Sample'),
        Toks.AttributeToken(attribute_name='field1'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*', op='==', val='hi'),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
    )
예제 #5
0
def test_tokenizer_subobject_filters2():
    query = '''
       query Sample {
         field1 [* in ['foo', 'bar']]
         tube {
           field2 [* == 3]
         }
       }
    '''
    assert tuple(tokenize(query)) == (
        Toks.RootQueryToken(query_model='Sample'),
        Toks.AttributeToken(attribute_name='field1'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*', op='in', val=['foo', 'bar']),
        Toks.FilterEndToken(),
        Toks.OpenObjectToken(rel='tube'),
        Toks.AttributeToken(attribute_name='field2'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*', op='==', val=3),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
        Toks.CloseObjectToken(),
    )
예제 #6
0
def test_tokenizer_filters7():
    query = '''
       query Sample {
         field1 [* in [true, false]]
       }
    '''
    assert tuple(tokenize(query)) == (
        Toks.RootQueryToken(query_model='Sample'),
        Toks.AttributeToken(attribute_name='field1'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*', op='in', val=[True, False]),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
    )
예제 #7
0
def test_tokenizer_filters2():
    query = '''
       query Sample {
         field1 [* == 4 and * <= 3]
       }
    '''
    assert tuple(tokenize(query)) == (
        Toks.RootQueryToken(query_model='Sample'),
        Toks.AttributeToken(attribute_name='field1'),
        Toks.FilterStartToken(),
        Toks.FilterBoolToken(sel='*', op='==', val=4),
        Toks.FilterBinaryLogicToken(logic_op='and'),
        Toks.FilterBoolToken(sel='*', op='<=', val=3),
        Toks.FilterEndToken(),
        Toks.CloseObjectToken(),
    )
예제 #8
0
query Sample {
    id
    tube {
        name
        type [any in ['a', 'b'] or all != 'c']
    }
    date [((* < '3/9/2017') or * == '3/3/2017') and ((* > '3/10/2017'))]
}
"""
test_token_gen_1 = (x for x in (
    Toks.RootQueryToken(query_model='Sample'),
    Toks.AttributeToken(attribute_name='id'),
    Toks.OpenObjectToken(rel='tube'),
    Toks.AttributeToken(attribute_name='name'),
    Toks.AttributeToken(attribute_name='type'),
    Toks.FilterStartToken(),
    Toks.FilterBoolToken(sel='any', op='in', val=['a', 'b']),
    Toks.FilterBinaryLogicToken(logic_op='or'),
    Toks.FilterBoolToken(sel='all', op='!=', val='c'),
    Toks.FilterEndToken(),
    Toks.CloseObjectToken(),
    Toks.AttributeToken(attribute_name='date'),
    Toks.FilterStartToken(),
    Toks.FilterOpenParanToken(),
    Toks.FilterOpenParanToken(),
    Toks.FilterBoolToken(sel='*', op='<', val='3/9/2017'),
    Toks.FilterCloseParanToken(),
    Toks.FilterBinaryLogicToken(logic_op='or'),
    Toks.FilterBoolToken(sel='*', op='==', val='3/3/2017'),
    Toks.FilterCloseParanToken(),
    Toks.FilterBinaryLogicToken(logic_op='and'),