Beispiel #1
0
 def test_generate_duplicate_explicit():
     assert Short.query.count() == 0
     one = Short.generate(target="test", delay=23)
     assert Short.query.count() == 1
     two = Short.generate(target="test", delay=42)
     assert Short.query.count() == 2
     assert one.symbol != two.symbol
Beispiel #2
0
 def test_generate_no_duplicate():
     assert Short.query.count() == 0
     one = Short.generate(target="test")
     assert Short.query.count() == 1
     two = Short.generate(target="test")
     assert Short.query.count() == 1
     assert one.symbol == two.symbol
Beispiel #3
0
    def test_search_by_param(visitor):
        assert Short.query.count() == 0
        one = Short.generate(target="___one")
        two = Short.generate(target="two___")
        assert Short.query.count() == 2

        org = visitor(ENDPOINT)
        res_one = visitor(ENDPOINT, query_string="q=one")
        res_two = visitor(ENDPOINT, query_string="q=two")
        res_all = visitor(ENDPOINT, query_string="q=___")
        exp_one = 'value="one"'
        exp_two = 'value="two"'
        exp_all = 'value="___"'

        assert exp_one not in org.text
        assert exp_two not in org.text
        assert exp_all not in org.text

        assert exp_one in res_one.text
        assert one.target in res_one.text

        assert exp_two in res_two.text
        assert two.target in res_two.text

        assert exp_all in res_all.text
        assert one.target in res_all.text
        assert two.target in res_all.text
Beispiel #4
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"
Beispiel #5
0
    def action(self):
        if not self.validate():
            return None

        return Short.generate(target=self.target.data,
                              delay=self.delay.data,
                              _commit=True)
Beispiel #6
0
    def test_ordered_query():
        assert Short.query.count() == 0
        Short.generate(target="one", delay=0)
        Short.generate(target="two", delay=0)
        Short.generate(target="drop", delay=1)
        Short.generate(target="nope", delay=2)
        assert Short.query.count() == 4

        assert Short.ordered(None).count() == 4
        query = Short.query.filter(Short.delay == 0)
        assert query.count() == 2
        assert Short.ordered(None, query=query).count() == 2
Beispiel #7
0
    def test_display(visitor, monkeypatch):
        assert Short.query.count() == 0
        one = Short.generate(target="one")
        two = Short.generate(target="two")
        thr = Short.generate(target="three")
        assert Short.query.count() == 3

        org = visitor(ENDPOINT)
        blocklist = [re_compile(r"^t.+", IGNORECASE)]
        monkeypatch.setattr(plus, "BLOCKLIST", blocklist)
        res = visitor(ENDPOINT)

        assert "nothing there" in org.text.lower()
        assert "nothing there" not in res.text.lower()
        assert f"<td>{one.prime}</td>" not in res.text
        assert f"<td>{two.prime}</td>" in res.text
        assert f"<td>{thr.prime}</td>" in res.text
        assert one.target not in res.text
        assert two.target in res.text
        assert thr.target in res.text
Beispiel #8
0
    def test_ordered():
        assert Short.query.count() == 0
        now = datetime.utcnow()

        one = Short.generate(
            target="one",
            delay=2,
            created=now - timedelta(seconds=1),
        )
        two = Short.generate(
            target="two",
            delay=1,
            created=now - timedelta(seconds=3),
        )
        thr = Short.generate(
            target="thr",
            delay=3,
            created=now - timedelta(seconds=2),
        )
        assert Short.query.count() == 3

        assert Short.ordered("PRIME") is None
        assert Short.ordered("BANANA") is None
        assert Short.ordered(None).all() == [one, two, thr]  # same as prime

        assert Short.ordered("prime").all() == [one, two, thr]
        assert Short.ordered("prime", rev=True).all() == [thr, two, one]

        assert Short.ordered("delay").all() == [two, one, thr]
        assert Short.ordered("delay", rev=True).all() == [thr, one, two]

        assert Short.ordered("target").all() == [one, thr, two]
        assert Short.ordered("target", rev=True).all() == [two, thr, one]

        assert Short.ordered("created").all() == [two, thr, one]
        assert Short.ordered("created", rev=True).all() == [one, thr, two]

        assert Short.ordered("active").all() == [one, two, thr]
        assert Short.ordered("active", rev=True).all() == [thr, two, one]
Beispiel #9
0
    def test_blocked():
        blocklist = [re_compile(r"^.+example\.com$", IGNORECASE)]
        assert Short.query.count() == 0
        Short.generate(target="http://www.example.org")
        Short.generate(target="https://example.org")
        one = Short.generate(target="http://www.example.com")
        two = Short.generate(target="https://example.com")
        assert Short.query.count() == 4

        assert Short.blocked([]).all() == []
        assert Short.blocked(blocklist).all() == [one, two]
        assert Short.blocked(blocklist, rev=True).all() == [two, one]
Beispiel #10
0
 def test_generate_no_duplicate_on_multi():
     assert Short.query.count() == 0
     one = Short.generate(target="test", delay=1)
     two = Short.generate(target="test", delay=2)
     thr = Short.generate(target="test", delay=3)
     assert Short.query.count() == 3
     g_thr = Short.generate(target="test", delay=3)
     g_two = Short.generate(target="test", delay=2)
     g_one = Short.generate(target="test", delay=1)
     assert Short.query.count() == 3
     assert g_one.symbol == one.symbol
     assert g_two.symbol == two.symbol
     assert g_thr.symbol == thr.symbol