Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ Contributing quickstart
Assuming Git, Vagrant_ and VirtualBox_ are installed:

::
host$ git clone git@github.com:snowplow/snowplow-python-tracker.git
host$ vagrant up && vagrant ssh
guest$ cd /vagrant
guest$ ./run-tests.sh

host$ git clone git@github.com:snowplow/snowplow-python-tracker.git
host$ vagrant up && vagrant ssh
guest$ cd /vagrant
guest$ ./run-tests.sh

.. _Vagrant: http://docs.vagrantup.com/v2/installation/index.html
.. _VirtualBox: https://www.virtualbox.org/wiki/Downloads
Expand All @@ -64,7 +65,8 @@ Publishing
##########

::
host$ vagrant push

host$ vagrant push

Copyright and license
#####################
Expand Down
3 changes: 3 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
httmock
freezegun
14 changes: 14 additions & 0 deletions snowplow_tracker/subject.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,17 @@ def set_network_user_id(self, nuid):
"""
self.standard_nv_pairs["tnuid"] = nuid
return self

@contract
def set_txn_id(self, txn_id):
"""
Set Transaction ID set client-side, used to de-dupe records.

:param txn_id: Network user ID
:type txn_id: int
:rtype: subject
"""
# Unfortunatly real name of this field is `tid`. This difference in
# documentation is little confusing.
self.standard_nv_pairs["tid"] = txn_id
return self
28 changes: 22 additions & 6 deletions snowplow_tracker/test/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_integration_page_view(self):
t.track_page_view("http://savethearctic.org", "Save The Arctic", "http://referrer.com")
expected_fields = {"e": "pv", "page": "Save+The+Arctic", "url": "http%3A%2F%2Fsavethearctic.org", "refr": "http%3A%2F%2Freferrer.com"}
for key in expected_fields:
self.assertEquals(from_querystring(key, querystrings[-1]), expected_fields[key])
self.assertEquals(from_querystring(key, querystrings[-1]), expected_fields[key])

def test_integration_ecommerce_transaction_item(self):
t = tracker.Tracker([default_emitter], default_subject)
Expand All @@ -94,15 +94,15 @@ def test_integration_ecommerce_transaction(self):
t = tracker.Tracker([default_emitter], default_subject)
with HTTMock(pass_response_content):
t.track_ecommerce_transaction("6a8078be", 35, city="London", currency="GBP", items=
[{
[{
"sku": "pbz0026",
"price": 20,
"quantity": 1
},
{
"sku": "pbz0038",
"price": 15,
"quantity": 1
"quantity": 1
}])

expected_fields = {"e": "tr", "tr_id": "6a8078be", "tr_tt": "35", "tr_ci": "London", "tr_cu": "GBP"}
Expand All @@ -124,7 +124,7 @@ def test_integration_screen_view(self):
with HTTMock(pass_response_content):
t.track_screen_view("Game HUD 2", id_="534")
expected_fields = {"e": "ue"}
for key in expected_fields:
for key in expected_fields:
self.assertEquals(from_querystring(key, querystrings[-1]), expected_fields[key])
envelope_string = from_querystring("ue_pr", querystrings[-1])
envelope = json.loads(unquote_plus(envelope_string))
Expand Down Expand Up @@ -184,7 +184,7 @@ def test_integration_context_non_base64(self):
"schema": "iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-1",
"data":[{"schema": "iglu:com.example/user/jsonschema/2-0-3", "data": {"user_type": "tester"}}]
})

def test_integration_context_base64(self):
t = tracker.Tracker([default_emitter], default_subject, encode_base64=True)
with HTTMock(pass_response_content):
Expand All @@ -195,7 +195,7 @@ def test_integration_context_base64(self):
"schema": "iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-1",
"data":[{"schema": "iglu:com.example/user/jsonschema/2-0-3", "data": {"user_type": "tester"}}]
})

def test_integration_standard_nv_pairs(self):
s = subject.Subject()
s.set_platform("mob")
Expand Down Expand Up @@ -235,6 +235,22 @@ def test_integration_identification_methods(self):
for key in expected_fields:
self.assertEquals(from_querystring(key, querystrings[-1]), expected_fields[key])

def test_integration_transaction(self):
s = subject.Subject()
s.set_domain_user_id("4616bfb38f872d16")
s.set_txn_id(10000)

t = tracker.Tracker([emitters.Emitter("localhost")], s, "cf", app_id="angry-birds-android")
with HTTMock(pass_response_content):
t.track_page_view("localhost", "local host")
expected_fields = {
"duid": "4616bfb38f872d16",
"tid": '10000'
}
for key in expected_fields:
self.assertEquals(from_querystring(key, querystrings[-1]), expected_fields[key])


def test_integration_redis_default(self):
r = redis.StrictRedis()
t = tracker.Tracker([emitters.RedisEmitter()], default_subject)
Expand Down