From 3e9828b8487646bbfe1996d26b3bb13b6dac30db Mon Sep 17 00:00:00 2001 From: Tomasz Pajor Date: Mon, 2 Apr 2018 19:07:55 +0200 Subject: [PATCH] rename traits to user_traits --- HISTORY.md | 4 ++++ README.rst | 2 +- castle/client.py | 5 ++++- castle/test/client_test.py | 5 +++++ castle/test/commands/authenticate_test.py | 4 ++-- castle/test/commands/identify_test.py | 4 ++-- castle/test/commands/track_test.py | 4 ++-- 7 files changed, 20 insertions(+), 8 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index eabeb09..3a796cf 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ ## master +### Breaking Changes: + +- [#35](github.com/castle/castle-python/pull/35) usage of `traits` key is deprecated, use `user_traits` instead + ## 2.1.1 (2018-02-26) ### Features: diff --git a/README.rst b/README.rst index 1c522df..087bc7c 100644 --- a/README.rst +++ b/README.rst @@ -88,7 +88,7 @@ background worker you can generate data for a worker: 'properties': { 'key': 'value' }, - 'traits': { + 'user_traits': { 'key': 'value' } }) diff --git a/castle/client.py b/castle/client.py index 074e3e8..273b9fd 100644 --- a/castle/client.py +++ b/castle/client.py @@ -9,7 +9,7 @@ from castle.exceptions import InternalServerError from castle.failover_response import FailoverResponse from castle.utils import timestamp as generate_timestamp - +import warnings class Client(object): @@ -29,6 +29,9 @@ def to_context(request, options={}): @staticmethod def to_options(options={}): options.setdefault('timestamp', generate_timestamp()) + if 'traits' in options: + warnings.warn('use user_traits instead of traits key', DeprecationWarning) + return options @staticmethod diff --git a/castle/test/client_test.py b/castle/test/client_test.py index 8506821..ee32bfa 100644 --- a/castle/test/client_test.py +++ b/castle/test/client_test.py @@ -164,6 +164,11 @@ def test_to_options(self): self.assertEqual( options, {'foo': 'bar', 'timestamp': '2018-01-02T03:04:05.678'}) + def test_to_options_with_deprecation(self): + options = Client.to_options({'foo': 'bar', 'traits': {}}) + self.assertEqual( + options, {'foo': 'bar', 'timestamp': '2018-01-02T03:04:05.678', 'traits': {}}) + def test_to_context(self): context = { 'active': True, diff --git a/castle/test/commands/authenticate_test.py b/castle/test/commands/authenticate_test.py index 5061ca6..3139a53 100644 --- a/castle/test/commands/authenticate_test.py +++ b/castle/test/commands/authenticate_test.py @@ -79,9 +79,9 @@ def test_build_properties_allowed(self): self.assertEqual(CommandsAuthenticate( context).build(options), expected) - def test_build_traits_allowed(self): + def test_build_user_traits_allowed(self): context = {} - options = default_options_plus(traits={'email': 'a@b.com'}) + options = default_options_plus(user_traits={'email': 'a@b.com'}) options.update({'context': context}) expected = default_command_with_data(**options) diff --git a/castle/test/commands/identify_test.py b/castle/test/commands/identify_test.py index 423712f..a916944 100644 --- a/castle/test/commands/identify_test.py +++ b/castle/test/commands/identify_test.py @@ -65,9 +65,9 @@ def test_build_properties_not_allowed(self): with self.assertRaises(InvalidParametersError): CommandsIdentify(context).build(options) - def test_build_traits_allowed(self): + def test_build_user_traits_allowed(self): context = {} - options = default_options_plus(traits={'email': 'identity@its.me.com'}) + options = default_options_plus(user_traits={'email': 'identity@its.me.com'}) options.update({'context': context}) expected = default_command_with_data(**options) diff --git a/castle/test/commands/track_test.py b/castle/test/commands/track_test.py index b411f8b..d89233d 100644 --- a/castle/test/commands/track_test.py +++ b/castle/test/commands/track_test.py @@ -67,10 +67,10 @@ def test_build_properties_allowed(self): self.assertEqual(CommandsTrack(context).build(options), expected) - def test_build_traits_allowed(self): + def test_build_user_traits_allowed(self): context = {} options = default_options_plus( - traits={'email': 'track@all.the.things.com'}) + user_traits={'email': 'track@all.the.things.com'}) options.update({'context': context}) expected = default_command_with_data(**options)