Skip to content

Commit 5e4e2a3

Browse files
committed
Added custom context vendor configuration option (snowplow#67)
1 parent 86d5e5f commit 5e4e2a3

6 files changed

Lines changed: 15 additions & 7 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: python
22
python:
33
- "2.7"
4+
- "3.2"
45
- "3.3"
56
# command to install dependencies
67
install:

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Version 0.3.0 (2014-xx-xx)
22
--------------------------
3+
Added custom context vendor configuration option (#67)
34
Changed the return value of the tracking methods to a tuple (#65)
45
Added coveralls code coverage button (#64)
56
Added currency parameter to ecommerce tracking methods (#62)

snowplow_tracker/payload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def add_json(self, dict_, encode_base64, type_when_encoded, type_when_not_encode
145145
:type type_when_not_encoded: str
146146
"""
147147

148-
if type(dict_) == "dict" and dict_ != {}:
148+
if dict_ is not None and dict_ != {}:
149149

150150
json_dict = json.dumps(dict_)
151151

snowplow_tracker/test/integration/test_integration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,18 @@ def test_integration_unstruct_event_base64_error(self):
153153
self.assertEquals("walrus$tms in dict is not a tms", str(e))
154154

155155
def test_integration_standard_nv_pairs(self):
156-
t = tracker.Tracker("localhost", "cf", app_id="angry-birds-android")
156+
t = tracker.Tracker("localhost", "cf", app_id="angry-birds-android", context_vendor="com.example")
157157
t.set_platform("mob")
158158
t.set_user_id("user12345")
159159
t.set_screen_resolution(100, 200)
160160
t.set_color_depth(24)
161161
t.set_timezone("Europe London")
162162
t.set_lang("en")
163163
with HTTMock(pass_response_content):
164-
t.track_page_view("localhost", "local host", None)
165-
expected_fields = {"tna": "cf", "evn": "com.snowplowanalytics", "res": "100x200", "lang": "en", "aid": "angry-birds-android", "cd": "24", "tz": "Europe+London", "p": "mob", "tv": "py-" + _version.__version__}
164+
t.track_page_view("localhost", "local host", None, {'user': {'user_type': 'tester'}})
165+
expected_fields = {"tna": "cf", "evn": "com.snowplowanalytics", "res": "100x200",
166+
"lang": "en", "aid": "angry-birds-android", "cd": "24", "tz": "Europe+London",
167+
"p": "mob", "tv": "py-" + _version.__version__, "cv": "com.example"}
166168
for key in expected_fields:
167169
self.assertEquals(from_querystring(key, querystrings[-1]), expected_fields[key])
168170

snowplow_tracker/test/unit/test_tracker.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ def setUp(self):
3030
pass
3131

3232
def test_initialisation(self):
33-
t = Tracker("d3rkrsqld9gmqf.cloudfront.net", "cloudfront", encode_base64= False, app_id="AF003")
33+
t = Tracker("d3rkrsqld9gmqf.cloudfront.net", "cloudfront", encode_base64= False, app_id="AF003", context_vendor="com.example")
3434
self.assertEquals(t.standard_nv_pairs["tna"], "cloudfront")
3535
self.assertEquals(t.standard_nv_pairs["aid"], "AF003")
3636
self.assertEquals(t.config["encode_base64"], False)
37+
self.assertEquals(t.config["context_vendor"], "com.example")
3738

3839
"""
3940
Testing URI generator

snowplow_tracker/tracker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Tracker:
5151
new_contract("payload", lambda s: isinstance(s, payload.Payload))
5252

5353
def __init__(self, collector_uri,
54-
namespace=None, app_id=None, encode_base64=DEFAULT_ENCODE_BASE64, contracts=True):
54+
namespace=None, app_id=None, context_vendor=None, encode_base64=DEFAULT_ENCODE_BASE64, contracts=True):
5555
"""
5656
Constructor
5757
"""
@@ -61,7 +61,8 @@ def __init__(self, collector_uri,
6161
self.collector_uri = self.as_collector_uri(collector_uri)
6262

6363
self.config = {
64-
"encode_base64": encode_base64
64+
"encode_base64": encode_base64,
65+
"context_vendor": context_vendor
6566
}
6667

6768
self.standard_nv_pairs = {
@@ -195,6 +196,8 @@ def track(self, pb):
195196
:rtype: tuple(bool, int | str)
196197
"""
197198
pb.add_dict(self.standard_nv_pairs)
199+
if "co" in pb.context or "cx" in pb.context:
200+
pb.add("cv", self.config["context_vendor"])
198201
return self.http_get(pb)
199202

200203
@contract

0 commit comments

Comments
 (0)