'ipdata (Maxmind, thyme.apnic.net) functions'

def test_data(self):

    (res, out, _) = RUN(['ivre', 'ipdata', '8.8.8.8'])
    self.assertEqual(res, 0)
    self.assertEqual(out, '8.8.8.8\n')
    res = RUN(['ivre', 'ipdata', '--init'], stdin=open(os.devnull))[0]
    self.assertEqual(res, 0)
    (res, out, _) = RUN(['ivre', 'ipdata', '8.8.8.8'])
    self.assertEqual(res, 0)
    self.assertEqual(out, '8.8.8.8\n')
    res = RUN(['ivre', 'ipdata', '--download'])[0]
    self.assertEqual(res, 0)
    res = RUN(['ivre', 'ipdata', '--import-all', '--no-update-passive-db'])[0]
    self.assertEqual(res, 0)
    (res, out, _) = RUN(['ivre', 'ipdata', '8.8.8.8'])
    self.assertEqual(res, 0)
    out = sorted((('                coordinates    (37.751,    -97.822)' if (x == '                coordinates    (37.750999999999998,    -97.822000000000003)') else x) for x in out.splitlines()))
    self.assertEqual(out, sorted('8.8.8.8\n                as_num    15169\n                as_name    Google    Inc.\n                coordinates    (37.751,    -97.822)\n                country_code    US\n                country_name    United    States\n'.splitlines()))
    (res, out, _) = RUN(['ivre', 'runscans', '--output', 'Count', '--asnum', '15169'])
    self.assertEqual(res, 0)
    self.assertEqual(out, 'AS15169    has    2685951    IPs.\n')
    (res, out, _) = RUN(['ivre', 'runscans', '--output', 'Count', '--country', 'US'])
    self.assertEqual(res, 0)
    self.assertEqual(out, 'US    has    1595080627    IPs.\n')
    (res, out, _) = RUN(['ivre', 'runscans', '--output', 'List', '--country', 'A2'])
    self.assertEqual(res, 0)
    self.assertEqual(out, '5.145.149.142    -    5.145.149.142\n57.72.6.0    -    57.72.6.255\n62.56.206.0    -    62.56.206.255\n62.128.160.0    -    62.128.160.255\n62.128.167.0    -    62.128.167.255\n62.145.35.0    -    62.145.35.255\n77.220.0.0    -    77.220.7.255\n78.41.29.0    -    78.41.29.255\n78.41.227.0    -    78.41.227.255\n80.78.16.152    -    80.78.16.167\n80.78.16.192    -    80.78.16.207\n80.78.16.224    -    80.78.16.224\n80.78.19.57    -    80.78.19.63\n80.78.19.233    -    80.78.19.239\n80.231.5.0    -    80.231.5.255\n82.206.239.0    -    82.206.239.255\n83.229.22.0    -    83.229.22.255\n84.22.67.0    -    84.22.67.255\n86.62.5.0    -    86.62.5.255\n86.62.30.0    -    86.62.30.255\n87.234.247.0    -    87.234.247.255\n93.93.101.96    -    93.93.101.127\n93.93.102.96    -    93.93.102.127\n111.90.150.0    -    111.90.150.255\n185.38.108.0    -    185.38.108.255\n196.15.8.0    -    196.15.8.255\n196.15.10.0    -    196.15.11.255\n196.47.77.0    -    196.47.78.255\n196.201.132.0    -    196.201.132.255\n196.201.135.0    -    196.201.135.255\n196.201.148.0    -    196.201.148.255\n199.190.44.0    -    199.190.47.255\n213.193.49.0    -    213.193.49.255\n216.147.155.0    -    216.147.155.255\n217.30.26.0    -    217.30.26.255\n217.175.75.0    -    217.175.75.255\n')
    (res, out, _) = RUN(['ivre', 'runscans', '--output', 'ListCIDRs', '--country', 'A1'])
    self.assertEqual(res, 0)
    self.assertEqual(out, '31.14.133.39/32\n37.221.172.0/23\n46.19.137.0/24\n46.19.143.0/24\n50.7.78.88/31\n62.73.8.0/23\n63.235.155.210/32\n64.12.118.23/32\n64.12.118.88/32\n67.43.156.0/24\n69.10.139.0/24\n70.232.245.0/24\n74.82.9.224/32\n80.254.74.0/23\n93.115.82.0/23\n93.115.84.0/23\n96.47.226.20/32\n147.203.120.0/24\n176.9.75.43/32\n185.36.100.145/32\n192.238.21.0/24\n193.107.17.71/32\n193.200.150.0/24\n198.144.105.88/32\n199.114.223.0/24\n199.188.236.0/23\n200.200.200.200/32\n206.71.162.0/24\n206.196.103.0/24\n208.43.225.52/32\n209.216.198.0/24\n213.234.249.115/32\n216.151.180.0/24\n')
    (res, out1, _) = RUN(['ivre', 'runscans', '--output', 'ListAll', '--country', 'A1'])
    self.assertEqual(res, 0)
    (res, out2, _) = RUN(['ivre', 'runscans', '--output', 'ListAllRand', '--country', 'A1'])
    self.assertEqual(res, 0)
    (out1, out2) = (out1.split('\n'), out2.split('\n'))
    self.assertGreater(len(out1), 0)
    self.assertItemsEqual(out1, out2)
    (res, out1, _) = RUN(['ivre', 'runscans', '--output', 'ListAll', '--region', 'GP', 'R5'])
    self.assertEqual(res, 0)
    (res, out2, _) = RUN(['ivre', 'runscans', '--output', 'ListAllRand', '--region', 'GP', 'R5'])
    self.assertEqual(res, 0)
    (out1, out2) = (out1.split('\n'), out2.split('\n'))
    self.assertGreater(len(out1), 0)
    self.assertItemsEqual(out1, out2)
    (res, out1, _) = RUN(['ivre', 'runscans', '--output', 'ListAll', '--city', 'FR', 'Carcassonne'])
    self.assertEqual(res, 0)
    (res, out2, _) = RUN(['ivre', 'runscans', '--output', 'ListAllRand', '--city', 'FR', 'Carcassonne'])
    self.assertEqual(res, 0)
    (out1, out2) = (out1.split('\n'), out2.split('\n'))
    self.assertGreater(len(out1), 0)
    self.assertItemsEqual(out1, out2)
    (res, out1, _) = RUN(['ivre', 'runscans', '--output', 'ListAll', '--asnum', '12345'])
    self.assertEqual(res, 0)
    (res, out2, _) = RUN(['ivre', 'runscans', '--output', 'ListAllRand', '--asnum', '12345'])
    self.assertEqual(res, 0)
    (out1, out2) = (out1.split('\n'), out2.split('\n'))
    self.assertGreater(len(out1), 0)
    self.assertItemsEqual(out1, out2)
    res = RUN(['ivre', 'ipdata', '--init'], stdin=open(os.devnull))[0]
    self.assertEqual(res, 0)
