Skip to content

Commit

Permalink
Fix for issue analytehealth#27
Browse files Browse the repository at this point in the history
  • Loading branch information
Val Kolovos committed Mar 27, 2015
1 parent acdfbf1 commit 1b6c042
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ License

Change Log
----------
- 1.0.1
- Fix for issue #27 - User-agents with non-ascii characters cause collect_reporting_stats command to fail
- 1.0
- Modeling for analytics reporting (#25)
- Adding a number of reports:
Expand Down
2 changes: 1 addition & 1 deletion djanalytics/management/commands/collect_reporting_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def create_page_visits(self, start, end):
created_page_visits = []
user_agent_md5 = device = None
if request_event.user_agent:
user_agent_md5 = md5(request_event.user_agent).hexdigest()
user_agent_md5 = md5(request_event.user_agent.encode('utf-8')).hexdigest()
device = device_cache.get(user_agent_md5)
if user_agent_md5 and not device:
user_agent = parse(request_event.user_agent)
Expand Down
32 changes: 32 additions & 0 deletions djanalytics/tests/test_collect_reporting_stats_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta, date
from mock import Mock
from os import path

from django.test.testcases import TestCase

Expand Down Expand Up @@ -126,6 +128,36 @@ def test_collect_no_funnel(self):
self.assertEqual(visit.last_page.path, '/page_three/123/')
self.assertEqual(visit.first_page.path, '/page_one')

def test_collect_non_ascii_user_agent(self):
tracking_key = models.generate_uuid()
tracking_user_id = models.generate_uuid()
f = open(
path.join(
path.dirname(path.abspath(__file__)),
'unicode_user_agent.txt'
)
)
user_agent = f.read()
f.close()
models.RequestEvent.objects.create(
ip_address='127.0.0.1',
user_agent=user_agent,
tracking_key=tracking_key,
tracking_user_id=tracking_user_id,
protocol='http',
domain='djanalytics.example.com',
path='page',
query_string='',
method='GET',
client=self.dja_client,
)
command = Command()
command.stdout = Mock()
try:
command.handle()
except UnicodeEncodeError:
self.fail()

def test_max_age(self):
freezer = freeze_time(datetime.now() - timedelta(days=15))
freezer.start()
Expand Down
1 change: 1 addition & 0 deletions djanalytics/tests/unicode_user_agent.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mozilla/5.0 (Linux; U; Android 4.1.2; ar-ye; SPH-D710 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 الجوال Safari/534.30/4.05d.1002.m7
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from setuptools import setup, find_packages
from setuptools_utils import minify

version = '1.0'
version = '1.0.1'

setup(
name='dj-analytics',
Expand Down

0 comments on commit 1b6c042

Please sign in to comment.