Exemple #1
0
def test_approximate_bandwidth_failed(mg, mc, mt):
    mg.side_effect = None, None
    mc.return_value = "http://example.com/1MB.bin"
    speed = approximate_bandwidth("8.8.8.8",
                                  1337,
                                  username="******",
                                  password="******",
                                  timeout=10,
                                  times=2,
                                  maxfail=1)
    assert speed is None
Exemple #2
0
def test_approximate_bandwidth_smallfile(mg, mc, mt):
    data = "A" * 100000
    mg.side_effect = data, data
    mc.return_value = "http://example.com/1MB.bin"
    mt.side_effect = 1, 1, 1, 1
    speed = approximate_bandwidth("8.8.8.8",
                                  1337,
                                  username="******",
                                  password="******",
                                  timeout=10)
    assert speed == 880.0
Exemple #3
0
def test_approximate_bandwidth_maxfail(mg, mc, mt):
    data = "A" * 1000000
    mg.side_effect = None, data
    mc.return_value = "http://example.com/1MB.bin"
    mt.side_effect = 1, 1, 10.1
    speed = approximate_bandwidth("8.8.8.8",
                                  1337,
                                  username="******",
                                  password="******",
                                  timeout=10)
    assert round(speed, 2) == 0.44
Exemple #4
0
    def approx_bandwidth(self):
        """
        Calculate an approximate Mbit/s download speed using
        the file specified in the config to download. Automatically
        updated in the database

        :returns: An approximate download speed in Mbit/s
        :rtype: float
        """
        approx_bandwidth = approximate_bandwidth(
            self.host, self.port, username=self.username,
            password=self.password, times=cfg("bandwidth", "times"),
            timeout=cfg("bandwidth", "timeout")
        )
        db.set_approx_bandwidth(self.id, approx_bandwidth)
        return approx_bandwidth
Exemple #5
0
def test_approximate_bandwidth_8(mg, mc, mt):
    data = "A" * 1000000
    mg.side_effect = data, data
    mc.return_value = "http://example.com/1MB.bin"
    mt.side_effect = 1, 2, 1, 2
    speed = approximate_bandwidth("8.8.8.8",
                                  1337,
                                  username="******",
                                  password="******",
                                  timeout=10,
                                  times=2)
    mg.assert_any_call("http://example.com/1MB.bin",
                       "8.8.8.8",
                       1337,
                       username="******",
                       password="******",
                       timeout=10)
    assert mg.call_count == 2
    assert speed == 8