Skip to content

Commit 94d4a20

Browse files
authored
Merge pull request #35 from authsignal/AUT-2461.8
AUT-2429: allowing track with no attributes
2 parents 41ccbd2 + 1c0757f commit 94d4a20

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

authsignal/client.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,22 @@ def __init__(self, api_secret_key, api_url=API_BASE_URL, timeout=2.0):
113113
self.version = VERSION
114114

115115
def track(
116-
self, user_id: str, action: str, attributes: Dict[str, Any]
116+
self, user_id: str, action: str, attributes: Dict[str, Any] = None
117117
) -> Dict[str, Any]:
118118
"""Tracks an action to authsignal, scoped to the user_id and action
119119
Returns the status of the action so that you can determine to whether to continue
120120
Args:
121121
user_id: A user's id. This id should be the same as the user_id used in
122122
event calls.
123123
action: The action that you are tracking an event for, i.e. signIn.
124-
attributes: A dictionary containing the request body.
124+
attributes: A dictionary containing the request body. Optional.
125125
"""
126126
_assert_non_empty_string(user_id, "user_id")
127127
_assert_non_empty_string(action, "action")
128-
_assert_non_empty_dict(attributes, "attributes")
128+
129129
path = f"{self.api_url}/users/{urllib.parse.quote(user_id)}/actions/{urllib.parse.quote(action)}"
130130

131+
attributes = attributes or {}
131132
response = self.session.post(
132133
url=path, data=json.dumps(attributes, cls=DecimalEncoder)
133134
)

authsignal/client_tests.py

+16
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,22 @@ def test_get_action_with_bad_secret(self):
232232
"AuthsignalException: 401 - The request is unauthorized. Check that your API key and region base URL are correctly configured.",
233233
)
234234

235+
def test_track_without_attributes(self):
236+
client = AuthsignalClient(
237+
api_secret_key=self.test_config["api_secret_key"],
238+
api_url=self.test_config["api_url"],
239+
)
240+
241+
track_response = client.track(
242+
user_id="user123",
243+
action="python-sdk-test",
244+
)
245+
246+
# Verify basic response structure
247+
self.assertEqual(track_response["state"], "CHALLENGE_REQUIRED")
248+
self.assertTrue(track_response.get("idempotency_key"))
249+
self.assertIsNotNone(track_response.get("token"))
250+
235251

236252
if __name__ == "__main__":
237253
unittest.main()

authsignal/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "4.0.2"
1+
VERSION = "4.0.3"

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "authsignal"
3-
version = "4.0.2"
3+
version = "4.0.3"
44
description = "Authsignal Python SDK for Passwordless Step Up Authentication"
55
authors = ["justinsoong <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)