From d068fdbaaf1fa1deb444110eb6213c7f24f4be6f Mon Sep 17 00:00:00 2001 From: Eli Bishop Date: Fri, 9 Dec 2022 09:32:15 -0800 Subject: [PATCH] (U2C 2) remove alias event functionality (#187) --- Makefile | 8 +++++++- contract-tests/client_entity.py | 3 --- contract-tests/service.py | 3 --- ldclient/client.py | 19 ------------------- ldclient/impl/event_factory.py | 9 --------- testing/test_ldclient.py | 13 ------------- 6 files changed, 7 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index ca4fa068..7c5f235b 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,12 @@ docs: TEMP_TEST_OUTPUT=/tmp/contract-test-service.log +# TEST_HARNESS_PARAMS can be set to add -skip parameters for any contract tests that cannot yet pass +# Explanation of current skips: +# - "events/alias": preliminary removal of alias functionality before starting U2C implementation +TEST_HARNESS_PARAMS := $(TEST_HARNESS_PARAMS) \ + -skip 'events/alias' + # port 8000 and 9000 is already used in the CI environment because we're # running a DynamoDB container and an SSE contract test PORT=10000 @@ -33,7 +39,7 @@ start-contract-test-service-bg: @make start-contract-test-service >$(TEMP_TEST_OUTPUT) 2>&1 & run-contract-tests: - @curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/v1.0.0/downloader/run.sh \ + curl -s https://raw.githubusercontent.com/launchdarkly/sdk-test-harness/main/downloader/run.sh \ | VERSION=v1 PARAMS="-url http://localhost:$(PORT) -debug -stop-service-at-end $(TEST_HARNESS_PARAMS)" sh contract-tests: build-contract-tests start-contract-test-service-bg run-contract-tests diff --git a/contract-tests/client_entity.py b/contract-tests/client_entity.py index 5d2d5220..ea4f34a7 100644 --- a/contract-tests/client_entity.py +++ b/contract-tests/client_entity.py @@ -72,9 +72,6 @@ def track(self, params): def identify(self, params): self.client.identify(params["user"]) - def alias(self, params): - self.client.alias(params["user"], params["previousUser"]) - def flush(self): self.client.flush() diff --git a/contract-tests/service.py b/contract-tests/service.py index d9f8e0a5..48340671 100644 --- a/contract-tests/service.py +++ b/contract-tests/service.py @@ -114,9 +114,6 @@ def post_client_command(id): elif params.get("command") == "identifyEvent": client.identify(params.get("identifyEvent")) return ('', 201) - elif params.get("command") == "aliasEvent": - client.alias(params.get("aliasEvent")) - return ('', 201) elif params.get('command') == "flushEvents": client.flush() return ('', 201) diff --git a/ldclient/client.py b/ldclient/client.py index 86a45e06..58ab766f 100644 --- a/ldclient/client.py +++ b/ldclient/client.py @@ -198,25 +198,6 @@ def track(self, event_name: str, user: dict, data: Optional[Any]=None, metric_va else: self._send_event(self._event_factory_default.new_custom_event(event_name, user, data, metric_value)) - def alias(self, current_user: dict, previous_user: dict): - """Associates two users for analytics purposes. - - This can be helpful in the situation where a person is represented by multiple - LaunchDarkly users. This may happen, for example, when a person initially logs into - an application, the person might be represented by an anonymous user prior to logging - in and a different user after logging in, as denoted by a different user key. - - :param current_user: The new version of a user. - :param previous_user: The old version of a user. - """ - if current_user is None or current_user.get('key') is None: - log.warning("Missing current_user or current_user key when calling alias().") - return None - if previous_user is None or previous_user.get('key') is None: - log.warning("Missing previous_user or previous_user key when calling alias().") - return None - self._send_event(self._event_factory_default.new_alias_event(current_user, previous_user)) - def identify(self, user: dict): """Registers the user. diff --git a/ldclient/impl/event_factory.py b/ldclient/impl/event_factory.py index 12823bed..d9ba5925 100644 --- a/ldclient/impl/event_factory.py +++ b/ldclient/impl/event_factory.py @@ -89,15 +89,6 @@ def new_custom_event(self, event_name, user, data, metric_value): e['contextKind'] = self._user_to_context_kind(user) return e - def new_alias_event(self, current_user, previous_user): - return { - 'kind': 'alias', - 'key': current_user.get('key'), - 'contextKind': self._user_to_context_kind(current_user), - 'previousKey': previous_user.get('key'), - 'previousContextKind': self._user_to_context_kind(previous_user) - } - def _user_to_context_kind(self, user): if user.get('anonymous'): return "anonymousUser" diff --git a/testing/test_ldclient.py b/testing/test_ldclient.py index e9a19c9a..4a708e4e 100644 --- a/testing/test_ldclient.py +++ b/testing/test_ldclient.py @@ -189,19 +189,6 @@ def test_track_anonymous_user(): assert e['kind'] == 'custom' and e['key'] == 'my_event' and e['user'] == anonymous_user and e.get('data') is None and e.get('metricValue') is None and e.get('contextKind') == 'anonymousUser' -def test_alias(): - with make_client() as client: - client.alias(user, anonymous_user) - e = get_first_event(client) - assert e['kind'] == 'alias' and e['key'] == 'xyz' and e['contextKind'] == 'user' and e['previousKey'] == 'abc' and e['previousContextKind'] == 'anonymousUser' - - -def test_alias_no_user(): - with make_client() as client: - client.alias(None, None) - assert count_events(client) == 0 - - def test_defaults(): config=Config("SDK_KEY", base_uri="http://localhost:3000", defaults={"foo": "bar"}, offline=True) with LDClient(config=config) as client: