Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
5be58fc1
Commit
5be58fc1
authored
Mar 11, 2014
by
David Baumgold
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2883 from edx/db/fix-import
Fix undefined references to pytz, and update tests
parents
5e4c25dd
f25a7870
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
20 deletions
+17
-20
common/djangoapps/track/tests/test_views.py
+13
-16
common/djangoapps/track/views.py
+4
-4
No files found.
common/djangoapps/track/tests/test_views.py
View file @
5be58fc1
# pylint: disable=missing-docstring,maybe-no-member
from
datetime
import
datetime
from
mock
import
patch
from
mock
import
sentinel
from
pytz
import
UTC
from
track
import
views
from
mock
import
patch
,
sentinel
from
freezegun
import
freeze_time
from
django.test
import
TestCase
from
django.test.client
import
RequestFactory
from
track
import
views
from
datetime
import
datetime
expected_time
=
datetime
(
2013
,
10
,
3
,
8
,
24
,
55
)
class
TestTrackViews
(
TestCase
):
...
...
@@ -21,12 +20,6 @@ class TestTrackViews(TestCase):
self
.
mock_tracker
=
patcher
.
start
()
self
.
addCleanup
(
patcher
.
stop
)
self
.
_expected_timestamp
=
datetime
.
now
(
UTC
)
self
.
_datetime_patcher
=
patch
(
'track.views.datetime'
)
self
.
addCleanup
(
self
.
_datetime_patcher
.
stop
)
mock_datetime_mod
=
self
.
_datetime_patcher
.
start
()
mock_datetime_mod
.
datetime
.
now
.
return_value
=
self
.
_expected_timestamp
# pylint: disable=maybe-no-member
self
.
path_with_course
=
'/courses/foo/bar/baz/xmod/'
self
.
url_with_course
=
'http://www.edx.org'
+
self
.
path_with_course
...
...
@@ -34,6 +27,7 @@ class TestTrackViews(TestCase):
sentinel
.
key
:
sentinel
.
value
}
@freeze_time
(
expected_time
)
def
test_user_track
(
self
):
request
=
self
.
request_factory
.
get
(
'/event'
,
{
'page'
:
self
.
url_with_course
,
...
...
@@ -51,7 +45,7 @@ class TestTrackViews(TestCase):
'event'
:
'{}'
,
'agent'
:
''
,
'page'
:
self
.
url_with_course
,
'time'
:
self
.
_expected_timestamp
,
'time'
:
expected_time
,
'host'
:
'testserver'
,
'context'
:
{
'course_id'
:
'foo/bar/baz'
,
...
...
@@ -60,6 +54,7 @@ class TestTrackViews(TestCase):
}
self
.
mock_tracker
.
send
.
assert_called_once_with
(
expected_event
)
@freeze_time
(
expected_time
)
def
test_server_track
(
self
):
request
=
self
.
request_factory
.
get
(
self
.
path_with_course
)
views
.
server_track
(
request
,
str
(
sentinel
.
event_type
),
'{}'
)
...
...
@@ -72,12 +67,13 @@ class TestTrackViews(TestCase):
'event'
:
'{}'
,
'agent'
:
''
,
'page'
:
None
,
'time'
:
self
.
_expected_timestamp
,
'time'
:
expected_time
,
'host'
:
'testserver'
,
'context'
:
{},
}
self
.
mock_tracker
.
send
.
assert_called_once_with
(
expected_event
)
@freeze_time
(
expected_time
)
def
test_server_track_with_no_request
(
self
):
request
=
None
views
.
server_track
(
request
,
str
(
sentinel
.
event_type
),
'{}'
)
...
...
@@ -90,12 +86,13 @@ class TestTrackViews(TestCase):
'event'
:
'{}'
,
'agent'
:
''
,
'page'
:
None
,
'time'
:
self
.
_expected_timestamp
,
'time'
:
expected_time
,
'host'
:
''
,
'context'
:
{},
}
self
.
mock_tracker
.
send
.
assert_called_once_with
(
expected_event
)
@freeze_time
(
expected_time
)
def
test_task_track
(
self
):
request_info
=
{
'username'
:
'anonymous'
,
...
...
@@ -120,7 +117,7 @@ class TestTrackViews(TestCase):
'event'
:
expected_event_data
,
'agent'
:
'agent'
,
'page'
:
None
,
'time'
:
self
.
_expected_timestamp
,
'time'
:
expected_time
,
'host'
:
'testserver'
,
'context'
:
{
'course_id'
:
''
,
...
...
common/djangoapps/track/views.py
View file @
5be58fc1
import
datetime
from
pytz
import
UTC
import
pytz
from
django.contrib.auth.decorators
import
login_required
from
django.http
import
HttpResponse
...
...
@@ -59,7 +59,7 @@ def user_track(request):
"event"
:
request
.
REQUEST
[
'event'
],
"agent"
:
_get_request_header
(
request
,
'HTTP_USER_AGENT'
),
"page"
:
page
,
"time"
:
datetime
.
datetime
.
now
(
UTC
),
"time"
:
datetime
.
datetime
.
utcnow
(
),
"host"
:
_get_request_header
(
request
,
'SERVER_NAME'
),
"context"
:
eventtracker
.
get_tracker
()
.
resolve_context
(),
}
...
...
@@ -92,7 +92,7 @@ def server_track(request, event_type, event, page=None):
"event"
:
event
,
"agent"
:
_get_request_header
(
request
,
'HTTP_USER_AGENT'
),
"page"
:
page
,
"time"
:
datetime
.
datetime
.
now
(
UTC
),
"time"
:
datetime
.
datetime
.
utcnow
(
),
"host"
:
_get_request_header
(
request
,
'SERVER_NAME'
),
"context"
:
eventtracker
.
get_tracker
()
.
resolve_context
(),
}
...
...
@@ -136,7 +136,7 @@ def task_track(request_info, task_info, event_type, event, page=None):
"event"
:
full_event
,
"agent"
:
request_info
.
get
(
'agent'
,
'unknown'
),
"page"
:
page
,
"time"
:
datetime
.
datetime
.
now
(
UTC
),
"time"
:
datetime
.
datetime
.
utcnow
(
),
"host"
:
request_info
.
get
(
'host'
,
'unknown'
),
"context"
:
eventtracker
.
get_tracker
()
.
resolve_context
(),
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment