Exemple #1
0
    def test_log(self):
        p = Proxy("127.0.0.1", "80")
        msg = "MSG"
        stime = time.time()
        err = ProxyConnError

        self.assertEqual(p.get_log(), [])
        self.assertEqual(p._runtimes, [])

        with self.assertLogs(log.name, level="DEBUG") as cm:
            p.log(msg)
            p.ngtr = "HTTP"
            p.log(msg)
            self.assertIn(("INFO", msg, 0), p.get_log())
            self.assertIn(("HTTP", msg, 0), p.get_log())
            self.assertEqual(len(p.stat["errors"]), 0)
            self.assertEqual(p._runtimes, [])
            self.assertEqual(
                cm.output,
                [
                    "DEBUG:proxybroker:127.0.0.1:80 [INFO]: MSG; Runtime: 0.00",
                    "DEBUG:proxybroker:127.0.0.1:80 [HTTP]: MSG; Runtime: 0.00",
                ],
            )

        p.log(msg, stime, err)
        p.log(msg, stime, err)
        self.assertEqual(len(p.stat["errors"]), 1)
        self.assertEqual(sum(p.stat["errors"].values()), 2)
        self.assertEqual(p.stat["errors"][err.errmsg], 2)
        self.assertAlmostEqual(p._runtimes[-1], 0.0, places=1)

        len_runtimes = len(p._runtimes)
        p.log(msg + "timeout", stime)
        self.assertEqual(len(p._runtimes), len_runtimes)

        msg = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do"
        p.log(msg)
        last_msg = p.get_log()[-1][1]
        cropped = msg[:60] + "..."
        self.assertEqual(last_msg, cropped)
Exemple #2
0
def test_log(log):
    p = Proxy('127.0.0.1', '80')
    msg = 'MSG'
    stime = time.time()
    err = ProxyConnError

    assert p.get_log() == []
    assert p._runtimes == []

    with log(logger.name, level='DEBUG') as cm:
        p.log(msg)
        p.ngtr = 'HTTP'
        p.log(msg)
        assert ('INFO', msg, 0) in p.get_log()
        assert ('HTTP', msg, 0) in p.get_log()
        assert len(p.stat['errors']) == 0
        assert p._runtimes == []
        assert cm.output == [
            'DEBUG:proxybroker:127.0.0.1:80 [INFO]: MSG; Runtime: 0.00',
            'DEBUG:proxybroker:127.0.0.1:80 [HTTP]: MSG; Runtime: 0.00',
        ]

    p.log(msg, stime, err)
    p.log(msg, stime, err)
    assert len(p.stat['errors']) == 1
    assert sum(p.stat['errors'].values()) == 2
    assert p.stat['errors'][err.errmsg] == 2
    assert round(p._runtimes[-1], 2) == 0.0

    len_runtimes = len(p._runtimes)
    p.log(msg + 'timeout', stime)
    assert len(p._runtimes) == len_runtimes

    msg = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do'
    p.log(msg)
    last_msg = p.get_log()[-1][1]
    cropped = msg[:60] + '...'
    assert last_msg == cropped
Exemple #3
0
    def test_log(self):
        p = Proxy('127.0.0.1', '80')
        msg = 'MSG'
        stime = time.time()
        err = ProxyConnError

        self.assertEqual(p.get_log(), [])
        self.assertEqual(p._runtimes, [])

        with self.assertLogs(log.name, level='DEBUG') as cm:
            p.log(msg)
            p.ngtr = 'HTTP'
            p.log(msg)
            self.assertIn(('INFO', msg, 0), p.get_log())
            self.assertIn(('HTTP', msg, 0), p.get_log())
            self.assertEqual(len(p.stat['errors']), 0)
            self.assertEqual(p._runtimes, [])
            self.assertEqual(
                cm.output,
                ['DEBUG:proxybroker:127.0.0.1:80 [INFO]: MSG; Runtime: 0.00',
                 'DEBUG:proxybroker:127.0.0.1:80 [HTTP]: MSG; Runtime: 0.00'])

        p.log(msg, stime, err)
        p.log(msg, stime, err)
        self.assertEqual(len(p.stat['errors']), 1)
        self.assertEqual(sum(p.stat['errors'].values()), 2)
        self.assertEqual(p.stat['errors'][err.errmsg], 2)
        self.assertAlmostEqual(p._runtimes[-1], 0.0, places=1)

        len_runtimes = len(p._runtimes)
        p.log(msg + 'timeout', stime)
        self.assertEqual(len(p._runtimes), len_runtimes)

        msg = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do'
        p.log(msg)
        last_msg = p.get_log()[-1][1]
        cropped = msg[:60] + '...'
        self.assertEqual(last_msg, cropped)
Exemple #4
0
def test_ngtr():
    p = Proxy('127.0.0.1', '80')
    p.ngtr = 'HTTPS'
    assert isinstance(p.ngtr, HttpsNgtr)
    assert p.ngtr._proxy is p
Exemple #5
0
 def test_ngtr(self):
     p = Proxy('127.0.0.1', '80')
     p.ngtr = 'HTTPS'
     self.assertIsInstance(p.ngtr, HttpsNgtr)
     self.assertIs(p.ngtr._proxy, p)
Exemple #6
0
 def test_ngtr(self):
     p = Proxy("127.0.0.1", "80")
     p.ngtr = "HTTPS"
     self.assertIsInstance(p.ngtr, HttpsNgtr)
     self.assertIs(p.ngtr._proxy, p)