Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Only lower camel twiml kwargs if they contain _ #401

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

Merged
merged 1 commit into from
Dec 16, 2017
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
28 changes: 27 additions & 1 deletion tests/unit/twiml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
from nose.tools import raises
from six import text_type

from twilio.twiml import format_language, TwiMLException, TwiML
from twilio.twiml import (
format_language,
lower_camel,
TwiMLException,
TwiML
)


class TwilioTest(unittest.TestCase):
Expand All @@ -30,3 +35,24 @@ def test_format_language_coerced(self):
@raises(TwiMLException)
def test_format_language_fail(self):
format_language('this is invalid')

def test_lower_camel_empty_string(self):
self.assertEqual('', lower_camel(''))

def test_lower_camel_none(self):
self.assertEqual(None, lower_camel(None))

def test_lower_camel_single_word(self):
self.assertEqual('foo', lower_camel('foo'))

def test_lower_camel_double_word(self):
self.assertEqual('fooBar', lower_camel('foo_bar'))

def test_lower_camel_multi_word(self):
self.assertEqual('fooBarBaz', lower_camel('foo_bar_baz'))

def test_lower_camel_multi_word_mixed_case(self):
self.assertEqual('fooBarBaz', lower_camel('foO_Bar_baz'))

def test_lower_camel_camel_cased(self):
self.assertEqual('fooBar', lower_camel('fooBar'))
6 changes: 3 additions & 3 deletions tests/unit/twiml/test_voice_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def test_task_string(self):

assert_equal(
self.strip(r),
'<?xml version="1.0" encoding="UTF-8"?><Response><Enqueue workflowsid="123123123"><Task>{"account_sid": "AC123123123"}</Task></Enqueue></Response>'
'<?xml version="1.0" encoding="UTF-8"?><Response><Enqueue workflowSid="123123123"><Task>{"account_sid": "AC123123123"}</Task></Enqueue></Response>'
)

def test_task_dict(self):
Expand All @@ -430,8 +430,8 @@ def test_task_dict(self):
r.append(e)

assert_equal(
self.strip(r),
'<?xml version="1.0" encoding="UTF-8"?><Response><Enqueue workflowsid="123123123"><Task>{"account_sid": "AC123123123"}</Task></Enqueue></Response>'
'<?xml version="1.0" encoding="UTF-8"?><Response><Enqueue workflowSid="123123123"><Task>{"account_sid": "AC123123123"}</Task></Enqueue></Response>',
self.strip(r)
)


Expand Down
6 changes: 3 additions & 3 deletions twilio/twiml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@


def lower_camel(string):
result = "".join([x.title() for x in string.split('_')])
if not result:
return result
if not string or '_' not in string:
return string

result = "".join([x.title() for x in string.split('_')])
return result[0].lower() + result[1:]


Expand Down