Skip to content

Commit

Permalink
(U2C 2) remove alias event functionality (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
eli-darkly authored Dec 9, 2022
1 parent 09d8b96 commit d068fdb
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 48 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions contract-tests/client_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
3 changes: 0 additions & 3 deletions contract-tests/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 0 additions & 19 deletions ldclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 0 additions & 9 deletions ldclient/impl/event_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 0 additions & 13 deletions testing/test_ldclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d068fdb

Please sign in to comment.