Example #1
0
def test_id_order(sheraf_connection, m0, m1, m2):
    assert [m0, m1, m2] == Cowboy.all()
    assert [m0, m1, m2] == Cowboy.order(sheraf.ASC)
    assert [m2, m1, m0] == Cowboy.order(sheraf.DESC)
    assert [m0, m1, m2] == Cowboy.all().order(sheraf.ASC)
    assert [m2, m1, m0] == Cowboy.all().order(sheraf.DESC)

    assert [m0, m1, m2] == QuerySet([m0, m1, m2]).order(id=sheraf.ASC)
    assert [m2, m1, m0] == QuerySet([m0, m1, m2]).order(id=sheraf.DESC)
Example #2
0
def test_slicing_iterator(sheraf_connection, m0, m1, m2):
    assert m0 == QuerySet(iter([m0, m1, m2]))[0]
    assert m2 == QuerySet(iter([m0, m1, m2]))[2]

    assert [m0, m1] == QuerySet(iter([m0, m1, m2]))[0:2]
    assert [m0] == QuerySet(iter([m0, m1, m2]))[0:1]

    assert [] == QuerySet(iter([m0, m1, m2]))[0:0]
    assert [] == QuerySet(iter([m0, m1, m2]))[2:2]
    assert [m0, m1, m2] == QuerySet(iter([m0, m1, m2]))[:]
    assert [m0, m2] == QuerySet(iter([m0, m1, m2]))[::2]
    assert [m0, m1, m2] == QuerySet(iter([m0, m1, m2]))[0:]
    assert [m2] == QuerySet(iter([m0, m1, m2]))[2:]
Example #3
0
def test_slicing_list_negative_values(sheraf_connection, m0, m1, m2):
    assert m2 == QuerySet([m0, m1, m2])[-1]

    assert [] == QuerySet([m0, m1, m2])[-1:-1]

    assert [m0, m1] == QuerySet([m0, m1, m2])[:-1]
    assert [m0, m1] == QuerySet([m0, m1, m2])[0:-1]
    assert [m1, m2] == QuerySet([m0, m1, m2])[-2:]
    assert [m1] == QuerySet([m0, m1, m2])[1:-1]
Example #4
0
def test_invalid_order_call(sheraf_connection, m0, m1, m2, m3):
    with pytest.raises(InvalidOrderException):
        Cowboy.order("foobar")

    with pytest.raises(InvalidOrderException):
        Cowboy.all().order("foobar")

    with pytest.raises(InvalidOrderException):
        Cowboy.all().order(sheraf.ASC).order(sheraf.DESC)

    with pytest.raises(InvalidOrderException):
        Cowboy.all().order(age=sheraf.ASC).order(age=sheraf.DESC)

    with pytest.raises(InvalidOrderException):
        Cowboy.all().order(age=sheraf.ASC).order(name=sheraf.DESC).order(
            age=sheraf.DESC)

    with pytest.raises(InvalidOrderException):
        Cowboy.order(age="foobar")

    with pytest.raises(InvalidOrderException):
        Cowboy.all().order(age="foobar")

    with pytest.raises(InvalidOrderException):
        Cowboy.order(foobar=sheraf.ASC)

    with pytest.raises(InvalidOrderException):
        list(Cowboy.all().order(foobar=sheraf.ASC))

    with pytest.raises(InvalidOrderException):
        QuerySet([Cowboy.create()]).order()

    with pytest.raises(InvalidOrderException):
        QuerySet([Cowboy.create()]).order(sheraf.ASC)

    with pytest.raises(InvalidOrderException):
        Cowboy.order(sheraf.ASC, sheraf.ASC)
Example #5
0
def test_slicing_iterator_negative_values(sheraf_connection, m0, m1, m2):
    with pytest.raises(ValueError):
        assert m2 == QuerySet(iter([m0, m1, m2]))[-1]

    with pytest.raises(ValueError):
        assert [m1] == QuerySet(iter([m0, m1, m2]))[1:-1]

    with pytest.raises(ValueError):
        assert [] == QuerySet(iter([m0, m1, m2]))[-1:-1]

    with pytest.raises(ValueError):
        assert [m0, m1] == QuerySet(iter([m0, m1, m2]))[:-1]

    with pytest.raises(ValueError):
        assert [m0, m1] == QuerySet(iter([m0, m1, m2]))[0:-1]

    with pytest.raises(ValueError):
        assert [m1, m2] == QuerySet(iter([m0, m1, m2]))[-2:]
Example #6
0
def test_filter_named_argument(sheraf_connection, m0, m1, m2):
    assert [m0, m2] == Cowboy.filter(age=30)
    assert QuerySet([m0, m2]) == Cowboy.filter(age=30)
    assert [m0] == Cowboy.filter(age=30, name="Peter")
Example #7
0
def test_repr(sheraf_connection, m0):
    assert str(Cowboy.all()).startswith("<QuerySet model=")
    assert str(QuerySet()) == "<QuerySet>"
    assert str(QuerySet(Cowboy.all())).startswith("<QuerySet iterable=")
Example #8
0
def test_create(sheraf_connection, m0):
    assert [m0] == Cowboy.filter(age=30)
    assert [] != Cowboy.filter(age=30)
    assert QuerySet([m0]) == Cowboy.filter(age=30)
    assert m0 in Cowboy.filter(age=30)
Example #9
0
def test_bool(sheraf_connection, m0):
    assert bool(QuerySet([m0])) is True
    assert bool(QuerySet()) is False
    assert bool(Cowboy.all()) is True
    assert bool(Cowboy.search(size=99)) is False
Example #10
0
def test_comparison(sheraf_connection, m0, m1, m2):
    assert QuerySet() is not None
    assert QuerySet([m0]) == QuerySet([m0])
    assert QuerySet([m0]) == QuerySet(m for m in [m0])
    assert QuerySet([m0]) == QuerySet(OOTreeSet([m0]))
Example #11
0
def test_and(sheraf_connection, m0, m1, m2):
    assert QuerySet([m1]) == QuerySet([m0, m1]) & QuerySet([m1, m2])
    assert QuerySet([m0, m1,
                     m2]) == QuerySet([m0, m1, m2]) & QuerySet([m2, m1, m0])
    assert QuerySet([m2, m1,
                     m0]) == QuerySet([m2, m1, m0]) & QuerySet([m0, m1, m2])
Example #12
0
def test_xor(sheraf_connection, m0, m1, m2):
    assert QuerySet([m0, m2]) == QuerySet([m0, m1]) ^ QuerySet([m1, m2])
    assert QuerySet([m2, m0]) == QuerySet([m1, m2]) ^ QuerySet([m0, m1])
    assert QuerySet() == QuerySet([m0, m1, m2]) ^ QuerySet([m2, m1, m0])
    assert QuerySet() == QuerySet([m2, m1, m0]) ^ QuerySet([m0, m1, m2])