def test_double_traverse(): nescafe = Coffee(name='Nescafe plus', price=99).save() tesco = Supplier(name='Asda', delivery_cost=2).save() nescafe.suppliers.connect(tesco) tesco.coffees.connect(Coffee(name='Decafe', price=2).save()) ns = NodeSet(NodeSet(source=nescafe).suppliers.match()).coffees.match() qb = QueryBuilder(ns).build_ast() results = qb._execute() assert len(results) == 1 assert results[0].name == 'Decafe'
def test_simple_has_via_label(): nescafe = Coffee(name='Nescafe', price=99).save() tesco = Supplier(name='Tesco', delivery_cost=2).save() nescafe.suppliers.connect(tesco) ns = NodeSet(Coffee).has(suppliers=True) qb = QueryBuilder(ns).build_ast() results = qb._execute() assert 'SUPPLIES' in qb._ast['where'][0] assert len(results) == 1 assert results[0].name == 'Nescafe' Coffee(name='nespresso', price=99).save() ns = NodeSet(Coffee).has(suppliers=False) qb = QueryBuilder(ns).build_ast() results = qb._execute() assert len(results) > 0 assert 'NOT' in qb._ast['where'][0]
def test_simple_has_via_label(): nescafe = Coffee(name="Nescafe", price=99).save() tesco = Supplier(name="Tesco", delivery_cost=2).save() nescafe.suppliers.connect(tesco) ns = NodeSet(Coffee).has(suppliers=True) qb = QueryBuilder(ns).build_ast() results = qb._execute() assert "COFFEE SUPPLIERS" in qb._ast["where"][0] assert len(results) == 1 assert results[0].name == "Nescafe" Coffee(name="nespresso", price=99).save() ns = NodeSet(Coffee).has(suppliers=False) qb = QueryBuilder(ns).build_ast() results = qb._execute() assert len(results) > 0 assert "NOT" in qb._ast["where"][0]
def test_simple_traverse_with_filter(): nescafe = Coffee(name='Nescafe2', price=99).save() tesco = Supplier(name='Sainsburys', delivery_cost=2).save() nescafe.suppliers.connect(tesco) qb = QueryBuilder(NodeSet(source=nescafe).suppliers.match(since__lt=datetime.now())) results = qb.build_ast()._execute() assert 'start' in qb._ast assert 'match' in qb._ast assert qb._ast['return'] == 'suppliers' assert len(results) == 1 assert results[0].name == 'Sainsburys'
def test_filter_exclude_via_labels(): Coffee(name='Java', price=99).save() node_set = NodeSet(Coffee) qb = QueryBuilder(node_set).build_ast() results = qb._execute() assert '(coffee:Coffee)' in qb._ast['match'] assert 'result_class' in qb._ast assert len(results) == 1 assert isinstance(results[0], Coffee) assert results[0].name == 'Java' # with filter and exclude Coffee(name='Kenco', price=3).save() node_set = node_set.filter(price__gt=2).exclude(price__gt=6, name='Java') qb = QueryBuilder(node_set).build_ast() results = qb._execute() assert '(coffee:Coffee)' in qb._ast['match'] assert 'NOT' in qb._ast['where'][0] assert len(results) == 1 assert results[0].name == 'Kenco'
def test_simple_traverse_with_filter(): nescafe = Coffee(name="Nescafe2", price=99).save() tesco = Supplier(name="Sainsburys", delivery_cost=2).save() nescafe.suppliers.connect(tesco) qb = QueryBuilder( NodeSet(source=nescafe).suppliers.match(since__lt=datetime.now())) results = qb.build_ast()._execute() assert "lookup" in qb._ast assert "match" in qb._ast assert qb._ast["return"] == "suppliers" assert len(results) == 1 assert results[0].name == "Sainsburys"
def test_filter_exclude_via_labels(): Coffee(name="Java", price=99).save() node_set = NodeSet(Coffee) qb = QueryBuilder(node_set).build_ast() results = qb._execute() assert "(coffee:Coffee)" in qb._ast["match"] assert "result_class" in qb._ast assert len(results) == 1 assert isinstance(results[0], Coffee) assert results[0].name == "Java" # with filter and exclude Coffee(name="Kenco", price=3).save() node_set = node_set.filter(price__gt=2).exclude(price__gt=6, name="Java") qb = QueryBuilder(node_set).build_ast() results = qb._execute() assert "(coffee:Coffee)" in qb._ast["match"] assert "NOT" in qb._ast["where"][0] assert len(results) == 1 assert results[0].name == "Kenco"
def test_filter_exclude_via_labels(): Coffee(name='Java', price=99).save() node_set = NodeSet(Coffee) qb = QueryBuilder(node_set).build_ast() results = qb._execute() assert '(coffee:Coffee)' in qb._ast['match'] assert 'result_class' in qb._ast assert len(results) == 1 assert isinstance(results[0], Coffee) assert results[0].name == 'Java' # with filter and exclude Coffee(name='Kenco', price=3).save() node_set = node_set.filter(price__gt=2).exclude(price__gt=6, name='Java') qb = QueryBuilder(node_set).build_ast() results = qb._execute() assert '(coffee:Coffee)' in qb._ast['match'] assert 'NOT' in qb._ast['where'][0] assert len(results) == 1 assert results[0].name == 'Kenco'
def test_traversal_filter_left_hand_statement(): nescafe = Coffee(name='Nescafe2', price=99).save() nescafe_gold = Coffee(name='Nescafe gold', price=11).save() tesco = Supplier(name='Sainsburys', delivery_cost=3).save() biedronka = Supplier(name='Biedronka', delivery_cost=5).save() lidl = Supplier(name='Lidl', delivery_cost=3).save() nescafe.suppliers.connect(tesco) nescafe_gold.suppliers.connect(biedronka) nescafe_gold.suppliers.connect(lidl) lidl_supplier = NodeSet( Coffee.nodes.filter(price=11).suppliers).filter(delivery_cost=3).all() assert lidl in lidl_supplier
def test_count(): Coffee(name='Nescafe Gold', price=99).save() count = QueryBuilder(NodeSet(source=Coffee)).build_ast()._count() assert count > 0