Ejemplo n.º 1
0
    def test_get_http_raw(self):
        from ipwhois.nir import NIR_WHOIS

        # GET
        result = Net('133.1.2.5')
        try:
            self.assertIsInstance(
                result.get_http_raw(
                    NIR_WHOIS['jpnic']['url'].format('133.1.2.5')), str)
        except HTTPLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        # POST
        result = Net('115.1.2.3')
        try:
            self.assertIsInstance(
                result.get_http_raw(
                    url=NIR_WHOIS['krnic']['url'].format('115.1.2.3'),
                    request_type=NIR_WHOIS['krnic']['request_type'],
                    form_data={
                        NIR_WHOIS['krnic']['form_data_ip_field']: '115.1.2.3'
                    }), str)
        except HTTPLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        self.assertRaises(HTTPLookupError, result.get_http_raw,
                          **dict(url='http://255.255.255.255', retry_count=1))

        result = Net(address='133.1.2.5', timeout=0)
        url = NIR_WHOIS['jpnic']['url'].format('133.1.2.5')
        self.assertRaises(HTTPLookupError, result.get_http_raw,
                          **dict(url=url, retry_count=0))
Ejemplo n.º 2
0
    def test_get_http_raw(self):
        from ipwhois.nir import NIR_WHOIS

        # GET
        result = Net('133.1.2.5')
        try:
            self.assertIsInstance(result.get_http_raw(
                NIR_WHOIS['jpnic']['url'].format('133.1.2.5')), str)
        except HTTPLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        # POST
        result = Net('115.1.2.3')
        try:
            self.assertIsInstance(result.get_http_raw(
                url=NIR_WHOIS['krnic']['url'].format('115.1.2.3'),
                request_type=NIR_WHOIS['krnic']['request_type'],
                form_data={
                    NIR_WHOIS['krnic']['form_data_ip_field']: '115.1.2.3'
                }
            ), str)
        except HTTPLookupError:
            pass
        except AssertionError as e:
            raise e
        except Exception as e:
            self.fail('Unexpected exception raised: {0}'.format(e))

        self.assertRaises(HTTPLookupError, result.get_http_raw, **dict(
            url='http://255.255.255.255', retry_count=1))

        result = Net(address='133.1.2.5', timeout=0)
        url = NIR_WHOIS['jpnic']['url'].format('133.1.2.5')
        self.assertRaises(HTTPLookupError, result.get_http_raw, **dict(
            url=url, retry_count=0))