예제 #1
0
    def test_relations(self):
        self.country = factory.any_country()
        self.region = factory.any_region(country=self.country)
        self.city = factory.any_city(region=self.region)
        range = create_ip_range(
            start_ip=struct.unpack('!L', socket.inet_aton('43.123.56.0'))[0],
            end_ip=struct.unpack('!L', socket.inet_aton('43.123.56.255'))[0],
            city=self.city,
            region=self.region,
            country=self.country)

        ip_range = IpRange.objects.by_ip('43.123.56.12')
        self.assertEqual(ip_range.city, self.city)
        self.assertEqual(ip_range.city.region, self.region)
        self.assertEqual(ip_range.city.region.country, self.country)
예제 #2
0
    def test_relations(self):
        self.country = factory.any_country()
        self.region = factory.any_region(country=self.country)
        self.city = factory.any_city(region=self.region)
        range = create_ip_range(
            start_ip=struct.unpack("!L", socket.inet_aton("43.123.56.0"))[0],
            end_ip=struct.unpack("!L", socket.inet_aton("43.123.56.255"))[0],
            city=self.city,
            region=self.region,
            country=self.country,
        )

        ip_range = IpRange.objects.by_ip("43.123.56.12")
        self.assertEqual(ip_range.city, self.city)
        self.assertEqual(ip_range.city.region, self.region)
        self.assertEqual(ip_range.city.region.country, self.country)
예제 #3
0
    def test_relations(self):
        self.country = factory.any_country()
        self.region = factory.any_region(country=self.country)
        self.city = factory.any_city(region=self.region)
        range = create_ip_range(start_ip=struct.unpack('!L', socket.inet_aton('43.123.56.0'))[0],
                                end_ip=struct.unpack('!L', socket.inet_aton('43.123.56.255'))[0],
                                city=self.city, region=self.region, country=self.country)

        ip_range = IpRange.objects.by_ip('43.123.56.12')
        self.assertEqual(ip_range.city, self.city)
        self.assertEqual(ip_range.city.region, self.region)
        self.assertEqual(ip_range.city.region.country, self.country)
        # with select_related
        ip_range = IpRange.objects.select_related('city', 'region', 'country').by_ip('43.123.56.12')
        self.assertEqual(ip_range.city, self.city)
        self.assertEqual(ip_range.region, self.region)
        self.assertEqual(ip_range.country, self.country)
예제 #4
0
 def setUp(self):
     self.range_contains = create_ip_range(start_ip=3568355840,
                                           end_ip=3568355843)
     self.range_not_contains = create_ip_range(start_ip=3568355844,
                                               end_ip=3568355851)
예제 #5
0
 def setUp(self):
     self.range_contains = create_ip_range(start_ip=3568355840, end_ip=3568355843)
     self.range_not_contains = create_ip_range(start_ip=3568355844, end_ip=3568355851)
예제 #6
0
 def test_get_corresponding_location_ok(self, mock_get_default_location,
                                        mock_get_by_ip_range):
     range = create_ip_range()
     self.locator._get_corresponding_location(range)
     mock_get_by_ip_range.assert_called_once_with(range)
     self.assertFalse(mock_get_default_location.called)
예제 #7
0
 def test_get_corresponding_location_ok(self, mock_get_default_location, mock_get_by_ip_range):
     range = create_ip_range()
     self.locator._get_corresponding_location(range)
     mock_get_by_ip_range.assert_called_once_with(range)
     self.assertFalse(mock_get_default_location.called)