def to_internal_value(self, data):
     output = super(BaseAbuseReportSerializer, self).to_internal_value(data)
     request = self.context['request']
     output['country_code'] = AbuseReport.lookup_country_code_from_ip(
         request.META.get('REMOTE_ADDR'))
     if request.user.is_authenticated:
         output['reporter'] = request.user
     return output
Beispiel #2
0
 def to_internal_value(self, data):
     output = super(BaseAbuseReportSerializer, self).to_internal_value(data)
     request = self.context['request']
     output['country_code'] = AbuseReport.lookup_country_code_from_ip(
         request.META.get('REMOTE_ADDR'))
     if request.user.is_authenticated:
         output['reporter'] = request.user
     return output
    def handle(self, *args, **kwargs):
        self.setup_check()

        qs = AbuseReport.objects.only('ip_address', 'country_code').filter(
            ip_address__isnull=False, country_code__isnull=True)
        for report in qs:
            log.info('Looking up country_code for abuse report %d', report.pk)
            value = AbuseReport.lookup_country_code_from_ip(report.ip_address)
            report.update(country_code=value)
    def handle(self, *args, **kwargs):
        self.setup_check()

        qs = AbuseReport.objects.only('ip_address', 'country_code').filter(
            ip_address__isnull=False, country_code__isnull=True)
        for report in qs:
            log.info('Looking up country_code for abuse report %d', report.pk)
            value = AbuseReport.lookup_country_code_from_ip(report.ip_address)
            report.update(country_code=value)
Beispiel #5
0
    def test_lookup_country_code_from_ip(self, GeoIP2_mock):
        GeoIP2_mock.return_value.country_code.return_value = 'ZZ'
        assert AbuseReport.lookup_country_code_from_ip('') == ''
        assert AbuseReport.lookup_country_code_from_ip('notanip') == ''
        assert GeoIP2_mock.return_value.country_code.call_count == 0

        GeoIP2_mock.return_value.country_code.return_value = 'ZZ'
        assert AbuseReport.lookup_country_code_from_ip('127.0.0.1') == 'ZZ'
        assert AbuseReport.lookup_country_code_from_ip('::1') == 'ZZ'

        GeoIP2_mock.return_value.country_code.side_effect = GeoIP2Exception
        assert AbuseReport.lookup_country_code_from_ip('127.0.0.1') == ''

        GeoIP2_mock.return_value.country_code.side_effect = GeoIP2Error
        assert AbuseReport.lookup_country_code_from_ip('127.0.0.1') == ''
Beispiel #6
0
    def test_lookup_country_code_from_ip(self, GeoIP2_mock):
        GeoIP2_mock.return_value.country_code.return_value = 'ZZ'
        assert AbuseReport.lookup_country_code_from_ip('') == ''
        assert AbuseReport.lookup_country_code_from_ip('notanip') == ''
        assert GeoIP2_mock.return_value.country_code.call_count == 0

        GeoIP2_mock.return_value.country_code.return_value = 'ZZ'
        assert AbuseReport.lookup_country_code_from_ip('127.0.0.1') == 'ZZ'
        assert AbuseReport.lookup_country_code_from_ip('::1') == 'ZZ'

        GeoIP2_mock.return_value.country_code.side_effect = GeoIP2Exception
        assert AbuseReport.lookup_country_code_from_ip('127.0.0.1') == ''

        GeoIP2_mock.return_value.country_code.side_effect = GeoIP2Error
        assert AbuseReport.lookup_country_code_from_ip('127.0.0.1') == ''
    def setup_check(self):
        value = AbuseReport.lookup_country_code_from_ip('1.1.1.1')

        if not value:
            raise CommandError('GeoIP lookups does not appear to be working.')
    def setup_check(self):
        value = AbuseReport.lookup_country_code_from_ip('1.1.1.1')

        if not value:
            raise CommandError('GeoIP lookups does not appear to be working.')