Beispiel #1
0
    def setUp(self):
        config = {
            "name": "vova",
            "countries": [],
            "username": "******",
            "password": "******",
        }

        self.luminati = Luminati(**config)
Beispiel #2
0
    def setUp(self):
        config = {
            "name": "vova",
            "countries": [],
            "username": "******",
            "password": "******",
        }

        self.luminati = Luminati(**config)
Beispiel #3
0
class LuminatiTestCase(unittest.TestCase):
    def setUp(self):
        config = {
            "name": "vova",
            "countries": [],
            "username": "******",
            "password": "******",
        }

        self.luminati = Luminati(**config)

    def test_getting_super_proxy(self):
        self.assertEqual(
            self.luminati.get_super_proxy_url(),
            "http://client.luminati.io/api/get_super_proxy?raw=1&user=vova&key=vova666kgb"
        )

    def test_get_proxy_auth(self):
        self.assertEqual(self.luminati.get_proxy_auth("VOVAVILLE"),
                         "vova-country-VOVAVILLE:vova666kgb")

    @responses.activate
    def test_get_proxy_address(self):
        fake_response = "100.64.0.1"
        expectedResult = "{}:22225".format(fake_response)

        responses.add(responses.GET,
                      self.luminati.get_super_proxy_url(),
                      status=200,
                      body=fake_response,
                      content_type="text/html",
                      match_querystring=True)

        self.assertEqual(self.luminati.get_proxy_address(), expectedResult)

    @responses.activate
    def test_raises_error_when_failed_to_get_proxy_address(self):
        responses.add(
            responses.GET,
            self.luminati.get_super_proxy_url(),
            status=400,
            match_querystring=True,
            body="vova is sad",
        )

        exceptionMessage = "Luminati returned: 400: vova is sad"

        with self.assertRaisesRegexp(RuntimeError, exceptionMessage):
            self.luminati.get_proxy_address()

    @responses.activate
    def test_teleporting_to_a_wrong_place_should_return_false(self):
        fake_country_code = "XL"
        responses.add(
            responses.GET,
            'http://geome-1042.appspot.com/',
            status=200,
            body='{}'.format(fake_country_code),
            content_type="text/html",
        )

        responses.add(responses.GET,
                      self.luminati.get_super_proxy_url(),
                      status=200,
                      body="100.64.1.5",
                      content_type="text/html",
                      match_querystring=True)

        self.assertFalse(self.luminati.teleport("be"))
Beispiel #4
0
class LuminatiTestCase(unittest.TestCase):
    def setUp(self):
        config = {
            "name": "vova",
            "countries": [],
            "username": "******",
            "password": "******",
        }

        self.luminati = Luminati(**config)

    def test_getting_super_proxy(self):
        self.assertEqual(
            self.luminati.get_super_proxy_url(),
            "http://client.luminati.io/api/get_super_proxy?raw=1&user=vova&key=vova666kgb"
        )

    def test_get_proxy_auth(self):
        self.assertEqual(
            self.luminati.get_proxy_auth("VOVAVILLE"),
            "vova-country-VOVAVILLE:vova666kgb"
        )

    @responses.activate
    def test_get_proxy_address(self):
        fake_response = "100.64.0.1"
        expectedResult = "{}:22225".format(fake_response)

        responses.add(
            responses.GET,
            self.luminati.get_super_proxy_url(),
            status=200,
            body=fake_response,
            content_type="text/html",
            match_querystring=True
        )

        self.assertEqual(self.luminati.get_proxy_address(), expectedResult)

    @responses.activate
    def test_raises_error_when_failed_to_get_proxy_address(self):
        responses.add(
            responses.GET,
            self.luminati.get_super_proxy_url(),
            status=400,
            match_querystring=True,
            body="vova is sad",
        )

        exceptionMessage = "Luminati returned: 400: vova is sad"

        with self.assertRaisesRegexp(RuntimeError, exceptionMessage):
            self.luminati.get_proxy_address()

    @responses.activate
    def test_teleporting_to_a_wrong_place_should_return_false(self):
        fake_country_code = "XL"
        responses.add(
            responses.GET,
            'http://geome-1042.appspot.com/',
            status=200,
            body='{}'.format(fake_country_code),
            content_type="text/html",
        )

        responses.add(
            responses.GET,
            self.luminati.get_super_proxy_url(),
            status=200,
            body="100.64.1.5",
            content_type="text/html",
            match_querystring=True
        )

        self.assertFalse(self.luminati.teleport("be"))