Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename traits to user_traits #35

Merged
merged 1 commit into from
Apr 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ background worker you can generate data for a worker:
'properties': {
'key': 'value'
},
'traits': {
'user_traits': {
'key': 'value'
}
})
Expand Down
5 changes: 4 additions & 1 deletion castle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions castle/test/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions castle/test/commands/authenticate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions castle/test/commands/identify_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions castle/test/commands/track_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down