Skip to content

Commit

Permalink
Merge branch 'master' into fix/issue#3
Browse files Browse the repository at this point in the history
  • Loading branch information
jose-lpa authored Jul 1, 2020
2 parents e6c6c3f + 0c6e258 commit 5c752f6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def run_tests(self):
'Django>=2.1',
'django-appconf',
'django-countries',
'django-ipware',
'django-ipware>=3.0',
'django-user-agents',
'geoip2'
],
Expand Down
2 changes: 2 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'

django.setup()

# Ojete
2 changes: 1 addition & 1 deletion tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Post(models.Model):
published = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.title
return str(self.title)

def save(
self, force_insert=False, force_update=False, using=None,
Expand Down
7 changes: 4 additions & 3 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ def test_create_from_request_missing_geoip_data(self, mock_geoip2):
the system must keep moving. Just GeoIP data won't be available.
"""
# Modify the request object to unset the `REMOTE_ADDR` IP meta data.
# That should make the using of `ipware.ip.get_real_ip()` method return
# an empty IP value. The system must deal with empty IP addresses.
# That should make the using of `ipware.ip.get_client_ip()` method
# return an empty IP value. The system must deal with empty IP
# addresses.
self.request.META['REMOTE_ADDR'] = ''

tracker = Tracker.objects.create_from_request(self.request, self.post)

# Now check the results. Empty data for IP address and GeoIP stuff.
self.assertEqual(tracker.ip_address, '')
self.assertEqual(tracker.ip_address, None)
self.assertEqual(tracker.ip_country, '')
self.assertEqual(tracker.ip_region, '')
self.assertEqual(tracker.ip_city, '')
Expand Down
4 changes: 2 additions & 2 deletions tracking_analyzer/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.http import HttpRequest

from geoip2.errors import GeoIP2Error
from ipware.ip import get_real_ip
from ipware.ip import get_client_ip


logger = logging.getLogger('tracking_analyzer')
Expand Down Expand Up @@ -50,7 +50,7 @@ def create_from_request(self, request, content_object):
city = {}

# Get the IP address and so the geographical info, if available.
ip_address = get_real_ip(request) or ''
ip_address, _ = get_client_ip(request) or ''
if not ip_address:
logger.debug(
'Could not determine IP address for request %s', request)
Expand Down

0 comments on commit 5c752f6

Please sign in to comment.