Пример #1
0
 def test_process_response_ok(self, mock, mock_location_set):
     mock.return_value = None
     base_response = HttpResponse()
     self.get_location_mock.return_value = mycity = any_city()
     self.middleware.process_request(self.request)
     self.middleware.process_response(self.request, base_response)
     mock.assert_called_once_with(request=self.request, response=base_response)
     # workaround simplelazyobject
     self.assertEqual(str(mycity), str(mock_location_set.call_args[1]['location']))
Пример #2
0
 def test_process_response_ok(self, mock, mock_location_set):
     mock.return_value = None
     base_response = HttpResponse()
     self.get_location_mock.return_value = mycity = any_city()
     self.middleware.process_request(self.request)
     self.middleware.process_response(self.request, base_response)
     mock.assert_called_once_with(request=self.request,
                                  response=base_response)
     # workaround simplelazyobject
     self.assertEqual(str(mycity),
                      str(mock_location_set.call_args[1]['location']))
Пример #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)
Пример #4
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)
Пример #5
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)