Unverified Commit d035088f authored by Philipp Winter's avatar Philipp Winter
Browse files

Make unit test use ipaddress instead of ipaddr.

This should fix the following unit test:

[FAIL]
Traceback (most recent call last):
  File "/home/travis/build/NullHypothesis/bridgedb/bridgedb/test/test_https.py", line 227, in test_get_vanilla_ipv6
    self.assertIsInstance(ipaddr.IPAddress(addr), ipaddr.IPv6Address)
  File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/twisted/trial/_synctest.py", line 649, in assertIsInstance
    instance, classOrTuple, suffix))
twisted.trial.unittest.FailTest: IPv4Address('98.255.18.132') is not an instance of <class 'ipaddr.IPv6Address'>
parent b452f6f9
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ repository.
from __future__ import print_function

import gettext
import ipaddr
import ipaddress
import mechanize
import os

@@ -199,7 +199,7 @@ class HTTPTests(unittest.TestCase):
        for bridge in bridges:
            self.assertTrue(bridge != None)
            addr = bridge[0].rsplit(':', 1)[0]
            self.assertIsInstance(ipaddr.IPAddress(addr), ipaddr.IPv4Address)
            self.assertIsInstance(ipaddress.ip_address(addr), ipaddress.IPv4Address)

    def test_get_vanilla_ipv6(self):
        self.openBrowser()
@@ -212,7 +212,7 @@ class HTTPTests(unittest.TestCase):
        for bridge in bridges:
            self.assertTrue(bridge != None)
            addr = bridge[0].rsplit(':', 1)[0].strip('[]')
            self.assertIsInstance(ipaddr.IPAddress(addr), ipaddr.IPv6Address)
            self.assertIsInstance(ipaddress.ip_address(addr), ipaddress.IPv6Address)

    def test_get_obfs4_ipv4(self):
        """Try asking for obfs4 bridges, and check that the PT arguments in the
+6 −6
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ import logging
import os
import shutil

import ipaddr
import ipaddress

from bs4 import BeautifulSoup

@@ -588,14 +588,14 @@ class ReCaptchaProtectedResourceTests(unittest.TestCase):
        """Check that removing our remoteip setting produces a random IP."""
        self.captchaResource.remoteIP = None
        ip = self.captchaResource.getRemoteIP()
        realishIP = ipaddr.IPv4Address(ip).compressed
        realishIP = ipaddress.IPv4Address(ip).compressed
        self.assertTrue(realishIP)
        self.assertNotEquals(realishIP, '111.111.111.111')

    def test_getRemoteIP_useConfiguredIP(self):
        """Check that our remoteip setting is used if configured."""
        ip = self.captchaResource.getRemoteIP()
        realishIP = ipaddr.IPv4Address(ip).compressed
        realishIP = ipaddress.IPv4Address(ip).compressed
        self.assertTrue(realishIP)
        self.assertEquals(realishIP, '111.111.111.111')

@@ -774,7 +774,7 @@ class BridgesResourceTests(unittest.TestCase):

            # Check that the IP and port seem okay:
            ip, port = fields[0].rsplit(':')
            self.assertIsInstance(ipaddr.IPv4Address(ip), ipaddr.IPv4Address)
            self.assertIsInstance(ipaddress.ip_address(ip), ipaddress.IPv4Address)
            self.assertIsInstance(int(port), int)
            self.assertGreater(int(port), 0)
            self.assertLessEqual(int(port), 65535)
@@ -858,7 +858,7 @@ class BridgesResourceTests(unittest.TestCase):

            # Check that the IP and port seem okay:
            ip, port = bridgeLine[1].rsplit(':')
            self.assertIsInstance(ipaddr.IPv4Address(ip), ipaddr.IPv4Address)
            self.assertIsInstance(ipaddress.ip_address(ip), ipaddress.IPv4Address)
            self.assertIsInstance(int(port), int)
            self.assertGreater(int(port), 0)
            self.assertLessEqual(int(port), 65535)
@@ -892,7 +892,7 @@ class BridgesResourceTests(unittest.TestCase):

            # Check that the IP and port seem okay:
            ip, port = bridgeLine[0].rsplit(b':')
            self.assertIsInstance(ipaddr.IPv4Address(ip), ipaddr.IPv4Address)
            self.assertIsInstance(ipaddress.ip_address(ip.decode("utf-8")), ipaddress.IPv4Address)
            self.assertIsInstance(int(port), int)
            self.assertGreater(int(port), 0)
            self.assertLessEqual(int(port), 65535)