示例#1
0
 def test_mixed(self):
     # build where clause
     _and = and_(['name = \'snake\''])
     _or = or_(['category = \'reptile\'', 'category = \'amphibian\''])
     _mixed = and_([_and, _or])
     # serialize
     _c = _mixed.serialize()
     # test
     assert _c == '(name = \'snake\') and'\
             ' (category = \'reptile\' or category = \'amphibian\')',\
             'or_ found: %s' % _c
示例#2
0
def _test_select(connector, uri):
    # ...
    __set_data(connector, uri)

    # check select
    _r = connector.select("animal", column_list=["category"], order_list=["category"], uri=uri)
    # check select
    assert _r == [u"amphibian", u"reptile"], "select found: %s" % _r

    # check select
    _r = connector.select("animal", column_list=["category"], order_list=["category"], order="desc", uri=uri)
    # check select
    assert _r == [u"reptile", u"amphibian"], "select found: %s" % _r

    # check select
    _r = connector.select("animal", column_list=["name"], where=and_(["name='snake'", "category='reptile'"]), uri=uri)
    # check select
    assert _r == [u"snake"], "select found: %s" % _r

    # check select
    _r = connector.select("animal", column_list=["category"], where=or_(["name='snake'", "name='frog'"]), uri=uri)
    # check select
    assert _r == [u"reptile", u"amphibian"], "select found: %s" % _r

    # check eager_select
    _generator = connector.eager_select(
        "animal", column_list=["category"], where=or_(["name='snake'", "name='frog'"]), uri=uri
    )
    # check eager_select
    _all = [_r for _c, _r in _generator]
    assert _all == [u"reptile", u"amphibian"], "eager_select found: %s" % _all
示例#3
0
def _test_update(connector, uri):
    # ...
    __set_data(connector, uri)

    # udpate something
    _r = connector.update("animal", column_list=["category"], values=["test"], where=and_(["name = 'frog'"]), uri=uri)

    # check count
    _r = connector.count("animal", where=and_(["category = 'test'"]), uri=uri)
    # check count
    assert _r == 1, "count found: %s" % _r

    # check count
    _r = connector.count("animal", where=and_(["category = 'amphibian'"]), uri=uri)
    # check count
    assert _r == 0, "count found: %s" % _r
示例#4
0
 def test_and(self):
     # build where clause
     _and = and_(['name = \'snake\'', 'category = \'reptile\''])
     # serialize
     _c = _and.serialize()
     # test
     assert _c == 'name = \'snake\' and category = \'reptile\'',\
             'and_ found: %s' % _c
示例#5
0
def _test_count(connector, uri):
    # ...
    __set_data(connector, uri)

    # check count
    _r = connector.count("animal", uri=uri)
    # check count
    assert _r == 2, "count found: %s" % _r

    # check count
    _r = connector.count("animal", where=and_(["name = 'snake'"]), uri=uri)
    # check count
    assert _r == 1, "count found: %s" % _r
示例#6
0
def _test_delete(connector, uri):
    # ...
    __set_data(connector, uri)

    # check delete
    _r = connector.delete("animal", where=and_(["name = 'frog'"]), uri=uri)
    # check delete
    assert _r == 1, "delete found: %s" % _r

    # check select
    _r = connector.select("animal", column_list=["category"], where=and_(["name = 'snake'"]), uri=uri)
    # check select
    assert _r == [u"reptile"], "select found: %s" % _r

    # check delete all
    _r = connector.delete("animal", uri=uri)
    # check delete
    assert _r == 1, "delete found: %s" % _r

    # check count
    _r = connector.count("animal", uri=uri)
    # check count
    assert _r == 0, "count found: %s" % _r