Commit caa49ced by Gabe Mulley

clean up some minor details

* Ensure "from future import __absolute__" is included in new files
* Clean up some doc strings
* Remove __ prefix from some internal test methods
parent 1b56a606
[run]
branch = True
omit = *mock*
include = eventtracking*
"""
Test the event tracking module
"""
from __future__ import absolute_import
from datetime import datetime
from unittest import TestCase
......@@ -28,9 +29,9 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
def test_event_simple_event_without_data(self):
track.event(sentinel.event_type)
self.__assert_backend_called_with(sentinel.event_type)
self.assert_backend_called_with(sentinel.event_type)
def __assert_backend_called_with(self, event_type, data=None, backend=None):
def assert_backend_called_with(self, event_type, data=None, backend=None):
"""Ensures the backend is called exactly once with the expected data."""
if not backend:
backend = self._mock_backend
......@@ -51,7 +52,7 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
}
)
self.__assert_backend_called_with(
self.assert_backend_called_with(
sentinel.event_type,
{
sentinel.key: sentinel.value
......@@ -64,8 +65,8 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
try:
track.event(sentinel.event_type)
self.__assert_backend_called_with(sentinel.event_type)
self.__assert_backend_called_with(
self.assert_backend_called_with(sentinel.event_type)
self.assert_backend_called_with(
sentinel.event_type, backend=another_backend)
finally:
track.BACKENDS.remove(another_backend)
......@@ -78,7 +79,7 @@ class TestTrack(TestCase): # pylint: disable=missing-docstring
try:
track.event(sentinel.event_type)
self.__assert_backend_called_with(
self.assert_backend_called_with(
sentinel.event_type, backend=another_backend)
finally:
track.BACKENDS.remove(another_backend)
......@@ -3,16 +3,18 @@ Track application events. Supports persisting events to multiple backends.
Best Practices:
* It is recommended that event types are namespaced using dot notation to
avoid naming collisions, similar to DNS names. For example:
org.edx.video.stop, edu.mit.audio.stop
avoid naming collisions, similar to DNS names. For example:
org.edx.video.stop, edu.mit.audio.stop
* Avoid using event type names that may cause collisions. The burden is
on the analyst to decide whether your event is equivalent to another
and should be grouped accordingly etc.
on the analyst to decide whether your event is equivalent to another
and should be grouped accordingly etc.
* Do not emit events that you don't own. This could negatively impact
the analysis of the event stream. If you suspect your event is
equivalent to another, say so in your documenation, and the analyst
can decide whether or not to group them.
the analysis of the event stream. If you suspect your event is
equivalent to another, say so in your documenation, and the analyst
can decide whether or not to group them.
"""
from __future__ import absolute_import
from datetime import datetime
import logging
......@@ -25,8 +27,9 @@ def event(event_type, data=None):
"""
Emit an event annotated with the UTC time when this function was called.
:event_type: A unique identification string for an event that has already been registered.
:data: A dictionary mapping field names to the value to include in the event. Note that all values provided must be serializable.
`event_type` is a unique identification string for an event that has already been registered.
`data` is a dictionary mapping field names to the value to include in the event.
Note that all values provided must be serializable.
"""
full_event = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment