From 367bee3643ad870dea03223497fea526fd75be04 Mon Sep 17 00:00:00 2001 From: Mikhail Kashkin Date: Wed, 10 Jun 2015 17:07:45 +0300 Subject: [PATCH 1/6] fix docs --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 981a1ea5..8d079c73 100644 --- a/README.rst +++ b/README.rst @@ -52,8 +52,8 @@ 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 + host$ git clone git@github.com:snowplow/snowplow-python-tracker.git + host$ vagrant up && vagrant ssh guest$ cd /vagrant guest$ ./run-tests.sh @@ -64,7 +64,7 @@ Publishing ########## :: - host$ vagrant push + host$ vagrant push Copyright and license ##################### From e7bec78268501ddf92132b27e6211f8e0952b187 Mon Sep 17 00:00:00 2001 From: Mikhail Kashkin Date: Wed, 10 Jun 2015 17:08:38 +0300 Subject: [PATCH 2/6] another try --- README.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 8d079c73..3883aed3 100644 --- a/README.rst +++ b/README.rst @@ -52,10 +52,10 @@ 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 @@ -64,7 +64,7 @@ Publishing ########## :: - host$ vagrant push + host$ vagrant push Copyright and license ##################### From 9812a24e04c197b7d8566d66fbaccda8036ca1d2 Mon Sep 17 00:00:00 2001 From: Mikhail Kashkin Date: Wed, 10 Jun 2015 17:10:25 +0300 Subject: [PATCH 3/6] Update README.rst --- README.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rst b/README.rst index 3883aed3..1b36772f 100644 --- a/README.rst +++ b/README.rst @@ -52,6 +52,7 @@ 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 @@ -64,6 +65,7 @@ Publishing ########## :: + host$ vagrant push Copyright and license From 8adcb4d513edf33a57041a69e8aceafd4d13764d Mon Sep 17 00:00:00 2001 From: Mikhail Kashkin Date: Wed, 10 Jun 2015 18:31:03 +0300 Subject: [PATCH 4/6] added txn_id support --- requirements-test.txt | 3 ++ snowplow_tracker/subject.py | 12 ++++++++ .../test/integration/test_integration.py | 28 +++++++++++++++---- 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 requirements-test.txt diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 00000000..e4d3153e --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,3 @@ +pytest +httmock +freezegun diff --git a/snowplow_tracker/subject.py b/snowplow_tracker/subject.py index 64c5374e..cfb989bb 100644 --- a/snowplow_tracker/subject.py +++ b/snowplow_tracker/subject.py @@ -162,3 +162,15 @@ 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 + """ + self.standard_nv_pairs["txn_id"] = txn_id + return self diff --git a/snowplow_tracker/test/integration/test_integration.py b/snowplow_tracker/test/integration/test_integration.py index f5095aa7..a47d4114 100644 --- a/snowplow_tracker/test/integration/test_integration.py +++ b/snowplow_tracker/test/integration/test_integration.py @@ -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) @@ -94,7 +94,7 @@ 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 @@ -102,7 +102,7 @@ def test_integration_ecommerce_transaction(self): { "sku": "pbz0038", "price": 15, - "quantity": 1 + "quantity": 1 }]) expected_fields = {"e": "tr", "tr_id": "6a8078be", "tr_tt": "35", "tr_ci": "London", "tr_cu": "GBP"} @@ -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)) @@ -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): @@ -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") @@ -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", + "txn_id": '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) From 632d7d144a2afec53045e64540809fd4bf37ab1d Mon Sep 17 00:00:00 2001 From: Mikhail Kashkin Date: Tue, 16 Jun 2015 12:26:50 +0300 Subject: [PATCH 5/6] set different name for txn_id param --- snowplow_tracker/subject.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/snowplow_tracker/subject.py b/snowplow_tracker/subject.py index cfb989bb..34212124 100644 --- a/snowplow_tracker/subject.py +++ b/snowplow_tracker/subject.py @@ -166,11 +166,13 @@ def set_network_user_id(self, nuid): @contract def set_txn_id(self, txn_id): """ - Set Transaction ID set client-side, used to de-dupe records + Set Transaction ID set client-side, used to de-dupe records. :param txn_id: Network user ID :type txn_id: int :rtype: subject """ - self.standard_nv_pairs["txn_id"] = txn_id + # Unfortunatly real name of this field is `tid`. This difference in + # documentation is little confusing. + self.standard_nv_pairs["tid"] = txn_id return self From e7317b3a8de599db8e5f781869f3547415a44cb7 Mon Sep 17 00:00:00 2001 From: Mikhail Kashkin Date: Tue, 16 Jun 2015 15:00:03 +0300 Subject: [PATCH 6/6] Forgot to fix tests --- snowplow_tracker/test/integration/test_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snowplow_tracker/test/integration/test_integration.py b/snowplow_tracker/test/integration/test_integration.py index a47d4114..103ad1cc 100644 --- a/snowplow_tracker/test/integration/test_integration.py +++ b/snowplow_tracker/test/integration/test_integration.py @@ -245,7 +245,7 @@ def test_integration_transaction(self): t.track_page_view("localhost", "local host") expected_fields = { "duid": "4616bfb38f872d16", - "txn_id": '10000' + "tid": '10000' } for key in expected_fields: self.assertEquals(from_querystring(key, querystrings[-1]), expected_fields[key])