Example #1
0
    def test_set_is_identified(self) -> None:
        distinct_id = "777"
        Person.objects.create(team_id=self.team.pk, distinct_ids=[distinct_id])
        person_before_event = get_person_by_distinct_id(
            team_id=self.team.pk, distinct_id=distinct_id)

        self.assertFalse(person_before_event["is_identified"])
        process_event(
            distinct_id,
            "",
            "",
            {
                "event": "$identify",
                "properties": {},
            },
            self.team.pk,
            now().isoformat(),
            now().isoformat(),
        )
        process_event_ee(
            distinct_id,
            "",
            "",
            {
                "event": "$identify",
                "properties": {},
            },
            self.team.pk,
            now().isoformat(),
            now().isoformat(),
        )

        person_after_event = get_person_by_distinct_id(team_id=self.team.pk,
                                                       distinct_id=distinct_id)
        self.assertTrue(person_after_event["is_identified"])
Example #2
0
    def test_set_is_identified(self) -> None:
        distinct_id = "777"
        Person.objects.create(team_id=self.team.pk, distinct_ids=[distinct_id])
        person_before_event = get_person_by_distinct_id(team_id=self.team.pk, distinct_id=distinct_id)

        self.assertFalse(person_before_event["is_identified"])
        process_event(
            distinct_id,
            "",
            "",
            {"event": "$identify", "properties": {},},
            self.team.pk,
            now().isoformat(),
            now().isoformat(),
        )
        process_event_ee(
            distinct_id,
            "",
            "",
            {"event": "$identify", "properties": {},},
            self.team.pk,
            now().isoformat(),
            now().isoformat(),
        )

        # Assume that clickhouse has done replacement
        ch_client.execute("OPTIMIZE TABLE person")

        person_after_event = get_person_by_distinct_id(team_id=self.team.pk, distinct_id=distinct_id)
        self.assertTrue(person_after_event["is_identified"])
Example #3
0
    def test_alias_before_person(self) -> None:
        process_event_ee(
            "new_distinct_id",
            "",
            "",
            {
                "event": "$create_alias",
                "properties": {
                    "distinct_id": "new_distinct_id",
                    "token": self.team.api_token,
                    "alias": "old_distinct_id",
                },
            },
            self.team.pk,
            now().isoformat(),
            now().isoformat(),
        )

        person1 = get_person_by_distinct_id(team_id=self.team.pk, distinct_id="old_distinct_id")
        person2 = get_person_by_distinct_id(team_id=self.team.pk, distinct_id="new_distinct_id")

        self.assertEqual(person1, person2)

        events = get_events()
        distinct_ids = [item["distinct_id"] for item in get_person_distinct_ids(team_id=self.team.pk)]

        self.assertEqual(len(events), 1)
        self.assertEqual(sorted(distinct_ids), sorted(["new_distinct_id", "old_distinct_id"]))
Example #4
0
    def test_distinct_with_multiple_anonymous_ids_which_were_already_created(self,) -> None:
        # logging in the first time
        create_person(team_id=self.team.pk, distinct_ids=["anonymous_id"])
        create_person(team_id=self.team.pk, distinct_ids=["new_distinct_id"], properties={"email": "*****@*****.**"})

        process_event_ee(
            "new_distinct_id",
            "",
            "",
            {
                "event": "$identify",
                "properties": {
                    "$anon_distinct_id": "anonymous_id",
                    "token": self.team.api_token,
                    "distinct_id": "new_distinct_id",
                },
            },
            self.team.pk,
            now().isoformat(),
            now().isoformat(),
        )

        # self.assertEqual(Event.objects.count(), 0)
        person = get_person_by_distinct_id(self.team.pk, "new_distinct_id")
        distinct_ids = [item["distinct_id"] for item in get_person_distinct_ids(team_id=self.team.pk)]
        self.assertEqual(sorted(distinct_ids), sorted(["anonymous_id", "new_distinct_id"]))
        self.assertEqual(person["properties"]["email"], "*****@*****.**")

        # logging in another time

        create_person(team_id=self.team.pk, distinct_ids=["anonymous_id_2"])

        process_event_ee(
            "new_distinct_id",
            "",
            "",
            {
                "event": "$identify",
                "properties": {
                    "$anon_distinct_id": "anonymous_id_2",
                    "token": self.team.api_token,
                    "distinct_id": "new_distinct_id",
                },
            },
            self.team.pk,
            now().isoformat(),
            now().isoformat(),
        )

        person = get_person_by_distinct_id(self.team.pk, "new_distinct_id")
        distinct_ids = [item["distinct_id"] for item in get_person_distinct_ids(team_id=self.team.pk)]
        self.assertEqual(sorted(distinct_ids), sorted(["anonymous_id", "new_distinct_id", "anonymous_id_2"]))
        self.assertEqual(person["properties"]["email"], "*****@*****.**")
Example #5
0
    def _query_clickhouse(self, distinct_id: str) -> bool:
        from ee.clickhouse.models.person import get_person_by_distinct_id

        return len(
            get_person_by_distinct_id(self.team, distinct_id,
                                      Filter(data=self.filters))) > 0