Skip to content

Commit 127d32b

Browse files
committed
Removed type hint suffixes from unstructured events (snowplow#36)
1 parent e9474cd commit 127d32b

5 files changed

Lines changed: 3 additions & 90 deletions

File tree

CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ Added callbacks for flushing
44
Added Python-logging
55
Added Redis and gevent based async approach (#75)
66
Added thread-based AsyncBufferedConsumer (#74)
7-
Improved test coverage up to 50% (73)
7+
Improved test coverage up to 50% (#73)
88
Added ability to specify port for collector (#72) (TODO)
99
Added POST support to tracker (#70)
1010
Added Redis-based queue (#45)
1111
Added Buffered Consumer (#44)
1212
Changed user_id to be set on a per-event basis (#39)
13+
Removed type hint suffixes from unstructured events (#36)
1314

1415
Version 0.3.0 (2014-04-25)
1516
--------------------------

snowplow_tracker/payload.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -63,49 +63,6 @@ def add_dict(self, dict_, base64=False):
6363
for f in dict_:
6464
self.add(f, dict_[f])
6565

66-
@contract
67-
def add_unstruct(self, dict_, encode_base64,
68-
type_when_encoded, type_when_not_encoded):
69-
"""
70-
Add an encoded or unencoded JSON to the payload after verifying
71-
the contents of the dict
72-
73-
:param dict_: Dictionary of the payload to be generated
74-
:type dict_: dict(str:*)
75-
:param encode_base64: If the payload is base64 encoded
76-
:type encode_base64: bool
77-
:param type_when_encoded: Name of the field when encode_base64 is set
78-
:type type_when_encoded: str
79-
:param type_when_not_encoded: Name of the field when encode_base64 is not set
80-
:type type_when_not_encoded: str
81-
"""
82-
def raise_error(f, type_):
83-
raise RuntimeError("".join([f, " in dict is not a ", type_]))
84-
85-
types = ["int", "flt", "geo", "dt", "ts", "tms"]
86-
87-
for f in dict_:
88-
parts = f.split("$")
89-
if parts[-1] in types:
90-
type_ = parts[-1]
91-
if ((type_ == "int" and not isinstance(dict_[f], int)) or
92-
(type_ == "flt" and not isinstance(dict_[f], float)) or
93-
(type_ == "geo" and not isinstance(dict_[f], tuple)) or
94-
(type_ == "dt" and not isinstance(dict_[f], int)) or
95-
(type_ == "ts" and not isinstance(dict_[f], int)) or
96-
(type_ == "tms" and not isinstance(dict_[f], int))):
97-
raise_error(f, type_)
98-
json_dict = json.dumps(dict_)
99-
100-
if encode_base64:
101-
encoded_dict = base64.urlsafe_b64encode(json_dict.encode("ascii"))
102-
if not isinstance(encoded_dict, str):
103-
encoded_dict = encoded_dict.decode("utf-8")
104-
self.add(type_when_encoded, encoded_dict)
105-
106-
else:
107-
self.add(type_when_not_encoded, json_dict)
108-
10966
@contract
11067
def add_json(self, dict_, encode_base64, type_when_encoded, type_when_not_encoded):
11168
"""

snowplow_tracker/test/integration/test_integration.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -131,31 +131,6 @@ def test_integration_unstruct_event_base64(self):
131131
for key in expected_fields:
132132
self.assertEquals(from_querystring(key, querystrings[-1]), expected_fields[key])
133133

134-
def test_integration_unstruct_event_non_base64_error(self):
135-
t = tracker.Tracker(default_consumer, default_subject, encode_base64=False)
136-
try:
137-
t.track_unstruct_event("com.example_company", "viewed_product",
138-
{
139-
"product_id": "ASO01043",
140-
"price$flt": 49, # ERROR
141-
"walrus$tms": int(time.time() * 1000),
142-
})
143-
except RuntimeError as e:
144-
self.assertEquals("price$flt in dict is not a flt", str(e))
145-
146-
147-
def test_integration_unstruct_event_base64_error(self):
148-
t = tracker.Tracker(default_consumer, default_subject)
149-
try:
150-
t.track_unstruct_event("com.example_company", "viewed_product",
151-
{
152-
"product_id": "ASO01043",
153-
"price$flt": 49.95,
154-
"walrus$tms": "hello", # ERROR
155-
})
156-
except RuntimeError as e:
157-
self.assertEquals("walrus$tms in dict is not a tms", str(e))
158-
159134
def test_integration_standard_nv_pairs(self):
160135
t = tracker.Tracker(default_consumer, default_subject, "cf", app_id="angry-birds-android", context_vendor="com.example")
161136
default_subject.set_platform("mob")

snowplow_tracker/test/unit/test_payload.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,3 @@ def test_add_dict(self):
6767
p.add_dict({"name4": 4, "name3": 3}) # Order doesn't matter
6868
output = {"n1": "v1", "n2": "v2", "name3": 3, "name4": 4}
6969
self.assertTrue(is_subset(output, p.nv_pairs))
70-
71-
def test_add_unstruct_1(self):
72-
p = payload.Payload()
73-
try:
74-
p.add_unstruct({"product_id": "ASO01043",
75-
"price$flt": 33, # ERROR
76-
"walrus$tms": int(time.time() * 1000),
77-
}, False, "ue_px", "ue_pe")
78-
except RuntimeError as e:
79-
self.assertEquals("price$flt in dict is not a flt", str(e))
80-
81-
def test_add_unstruct_2(self):
82-
p = payload.Payload()
83-
try:
84-
p.add_unstruct({"product_id": "ASO01043",
85-
"price$flt": 33.3,
86-
"walrus$tms": "hello world!", # ERROR
87-
}, True, "ue_px", "ue_pe")
88-
except RuntimeError as e:
89-
self.assertEquals("walrus$tms in dict is not a tms", str(e))

snowplow_tracker/tracker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def track_unstruct_event(self, event_vendor, event_name, dict_, context=None, ts
349349

350350
pb.add("e", "ue")
351351
pb.add("ue_na", event_name)
352-
pb.add_unstruct(dict_, self.encode_base64, "ue_px", "ue_pr")
352+
pb.add_json(dict_, self.encode_base64, "ue_px", "ue_pr")
353353
pb.add("evn", event_vendor)
354354

355355
dtm = Tracker.get_timestamp(tstamp)

0 commit comments

Comments
 (0)