MCPcopy
hub / github.com/PostHog/posthog / _create_person

Function _create_person

posthog/test/base.py:495–521  ·  view source on GitHub ↗

Create a person in tests. NOTE: all persons get batched and only created when sync_execute is called Pass immediate=True to create immediately and get a pk back

(*args, **kwargs)

Source from the content-addressed store, hash-verified

493
494
495def _create_person(*args, **kwargs):
496 """
497 Create a person in tests. NOTE: all persons get batched and only created when sync_execute is called
498 Pass immediate=True to create immediately and get a pk back
499 """
500 global persons_ordering_int
501 if not (kwargs.get("uuid")):
502 kwargs["uuid"] = uuid.UUID(
503 int=persons_ordering_int, version=4
504 ) # make sure the ordering of uuids is always consistent
505 persons_ordering_int += 1
506 # If we've done freeze_time just create straight away
507 if kwargs.get("immediate") or (hasattr(now(), "__module__") and now().__module__ == "freezegun.api"):
508 if kwargs.get("immediate"):
509 del kwargs["immediate"]
510 create_person(
511 team_id=kwargs.get("team_id") or kwargs["team"].pk,
512 properties=kwargs.get("properties"),
513 uuid=kwargs["uuid"],
514 version=kwargs.get("version", 0),
515 )
516 return Person.objects.create(**kwargs)
517 if len(args) > 0:
518 kwargs["distinct_ids"] = [args[0]] # allow calling _create_person("distinct_id")
519
520 persons_cache_tests.append(kwargs)
521 return Person(**{key: value for key, value in kwargs.items() if key != "distinct_ids"})
522
523
524class ClickhouseTestMixin(QueryMatchingTest):

Calls 5

create_personFunction · 0.90
PersonClass · 0.90
nowFunction · 0.85
getMethod · 0.65
createMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…