Esempio n. 1
0
    def test_searched():
        assert Short.query.count() == 0
        one = Short.create(symbol="one", target="_cherry", delay=3)
        two = Short.create(symbol="two", target="_eggplant", delay=2)
        thr = Short.create(symbol="thr", target="_peach", delay=1)
        assert Short.query.count() == 3

        assert Short.searched("one").all() == [one]
        assert Short.searched("two").all() == [two]

        assert Short.searched("err").all() == [one]
        assert Short.searched("egg").all() == [two]

        assert Short.searched("t").all() == [two, thr]
        assert Short.searched("p").all() == [two, thr]
        assert Short.searched("_").all() == [one, two, thr]
        assert Short.searched("_", rev=True).all() == [thr, two, one]

        assert Short.searched("_", field="delay", rev=False).all() == [
            thr,
            two,
            one,
        ]
        assert Short.searched("_", field="delay", rev=True).all() == [
            one,
            two,
            thr,
        ]
Esempio n. 2
0
 def test_generate_create():
     assert Short.query.count() == 0
     Short.create(symbol="demo", target="test")
     assert Short.query.count() == 1
     short = Short.generate(target="test")
     assert Short.query.count() == 1
     assert short.symbol == "demo"
Esempio n. 3
0
    def test_symbol_unique():
        one = Short.create(symbol="sym", target="one", _commit=False)
        assert one.save(_commit=True)

        two = Short.create(symbol="sym", target="two", _commit=False)
        with raises(IntegrityError):
            assert two.save(_commit=True)
Esempio n. 4
0
    def test_by_symbol_active():
        act = Short.create(symbol="act", target="act", active=True)
        ina = Short.create(symbol="ina", target="ina", active=False)

        assert Short.by_symbol_active("lol") is None
        assert Short.by_symbol_active("act") == act
        assert Short.by_symbol_active("ina") is None
        assert Short.by_symbol("ina") == ina
Esempio n. 5
0
    def test_by_symbol():
        one = Short.create(symbol="one", target="1")
        two = Short.create(symbol="two", target="2")

        assert Short.by_symbol("null") is None
        assert Short.by_symbol("one") == one
        assert Short.by_symbol("two") == two
        assert Short.by_symbol("three") is None
Esempio n. 6
0
    def test_len_symbol():
        assert Short.len_symbol(1) == 1

        for sym in SYM_POOL:
            Short.create(symbol=sym, target=sym, _commit=False)

        assert Short.len_symbol(0) == 2
        assert Short.len_symbol(1) == 2
        assert Short.len_symbol(2) == 2
        assert Short.len_symbol(3) == 3
Esempio n. 7
0
    def test_len_symbol_fact():
        assert Short.len_symbol(1) == 1

        for a_sym in SYM_POOL:
            for b_sym in SYM_POOL:
                sym = a_sym + b_sym
                Short.create(symbol=sym, target=sym, _commit=False)
            Short.create(symbol=a_sym, target=a_sym, _commit=False)

        assert Short.len_symbol(0) == 3
        assert Short.len_symbol(1) == 3
        assert Short.len_symbol(2) == 3
        assert Short.len_symbol(3) == 3
        assert Short.len_symbol(4) == 4
def _sho(target="test", delay=23):
    return Short.create(
        symbol="".join(choice(SYM_POOL) for _ in range(SYM_MINI)),
        target=target,
        delay=delay,
        _commit=False,
    )
Esempio n. 9
0
    def test_nullables(session):
        short = Short.create(_commit=False)

        assert short.prime is None
        assert short.symbol is None
        assert short.target is None
        assert short.active is None
        assert short.created is None
        assert short.visited is None

        with raises(IntegrityError):
            short.save(_commit=True)
        session.rollback()

        short.update(symbol="sym", _commit=False)

        with raises(IntegrityError):
            short.save(_commit=True)
        session.rollback()

        short.update(target="tgt", _commit=False)

        short.save(_commit=True)

        assert short.prime == 1
        assert short.symbol == "sym"
        assert short.target == "tgt"
        assert short.active is True
        assert short.created is not None
        assert short.visited == 0
Esempio n. 10
0
    def test_default_fields():
        start = datetime.utcnow()
        short = Short.create(symbol="abc", target="def")

        assert short.prime == 1
        assert short.symbol == "abc"
        assert short.target == "def"
        assert short.active is True
        assert start <= short.created
        assert short.created <= datetime.utcnow()
        assert short.visited == 0
Esempio n. 11
0
    def test_content(visitor):
        assert Short.query.count() == 0
        obj = Short.create(symbol="symbol", target="target")
        assert Short.query.count() == 1

        res = visitor(ENDPOINT)
        txt = res.text
        assert str(obj.prime) in txt
        assert obj.symbol in txt
        assert obj.target in txt
        assert str(obj.created) in txt
Esempio n. 12
0
    def test_increase_visit_fallback():
        short = Short.create(symbol="abc", target="def")
        assert short.visited == 0

        short.increase_visit()
        assert short.visited == 1

        short.update(visited="wrong", _commit=False)
        assert short.visited == "wrong"

        short.increase_visit()
        assert short.visited == 1
Esempio n. 13
0
    def test_make_symbol():
        pool, delim, miss = SYM_POOL.partition(SYM_POOL[-2])
        for sym in pool:
            Short.create(symbol=sym, target=sym, _commit=False)

        symbol = Short.make_symbol(1)
        assert symbol in delim + miss
        Short.create(symbol=symbol, target=symbol, _commit=False)

        symbol = Short.make_symbol(1)
        assert symbol in delim + miss
        Short.create(symbol=symbol, target=symbol, _commit=False)

        assert len(Short.make_symbol(1)) == 2
Esempio n. 14
0
def _sho(target="test"):
    return Short.create(symbol=_sym(), target=target)
Esempio n. 15
0
 def test_increase_visit():
     short = Short.create(symbol="abc", target="def")
     assert short.visited == 0
     for num in range(1, 1 + 23):
         short.increase_visit()
         assert short.visited == num