def test_unauthorized(self): BUCKETNAME = uuid.uuid4().hex DESCRIPTION = uuid.uuid4().hex result = yield request( "POST", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=self.password, data={"description":DESCRIPTION}) self.assertEqual(result.code, 201) result = yield request( "GET", "%s/%s" % (self.url, BUCKETNAME), username="******", password="******") self.assertEqual(result.code, 401) result = yield request( "GET", "%s/%s" % (self.url, BUCKETNAME), username=self.username2, password=self.password2) self.assertEqual(result.code, 401) result = yield request( "DELETE", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=self.password) self.assertEqual(result.code, 200)
def tearDown(self): yield request( "DELETE", self.url, username=self.username, password=self.password) yield request( "DELETE", "http://127.0.0.1:8080/%s" % self.username, username=self.username, password=self.password) self.hiitrack.stopService()
def test_set(self): event_name_1 = "Event 1 %s" % uuid.uuid4().hex event_name_2 = "Event 2 %s" % uuid.uuid4().hex event_name_3 = "Event 2 %s" % uuid.uuid4().hex visitor_id_2 = uuid.uuid4().hex events = [event_name_1] properties = [] message = b64encode(ujson.dumps([ events, properties])) qs = urlencode({"message": message}) response = yield request( "GET", "%s/batch?%s" % (self.url, qs)) for cookie in response.cookies: if cookie.name == "v": break self.assertEqual(ujson.loads(response.body)["visitor_id"], cookie.value) visitor_id_1 = cookie.value qs = urlencode({ "message": message, "visitor_id": visitor_id_1}) response = yield request( "GET", "%s/batch?%s" % (self.url, qs)) for cookie in response.cookies: if cookie.name == "v": break self.assertEqual(cookie.value, visitor_id_1) self.assertEqual(ujson.loads(response.body)["visitor_id"], visitor_id_1) qs = urlencode({ "message": message, "visitor_id": visitor_id_2}) response = yield request( "GET", "%s/batch?%s" % (self.url, qs)) for cookie in response.cookies: if cookie.name == "v": break self.assertEqual(cookie.value, visitor_id_2) self.assertEqual(ujson.loads(response.body)["visitor_id"], visitor_id_2) qs = urlencode({ "message": message, "visitor_id": visitor_id_1}) response = yield request( "GET", "%s/batch?%s" % (self.url, qs)) for cookie in response.cookies: if cookie.name == "v": break self.assertEqual(cookie.value, visitor_id_1) self.assertEqual(ujson.loads(response.body)["visitor_id"], visitor_id_1)
def tearDown(self): yield request( "DELETE", "http://127.0.0.1:8080/%s" % self.username, username=self.username, password=self.password) yield request( "DELETE", "http://127.0.0.1:8080/%s" % self.username2, username=self.username2, password=self.password2) # Despite beforeShutdown hooks, Twisted complains. self.hiitrack.stopService()
def test_bucket(self): NAME = uuid.uuid4().hex VALUE = uuid.uuid4().hex VISITOR_ID = uuid.uuid4().hex qs = urlencode({"value":b64encode(ujson.dumps(VALUE))}) result = yield request( "POST", "%s/property/%s?%s" % (self.url, quote(NAME), qs), data={"visitor_id":VISITOR_ID}) result = yield request( "GET", self.url, username=self.username, password=self.password) self.assertTrue(NAME in ujson.loads(result.body)["properties"].values())
def test_create(self): VISITOR_ID_1 = uuid.uuid4().hex EVENT_1 = "Event 1 %s" % uuid.uuid4().hex EVENT_2 = "Event 2 %s" % uuid.uuid4().hex yield self.post_event(VISITOR_ID_1, EVENT_1) yield self.post_event(VISITOR_ID_1, EVENT_2) events = yield self.get_event_dict() event_id_1 = events[EVENT_1] event_id_2 = events[EVENT_2] FUNNEL_NAME = uuid.uuid4().hex DESCRIPTION = uuid.uuid4().hex result = yield request( "POST", "%s/funnel/%s" % (self.url, FUNNEL_NAME), username=self.username, password=self.password, data=[ ("description", DESCRIPTION), ("event_id",event_id_1), ("event_id",event_id_2)]) self.assertEqual(result.code, 201) result = yield request( "GET", "%s/funnel/%s" % (self.url, FUNNEL_NAME), username=self.username, password=self.password) self.assertEqual(result.code, 200) returned_description = ujson.decode(result.body)["description"] self.assertEqual(DESCRIPTION, returned_description) returned_event_ids = ujson.decode(result.body)["event_ids"] self.assertTrue(event_id_1 in returned_event_ids) self.assertTrue(event_id_2 in returned_event_ids) funnel = ujson.decode(result.body)["funnel"] unique_funnel = ujson.decode(result.body)["unique_funnel"] self.assertEqual(funnel[0][0], event_id_1) self.assertEqual(funnel[1][0], event_id_2) self.assertEqual(funnel[0][1], 1) self.assertEqual(funnel[1][1], 1) self.assertEqual(unique_funnel[0][0], event_id_1) self.assertEqual(unique_funnel[1][0], event_id_2) self.assertEqual(unique_funnel[0][1], 1) self.assertEqual(unique_funnel[1][1], 1) result = yield request( "DELETE", "%s/funnel/%s" % (self.url, FUNNEL_NAME), username=self.username, password=self.password) self.assertEqual(result.code, 200)
def test_dynamic_by_name(self): VISITOR_ID_1 = uuid.uuid4().hex EVENT_1 = "Event 1 %s" % uuid.uuid4().hex EVENT_2 = "Event 2 %s" % uuid.uuid4().hex yield self.post_event(VISITOR_ID_1, EVENT_1) yield self.post_event(VISITOR_ID_1, EVENT_2) events = yield self.get_event_dict() event_id_1 = events[EVENT_1] event_id_2 = events[EVENT_2] qs = urlencode([("event", EVENT_1), ("event", EVENT_2)]) result = yield request( "GET", "%s/funnel?%s" % (self.url, qs), username=self.username, password=self.password) self.assertEqual(result.code, 200) returned_event_ids = ujson.decode(result.body)["event_ids"] self.assertTrue(event_id_1 in returned_event_ids) self.assertTrue(event_id_2 in returned_event_ids) funnel = ujson.decode(result.body)["funnel"] unique_funnel = ujson.decode(result.body)["unique_funnel"] self.assertEqual(funnel[0][0], event_id_1) self.assertEqual(funnel[1][0], event_id_2) self.assertEqual(funnel[0][1], 1) self.assertEqual(funnel[1][1], 1) self.assertEqual(unique_funnel[0][0], event_id_1) self.assertEqual(unique_funnel[1][0], event_id_2) self.assertEqual(unique_funnel[0][1], 1) self.assertEqual(unique_funnel[1][1], 1)
def post_event(self, visitor_id, name): result = yield request( "POST", "%s/event/%s" % (self.url, quote(name)), data={"visitor_id":visitor_id}) self.assertEqual(result.code, 200) returnValue(result)
def setUp(self): self.hiitrack = HiiTrack(8080) self.hiitrack.startService() self.username = uuid.uuid4().hex self.password = uuid.uuid4().hex self.username2 = uuid.uuid4().hex self.password2 = uuid.uuid4().hex yield request( "POST", "http://127.0.0.1:8080/%s" % self.username, data={"password":self.password}) self.url = "http://127.0.0.1:8080/%s" % self.username yield request( "POST", "http://127.0.0.1:8080/%s" % self.username2, data={"password":self.password2})
def post_property(self, visitor_id, name, value): result = yield request( "POST", "%s/property/%s/%s" % (self.url, quote(name), quote(value)), data={"visitor_id":visitor_id}) self.assertEqual(result.code, 200) returnValue(result)
def test_missing(self): BUCKETNAME = uuid.uuid4().hex result = yield request( "GET", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=self.password) self.assertEqual(result.code, 404)
def post_property(self, visitor_id, name, value): qs = urlencode({"value":b64encode(ujson.dumps(value))}) result = yield request( "POST", "%s/property/%s?%s" % (self.url, quote(name), qs), data={"visitor_id":visitor_id}) self.assertEqual(result.code, 200) returnValue(result)
def get_event(self, name): result = yield request( "GET", str("%s/event/%s" % (self.url, quote(name))), username=self.username, password=self.password) self.assertEqual(result.code, 200) returnValue(ujson.loads(result.body))
def get_property(self, name, value): properties = yield self.get_property_dict() result = yield request( "GET", str("%s/property/%s/%s" % (self.url, quote(name), quote(value))), username=self.username, password=self.password) self.assertEqual(result.code, 200) returnValue(ujson.loads(result.body))
def get_event_dict(self): result = yield request( "GET", self.url, username=self.username, password=self.password) self.assertEqual(result.code, 200) result = ujson.loads(result.body)["events"] returnValue(result)
def test_duplicate(self): USERNAME = uuid.uuid4().hex PASSWORD = "******" result = yield request( "POST", "http://127.0.0.1:8080/%s" % USERNAME, data={"password":PASSWORD}) self.assertEqual(result.code, 201) result = yield request( "POST", "http://127.0.0.1:8080/%s" % USERNAME, data={"password":PASSWORD}) self.assertEqual(result.code, 403) result = yield request( "DELETE", "http://127.0.0.1:8080/%s" % USERNAME, username=USERNAME, password=PASSWORD) self.assertEqual(result.code, 200)
def setUp(self): self.hiitrack = HiiTrack(8080) self.hiitrack.startService() self.username = uuid.uuid4().hex self.password = uuid.uuid4().hex yield request( "POST", "http://127.0.0.1:8080/%s" % self.username, data={"password":self.password}) self.description = uuid.uuid4().hex self.url = "http://127.0.0.1:8080/%s/%s" % ( self.username, uuid.uuid4().hex) result = yield request( "POST", self.url, username=self.username, password=self.password, data={"description":self.description})
def get_event_dict(self): result = yield request( "GET", self.url, username=self.username, password=self.password) self.assertEqual(result.code, 200) events = ujson.loads(result.body)["events"].items() result = dict([(k, v["id"]) for k,v in events]) returnValue(result)
def get_property(self, name): result = yield request( "GET", str("%s/property/%s" % (self.url, quote(name))), username=self.username, password=self.password) self.assertEqual(result.code, 200) data = ujson.loads(result.body) data["value_ids"] = dict([(data["values"][x]["value"], x) for x in data["values"]]) returnValue(data)
def test_post(self): NAME = uuid.uuid4().hex VALUE = uuid.uuid4().hex VISITOR_ID = uuid.uuid4().hex qs = urlencode({"value":b64encode(ujson.dumps(VALUE))}) result = yield request( "POST", "%s/property/%s?%s" % (self.url, quote(NAME), qs), data={"visitor_id":VISITOR_ID}) self.assertEqual(result.code, 200)
def test_bucket_access(self): BUCKETNAME = uuid.uuid4().hex DESCRIPTION = uuid.uuid4().hex result = yield request( "POST", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=self.password, data={"description":DESCRIPTION}) self.assertEqual(result.code, 201) bucket_pass = b64encode(sha1("%s:%s" % (BUCKETNAME, sha1("%s:%s" % (self.username, self.password)).digest())).digest()) result = yield request( "GET", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=bucket_pass) self.assertEqual(result.code, 200) result = yield request( "DELETE", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=self.password) self.assertEqual(result.code, 200)
def test_create(self): BUCKETNAME = uuid.uuid4().hex DESCRIPTION = uuid.uuid4().hex result = yield request( "POST", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=self.password, data={"description":DESCRIPTION}) self.assertEqual(result.code, 201) result = yield request( "GET", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=self.password) self.assertEqual(result.code, 200) returned_description = ujson.decode(result.body)["description"] result = yield request( "DELETE", "%s/%s" % (self.url, BUCKETNAME), username=self.username, password=self.password) self.assertEqual(result.code, 200)
def test_dynamic_create(self): BUCKET_NAME_1 = uuid.uuid4().hex BUCKET_NAME_2 = uuid.uuid4().hex BUCKET_NAME_3 = uuid.uuid4().hex EVENT_NAME = uuid.uuid4().hex PROPERTY_NAME = uuid.uuid4().hex PROPERTY_VALUE = uuid.uuid4().hex VISITOR_ID = uuid.uuid4().hex yield request( "POST", "%s/%s/event/%s" % (self.url, BUCKET_NAME_1, EVENT_NAME), data={"visitor_id":VISITOR_ID}) result = yield request( "GET", "%s/%s" % (self.url, BUCKET_NAME_1), username=self.username, password=self.password) self.assertEqual(result.code, 200) qs = urlencode({"value":b64encode(ujson.dumps(PROPERTY_VALUE))}) yield request( "POST", "%s/%s/property/%s?%s" % ( self.url, BUCKET_NAME_2, PROPERTY_NAME, qs), data={"visitor_id":VISITOR_ID}) result = yield request( "GET", "%s/%s" % (self.url, BUCKET_NAME_2), username=self.username, password=self.password) self.assertEqual(result.code, 200) events = [EVENT_NAME] properties = [[PROPERTY_NAME, PROPERTY_VALUE]] message = b64encode(ujson.dumps([ events, properties])) qs = urlencode({ "message": message, "id": 12345, "visitor_id": VISITOR_ID}) result = yield request( "GET", "%s/%s/batch?%s" % (self.url, BUCKET_NAME_3, qs)) result = yield request( "GET", "%s/%s" % (self.url, BUCKET_NAME_3), username=self.username, password=self.password) self.assertEqual(result.code, 200)
def get_event(self, name, _property=None, start=None, finish=None, interval="day"): url = str("%s/event/%s" % (self.url, quote(name))) qs = {} if start: qs["start"] = start qs["interval"] = interval if finish: qs["finish"] = finish if _property: qs["property"] = _property if qs: url += "?%s" % urlencode(qs) result = yield request( "GET", url, username=self.username, password=self.password) self.assertEqual(result.code, 200) returnValue(ujson.loads(result.body))
def test_access(self): USERNAME_A = uuid.uuid4().hex USERNAME_B = uuid.uuid4().hex PASSWORD_A = "poiuy" PASSWORD_B = "mnbvc" result = yield request( "POST", "http://127.0.0.1:8080/%s" % USERNAME_A, data={"password":PASSWORD_A}) self.assertEqual(result.code, 201) result = yield request( "POST", "http://127.0.0.1:8080/%s" % USERNAME_B, data={"password":PASSWORD_B}) self.assertEqual(result.code, 201) result = yield request( "GET", "http://127.0.0.1:8080/%s" % USERNAME_A, username=USERNAME_A, password=PASSWORD_B) self.assertEqual(result.code, 401) result = yield request( "GET", "http://127.0.0.1:8080/%s" % USERNAME_B, username=USERNAME_A, password=PASSWORD_A) self.assertEqual(result.code, 401) result = yield request( "GET", "http://127.0.0.1:8080/%s" % USERNAME_A, username=USERNAME_A, password=PASSWORD_B) self.assertEqual(result.code, 401) result = yield request( "DELETE", "http://127.0.0.1:8080/%s" % USERNAME_A, username=USERNAME_A, password=PASSWORD_A) self.assertEqual(result.code, 200) result = yield request( "DELETE", "http://127.0.0.1:8080/%s" % USERNAME_B, username=USERNAME_B, password=PASSWORD_B) self.assertEqual(result.code, 200)
def test_create(self): CORRECT_PASSWORD = "******" INCORRECT_PASSWORD = "******" USERNAME = uuid.uuid4().hex result = yield request( "POST", "http://127.0.0.1:8080/%s" % USERNAME, data={"password":CORRECT_PASSWORD}) self.assertEqual(result.code, 201) result = yield request( "GET", "http://127.0.0.1:8080/%s" % USERNAME) self.assertEqual(result.code, 401) result = yield request( "GET", "http://127.0.0.1:8080/%s" % USERNAME, username=USERNAME, password=CORRECT_PASSWORD) self.assertEqual(result.code, 200) result = yield request( "GET", "http://127.0.0.1:8080/%s" % USERNAME, username=USERNAME, password=INCORRECT_PASSWORD) self.assertEqual(result.code, 401) result = yield request( "DELETE", "http://127.0.0.1:8080/%s" % USERNAME, username=USERNAME, password=INCORRECT_PASSWORD) self.assertEqual(result.code, 401) result = yield request( "DELETE", "http://127.0.0.1:8080/%s" % USERNAME, username=USERNAME, password=CORRECT_PASSWORD) self.assertEqual(result.code, 200)
def test_batch_insert(self): event_name_1 = "Event 1 %s" % uuid.uuid4().hex event_name_2 = "Event 2 %s" % uuid.uuid4().hex event_name_3 = "Event 3 %s" % uuid.uuid4().hex visitor_id_1 = uuid.uuid4().hex visitor_id_2 = uuid.uuid4().hex property_1_key = uuid.uuid4().hex property_1_value = "Property 1 %s" % uuid.uuid4().hex property_2_key = uuid.uuid4().hex property_2_value = "Property 2 %s" % uuid.uuid4().hex property_3_key = uuid.uuid4().hex property_3_value = "Property 3 %s" % uuid.uuid4().hex # VISITOR 1 events = [event_name_1, event_name_2, event_name_3] properties = [ [property_1_key, property_1_value], [property_2_key, property_2_value], [property_3_key, property_3_value]] message = b64encode(ujson.dumps([ events, properties])) request_id = randint(0, 100000) callback = uuid.uuid4().hex[0:10]; qs = urlencode({ "message": message, "request_id": request_id, "callback": callback, "visitor_id": visitor_id_1}) result = yield request( "GET", "%s/batch?%s" % (self.url, qs)) self.assertEqual(result.body[0:11], "%s(" % callback) self.assertEqual(result.body[-2:], ");") payload = result.body[11:-2] self.assertEqual(ujson.loads(payload)["request_id"], str(request_id)) # VISITOR 2 events = [event_name_1, event_name_3] properties = [] message = b64encode(ujson.dumps([ events, properties])) request_id = randint(0, 100000) callback = uuid.uuid4().hex[0:10]; qs = urlencode({ "message": message, "request_id": request_id, "callback": callback, "visitor_id": visitor_id_2}) message = b64encode(ujson.dumps([ events, properties])) result = yield request( "GET", "%s/batch?%s" % (self.url, qs)) self.assertEqual(result.body[0:11], "%s(" % callback) self.assertEqual(result.body[-2:], ");") payload = result.body[11:-2] self.assertEqual(ujson.loads(payload)["request_id"], str(request_id)) # Check events event_1 = yield self.get_event(event_name_1) event_2 = yield self.get_event(event_name_2) event_3 = yield self.get_event(event_name_3) event_1_property_1 = yield self.get_event(event_name_1, _property=property_1_key) event_2_property_1 = yield self.get_event(event_name_2, _property=property_1_key) event_3_property_1 = yield self.get_event(event_name_3, _property=property_1_key) event_1_property_2 = yield self.get_event(event_name_1, _property=property_2_key) event_2_property_2 = yield self.get_event(event_name_2, _property=property_2_key) event_3_property_2 = yield self.get_event(event_name_3, _property=property_2_key) event_1_property_3 = yield self.get_event(event_name_1, _property=property_3_key) event_2_property_3 = yield self.get_event(event_name_2, _property=property_3_key) event_3_property_3 = yield self.get_event(event_name_3, _property=property_3_key) events = yield self.get_event_dict() event_1_id = events[event_name_1] event_2_id = events[event_name_2] event_3_id = events[event_name_3] property_1 = yield self.get_property(property_1_key) property_2 = yield self.get_property(property_2_key) property_3 = yield self.get_property(property_3_key) property_1_id = property_1["value_ids"][property_1_value] property_2_id = property_2["value_ids"][property_2_value] property_3_id = property_3["value_ids"][property_3_value] # Event totals self.assertEqual(event_1["total"], 2) self.assertEqual(event_2["total"], 1) self.assertEqual(event_3["total"], 2) # Event property totals self.assertEqual(event_1_property_1["totals"][property_1_id], 1) self.assertEqual(event_2_property_1["totals"][property_1_id], 1) self.assertEqual(event_3_property_1["totals"][property_1_id], 1) self.assertEqual(event_1_property_2["totals"][property_2_id], 1) self.assertEqual(event_2_property_2["totals"][property_2_id], 1) self.assertEqual(event_3_property_2["totals"][property_2_id], 1) self.assertEqual(event_1_property_3["totals"][property_3_id], 1) self.assertEqual(event_2_property_3["totals"][property_3_id], 1) self.assertEqual(event_3_property_3["totals"][property_3_id], 1) # Property event totals self.assertEqual(property_1["values"][property_1_id]["total"][event_1_id], 1) self.assertEqual(property_1["values"][property_1_id]["total"][event_2_id], 1) self.assertEqual(property_1["values"][property_1_id]["total"][event_3_id], 1) self.assertEqual(property_2["values"][property_2_id]["total"][event_1_id], 1) self.assertEqual(property_2["values"][property_2_id]["total"][event_2_id], 1) self.assertEqual(property_2["values"][property_2_id]["total"][event_3_id], 1) self.assertEqual(property_3["values"][property_3_id]["total"][event_1_id], 1) self.assertEqual(property_3["values"][property_3_id]["total"][event_2_id], 1) self.assertEqual(property_3["values"][property_3_id]["total"][event_3_id], 1) # Event paths self.assertEqual(len(event_1["path"]), 0) # Event paths self.assertEqual(event_2["path"][event_1_id], 1) self.assertEqual(event_2_property_1["paths"][property_1_id][event_1_id], 1) self.assertEqual(event_2_property_2["paths"][property_2_id][event_1_id], 1) self.assertEqual(event_2_property_3["paths"][property_3_id][event_1_id], 1) # Event paths self.assertEqual(event_3["path"][event_1_id], 2) self.assertEqual(event_3_property_1["paths"][property_1_id][event_1_id], 1) self.assertEqual(event_3_property_2["paths"][property_2_id][event_1_id], 1) self.assertEqual(event_3_property_3["paths"][property_3_id][event_1_id], 1) self.assertEqual(event_3["path"][event_2_id], 1) self.assertEqual(event_3_property_1["paths"][property_1_id][event_2_id], 1) self.assertEqual(event_3_property_2["paths"][property_2_id][event_2_id], 1) self.assertEqual(event_3_property_3["paths"][property_3_id][event_2_id], 1)
def test_add(self): VISITOR_ID_1 = uuid.uuid4().hex VISITOR_ID_2 = uuid.uuid4().hex VISITOR_ID_3 = uuid.uuid4().hex EVENT_1 = "Event 1 %s" % uuid.uuid4().hex EVENT_2 = "Event 2 %s" % uuid.uuid4().hex EVENT_3 = "Event 3 %s" % uuid.uuid4().hex PROPERTY_1 = "Property 1 %s" % uuid.uuid4().hex PROPERTY_2 = "Property 2 %s" % uuid.uuid4().hex VALUE_1 = "Value 1 %s" % uuid.uuid4().hex VALUE_2 = "Value 2 %s" % uuid.uuid4().hex yield self.post_event(VISITOR_ID_1, EVENT_3) yield self.post_event(VISITOR_ID_1, EVENT_3) yield self.post_event(VISITOR_ID_1, EVENT_1) yield self.post_event(VISITOR_ID_1, EVENT_1) yield self.post_event(VISITOR_ID_2, EVENT_1) yield self.post_event(VISITOR_ID_3, EVENT_1) yield self.post_event(VISITOR_ID_1, EVENT_2) yield self.post_event(VISITOR_ID_2, EVENT_2) yield self.post_event(VISITOR_ID_1, EVENT_2) yield self.post_event(VISITOR_ID_1, EVENT_3) yield self.post_event(VISITOR_ID_1, EVENT_3) yield self.post_property(VISITOR_ID_1, PROPERTY_1, VALUE_1) yield self.post_property(VISITOR_ID_1, PROPERTY_2, VALUE_2) yield self.post_property(VISITOR_ID_2, PROPERTY_2, VALUE_2) events = yield self.get_event_dict() event_id_1 = events[EVENT_1] event_id_2 = events[EVENT_2] event_id_3 = events[EVENT_3] property_1 = yield self.get_property(PROPERTY_1) property_id_1 = property_1["value_ids"][VALUE_1] property_2 = yield self.get_property(PROPERTY_2) property_id_2 = property_2["value_ids"][VALUE_2] FUNNEL_NAME = uuid.uuid4().hex DESCRIPTION = uuid.uuid4().hex result = yield request( "POST", "%s/funnel/%s" % (self.url, FUNNEL_NAME), username=self.username, password=self.password, data=[ ("description", DESCRIPTION), ("event_id", event_id_1), ("event_id", event_id_2), ("event_id", event_id_3)]) self.assertEqual(result.code, 201) result = yield request( "GET", "%s/funnel/%s" % (self.url, FUNNEL_NAME), username=self.username, password=self.password) self.assertEqual(result.code, 200) funnel = ujson.decode(result.body)["funnel"] unique_funnel = ujson.decode(result.body)["unique_funnel"] self.assertEqual(funnel[0][0], event_id_1) self.assertEqual(funnel[1][0], event_id_2) self.assertEqual(funnel[2][0], event_id_3) self.assertEqual(funnel[0][1], 4) self.assertEqual(funnel[1][1], 3) self.assertEqual(funnel[2][1], 2) self.assertEqual(unique_funnel[0][0], event_id_1) self.assertEqual(unique_funnel[1][0], event_id_2) self.assertEqual(unique_funnel[2][0], event_id_3) self.assertEqual(unique_funnel[0][1], 3) self.assertEqual(unique_funnel[1][1], 2) self.assertEqual(unique_funnel[2][1], 1) FUNNEL_NAME_2 = uuid.uuid4().hex result = yield request( "POST", "%s/funnel/%s" % (self.url, FUNNEL_NAME_2), username=self.username, password=self.password, data=[ ("description", DESCRIPTION), ("event_id", event_id_1), ("event_id", event_id_2), ("event_id", event_id_3), ("property", PROPERTY_1)]) self.assertEqual(result.code, 201) result = yield request( "GET", "%s/funnel/%s" % (self.url, FUNNEL_NAME_2), username=self.username, password=self.password) self.assertEqual(result.code, 200) funnels = ujson.decode(result.body)["funnels"] unique_funnels = ujson.decode(result.body)["unique_funnels"] self.assertEqual(funnels[property_id_1][0][0], event_id_1) self.assertEqual(funnels[property_id_1][1][0], event_id_2) self.assertEqual(funnels[property_id_1][2][0], event_id_3) self.assertEqual(funnels[property_id_1][0][1], 2) self.assertEqual(funnels[property_id_1][1][1], 2) self.assertEqual(funnels[property_id_1][2][1], 2) self.assertEqual(unique_funnels[property_id_1][0][0], event_id_1) self.assertEqual(unique_funnels[property_id_1][1][0], event_id_2) self.assertEqual(unique_funnels[property_id_1][2][0], event_id_3) self.assertEqual(unique_funnels[property_id_1][0][1], 1) self.assertEqual(unique_funnels[property_id_1][1][1], 1) self.assertEqual(unique_funnels[property_id_1][2][1], 1) FUNNEL_NAME_3 = uuid.uuid4().hex result = yield request( "POST", "%s/funnel/%s" % (self.url, FUNNEL_NAME_3), username=self.username, password=self.password, data=[ ("description", DESCRIPTION), ("event_id", event_id_1), ("event_id", event_id_2), ("event_id", event_id_3), ("property", PROPERTY_2)]) self.assertEqual(result.code, 201) result = yield request( "GET", "%s/funnel/%s" % (self.url, FUNNEL_NAME_3), username=self.username, password=self.password) self.assertEqual(result.code, 200) funnels = ujson.decode(result.body)["funnels"] unique_funnels = ujson.decode(result.body)["unique_funnels"] self.assertEqual(funnels[property_id_2][0][0], event_id_1) self.assertEqual(funnels[property_id_2][1][0], event_id_2) self.assertEqual(funnels[property_id_2][2][0], event_id_3) self.assertEqual(funnels[property_id_2][0][1], 3) self.assertEqual(funnels[property_id_2][1][1], 3) self.assertEqual(funnels[property_id_2][2][1], 2) self.assertEqual(unique_funnels[property_id_2][0][0], event_id_1) self.assertEqual(unique_funnels[property_id_2][1][0], event_id_2) self.assertEqual(unique_funnels[property_id_2][2][0], event_id_3) self.assertEqual(unique_funnels[property_id_2][0][1], 2) self.assertEqual(unique_funnels[property_id_2][1][1], 2) self.assertEqual(unique_funnels[property_id_2][2][1], 1)