diff --git a/pyproject.toml b/pyproject.toml index 67123bb..113c55a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "ABSmartly" -version = "0.2.3" +version = "0.2.4" description = "ABSmartly Python SDK lib" readme = "README.md" authors = [{ name = "ABSmartly", email = "info@ABSmartly.com" }] diff --git a/sdk/context.py b/sdk/context.py index 79599ab..5555a82 100644 --- a/sdk/context.py +++ b/sdk/context.py @@ -452,11 +452,11 @@ def publish_async(self): self.check_not_closed() return self.flush() - def track(self, goal_name: str, properties: dict): + def track(self, goal_name: str, properties: dict, achieved_at: int = None): self.check_not_closed() achievement = GoalAchievement() - achievement.achievedAt = self.clock.millis() + achievement.achievedAt = achieved_at or self.clock.millis() achievement.name = goal_name if properties is None: achievement.properties = None diff --git a/test/test_context.py b/test/test_context.py index 84017a3..3016c13 100644 --- a/test/test_context.py +++ b/test/test_context.py @@ -1135,3 +1135,20 @@ def test_assignment_with_historical_exposed_at_timestamp(self): exposure = context.exposures[0] self.assertEqual(1713218400000, exposure.exposedAt) context.close() + + def test_achievement_with_historical_achieved_at_timestamp(self): + self.set_up() + config = ContextConfig() + config.units = self.units + context = self.create_test_context(config, self.data_future_ready) + self.assertEqual(True, context.is_ready()) + self.assertEqual(False, context.is_failed()) + + context.track( + "goal_test_historical_timestamp", + properties = {}, + achieved_at = 1713218400000 + ) + achievement = context.achievements[0] + self.assertEqual(1713218400000, achievement.achievedAt) + context.close()