def test_update_status(self, setup): p1 = Proxy(ip="127.0.0.1", port=80) p2 = Proxy(ip="127.0.0.1", port=8080) p3 = Proxy(ip="127.0.0.2", port=80) p4 = Proxy(ip="127.0.0.2", port=8080) proxypool = ProxyPool() proxypool.add_proxy(p1) proxypool.add_proxy(p2) proxypool.add_proxy(p3) proxypool.add_proxy(p4) proxypool.update_proxy_status(p1.proxy_url(), False) proxypool.update_proxy_status(p1.proxy_url(), False) proxypool.update_proxy_status(p1.proxy_url(), False) assert len(ProxyModel.load_all()) == 4 assert proxypool.count() == 4 proxypool.update_proxy_status(p2.proxy_url(), True) proxypool.update_proxy_status(p1.proxy_url(), False) proxypool.update_proxy_status(p1.proxy_url(), False) assert len(ProxyModel.load_all()) == 4 assert proxypool.count() == 4 proxypool.update_proxy_status(p1.proxy_url(), False) assert len(ProxyModel.load_all()) == 3 assert proxypool.count() == 3 proxypool.add_proxy(p1) proxypool.update_proxy_status(p1.proxy_url(), False) proxypool.update_proxy_status(p1.proxy_url(), True) proxypool.update_proxy_status(p1.proxy_url(), False) proxypool.update_proxy_status(p1.proxy_url(), False) assert len(ProxyModel.load_all()) == 4 assert proxypool.count() == 4
def test_add_del(self, setup): proxypool = ProxyPool() p1 = Proxy(ip="127.0.0.1", port=80) p2 = Proxy(ip="127.0.0.1", port=8080) p3 = Proxy(ip="127.0.0.2", port=8080) proxypool.add_proxy(p1) assert len(ProxyModel.load_all()) == 1 from sqlalchemy.exc import IntegrityError with pytest.raises(IntegrityError): proxypool.add_proxy(p1) proxypool.add_proxy(p2) proxypool.add_proxy(p3) assert proxypool.count() == 3 assert proxypool.has_proxy(p1.proxy_url()) proxypool.del_proxy(p1.proxy_url()) assert len(ProxyModel.load_all()) == 2 assert proxypool.count() == 2 proxypool.del_proxy(p2.proxy_url()) proxypool.del_proxy(p3.proxy_url()) assert proxypool.count() == 0 proxypool.del_proxy(p1.proxy_url())
def test_op(self, setup): p = ProxyModel(ip="127.0.0.1", port=88888) try: p.insert() except: p.ip = "127.0.0.1" p.port = 88888 p.update() t = ProxyModel.load_all() p = t[-1] proxy_count = len(t) assert p.ip == "127.0.0.1" and p.port == 88888 p = ProxyModel.load("127.0.0.1", 88888) assert p.ip == "127.0.0.1" and p.port == 88888 p.country = "SAS" p.update() p = ProxyModel.load_all()[-1] assert p.ip == "127.0.0.1" and p.country == "SAS" p.delete() assert proxy_count - 1 == len(ProxyModel.load_all())