Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Added application/json hotfix, updated version number of SDK#33

Merged
Aubron merged 7 commits intoBandwidth:masterfrom
jmulford-bw:changed-api-response-header
Mar 25, 2019
Merged

Added application/json hotfix, updated version number of SDK#33
Aubron merged 7 commits intoBandwidth:masterfrom
jmulford-bw:changed-api-response-header

Conversation

@jmulford-bw
Copy link
Copy Markdown
Contributor

Make sure you've checked off all these things before submitting:

  • This pull request contains 100% test coverage.
  • This pull request is completely documented. All available fields are listed in the docs with description.
  • Each public facing method should include at least one example using said method.

@jmulford-bw
Copy link
Copy Markdown
Contributor Author

Unit tests

jmulford@jmulford-mbp python-bandwidth (changed-api-response-header) $ make
rm -rf `find . -name __pycache__`
rm -f `find . -type f -name '*.py[co]' `
rm -f `find . -type f -name '*~' `
rm -f `find . -type f -name '.*~' `
rm -f `find . -type f -name '@*' `
rm -f `find . -type f -name '#*#' `
rm -f `find . -type f -name '*.orig' `
rm -f `find . -type f -name '*.rej' `
pip install -r requirements.txt
Requirement already satisfied: lxml in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (4.3.1)
Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (2.21.0)
Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (1.12.0)
Requirement already satisfied: python-dateutil==2.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (2.2)
Requirement already satisfied: bpython==0.13.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 1)) (0.13.1)
Requirement already satisfied: green==1.6.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 2)) (1.6.0)
Requirement already satisfied: flake8 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 3)) (3.7.5)
Requirement already satisfied: pep8 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 4)) (1.7.1)
Requirement already satisfied: coverage==3.7.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 5)) (3.7.1)
Requirement already satisfied: responses in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 6)) (0.10.5)
Requirement already satisfied: mock in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 7)) (2.0.0)
Requirement already satisfied: Sphinx==1.3.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 8)) (1.3.1)
Requirement already satisfied: sphinx-rtd-theme==0.1.8 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from -r ./dev_requirements.txt (line 9)) (0.1.8)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests->-r requirements.txt (line 2)) (2018.11.29)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests->-r requirements.txt (line 2)) (3.0.4)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests->-r requirements.txt (line 2)) (1.24.1)
Requirement already satisfied: idna<2.9,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from requests->-r requirements.txt (line 2)) (2.8)
Requirement already satisfied: pygments in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from bpython==0.13.1->-r ./dev_requirements.txt (line 1)) (2.3.1)
Requirement already satisfied: python-termstyle in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from green==1.6.0->-r ./dev_requirements.txt (line 2)) (0.1.10)
Requirement already satisfied: pycodestyle<2.6.0,>=2.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from flake8->-r ./dev_requirements.txt (line 3)) (2.5.0)
Requirement already satisfied: pyflakes<2.2.0,>=2.1.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from flake8->-r ./dev_requirements.txt (line 3)) (2.1.0)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from flake8->-r ./dev_requirements.txt (line 3)) (0.6.1)
Requirement already satisfied: entrypoints<0.4.0,>=0.3.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from flake8->-r ./dev_requirements.txt (line 3)) (0.3)
Requirement already satisfied: pbr>=0.11 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from mock->-r ./dev_requirements.txt (line 7)) (5.1.2)
Requirement already satisfied: babel>=1.3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Sphinx==1.3.1->-r ./dev_requirements.txt (line 8)) (2.6.0)
Requirement already satisfied: snowballstemmer>=1.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Sphinx==1.3.1->-r ./dev_requirements.txt (line 8)) (1.2.1)
Requirement already satisfied: docutils>=0.11 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Sphinx==1.3.1->-r ./dev_requirements.txt (line 8)) (0.14)
Requirement already satisfied: Jinja2>=2.3 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Sphinx==1.3.1->-r ./dev_requirements.txt (line 8)) (2.10)
Requirement already satisfied: alabaster<0.8,>=0.7 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Sphinx==1.3.1->-r ./dev_requirements.txt (line 8)) (0.7.12)
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from python-termstyle->green==1.6.0->-r ./dev_requirements.txt (line 2)) (39.0.1)
Requirement already satisfied: pytz>=0a in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from babel>=1.3->Sphinx==1.3.1->-r ./dev_requirements.txt (line 8)) (2018.9)
Requirement already satisfied: MarkupSafe>=0.23 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from Jinja2>=2.3->Sphinx==1.3.1->-r ./dev_requirements.txt (line 8)) (1.1.0)
You are using pip version 19.0.1, however version 19.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
green tests -vvv -r
Green 1.6.0, Coverage 3.7.1, Python 3.7.0

tests.bandwidth.account.test_account
  AccountTests
.   get_account() should return account data
.   list_account_transactions() should return account transactions
tests.bandwidth.account.test_application
  ApplicationTests
.   create_application() should create an application and return id
.   delete_application() should remove an application
.   get_application() should return an application
.   get_applications() should return applications
.   update_application() should update an application
tests.bandwidth.account.test_available_number
  AvailableNumberTests
.   search_and_order_available_numbers() should search, order and return available numbers
.   search_and_order_available_numbers() should search, order and return available numbers
.   search_available_numbers() should return available numbers
.   search_available_numbers() should return available numbers
tests.bandwidth.account.test_domain
  DomainTests
.   create_domain() should create a domain and return id
.   delete_domain() should remove an domain
.   get_domain('domain_id') should return a domain
.   list_domains() should return domains
tests.bandwidth.account.test_endpoint
  EndpointTests
.   create_domain_endpoint() should create an endpoint and return id
.   create_domain_endpoint_auth_token() should create auth token
.   delete_domain_endpoint() should remove an endpoint
.   get_domain_endpoint() should return an endpoint
.   list_domain_endpoints() should return endpoints
.   update delete_domain_endpoint() should update an endpoint
tests.bandwidth.account.test_error
  ErrorTests
.   get_errors() should return an error
.   list_errors() should return errors
tests.bandwidth.account.test_media
  MediaTests
.   delete_media_file() should remove a media file
.   download_media_file() should download file
.   list_media_files() should return media files
.   upload_media_file() should upload file
.   upload_media_file() should upload file by file path
tests.bandwidth.account.test_number_info
  NumberInfoTests
.   get_number_info() should return recordings
tests.bandwidth.account.test_phone_number
  PhoneNumberTests
.   delete_phone_number() should remove a number
.   get_phone_number() should return a phone number
.   list_phone_numbers() should return numbers
.   order_phone_number() should create an number and return id
.   update_phone_number() should update a phone number
tests.bandwidth.messaging.test_message
  MessageTests
.   get_message() should return a message
.   list_messages() should return messages
.   send_message() should create an message and return id
.   send_messages() should send some messages
tests.bandwidth.test_account_client
  ClientTests
.   _check_response() should extract error data from json
.   _check_response() should extract error data from json (without code)
.   _check_response() should extract error data from plain text
.   Client() should raise error on missing auth data
.   Client() should return client instance with right auth data
.   Client() should return client instance with right auth data (different endpoint and version)
.   _request() should add the user agent to header
.   _make_request() should make request, check response and extract json data
.   _make_request() should make request, check response and extract id from location header
.   _request() should make authorized request to absolute url
.   _request() should make authorized request to relative url
tests.bandwidth.test_bxml
  ResponseTests
.   __str__() should return XML as string
.   to_xml() should build XML
.   to_xml() should build XML (some verbs)
tests.bandwidth.test_decorators
  DecoratorsTests
.   play_audio() should add methods speak_sentence and play_audio_file to class
tests.bandwidth.test_lazy_enumerable
  LazyEnumerableTests
.   get_lazy_enumerator() should return data on demand
.   get_lazy_enumerator() should request new portion of data on demand
tests.bandwidth.test_messaging_client
  ClientTests
.   _check_response() should extract error data from json
.   _check_response() should extract error data from json (without code)
.   _check_response() should extract error data from plain text
.   Client() should raise error on missing auth data
.   Client() should return client instance with right auth data
.   Client() should return client instance with right auth data (different endpoint and version)
.   _request() should add the user agent to header
.   _make_request() should make request, check response and extract json data
.   _make_request() should make request, check response and extract id from location header
.   _request() should make authorized request to absolute url
.   _request() should make authorized request to relative url
tests.bandwidth.test_voice_client
.   _check_response() should extract error data from json
.   _check_response() should extract error data from json (without code)
.   _check_response() should extract error data from plain text
.   Client() should raise error on missing auth data
.   Client() should return client instance with right auth data
.   Client() should return client instance with right auth data (different endpoint and version)
.   _request() should add the user agent to header
.   _make_request() should make request, check response and extract json data
.   _make_request() should make request, check response and extract id from location header
.   client should contain play audio helpers
.   _request() should make authorized request to absolute url
.   _request() should make authorized request to relative url
tests.bandwidth.voice.test_audio
  AudioBuilderTests
.   Should return dict of values
.   Should return dict of values
tests.bandwidth.voice.test_bridge
  BridgesTests
.   create_bridge() should create a bridge and return id
.   get_bridge() should return a bridge
.   list_bridge_calls() should return calls of a bridge
.   list_bridges() should return bridges
.   play_audio_to_bridge() should play audio to a bridge
.   update_bridge() should update a bridge
tests.bandwidth.voice.test_call
  CallTests
.   answer_call() should call update_call with right data
.   create_call() should create a call and return id
.   create_call_gather() should create a gather
.   disable_call_recording() should call update_call with recording_enabled=False
.   enable_call_recording() should call update_call with recording_enabled=True
.   get_call() should return a call
.   get_call_event() should return an event
.   get_call_gather() should return a gather
.   hangup_call() should call update_call with right data
.   list_call_events() should return events
.   list_call_recordings() should return recordings
.   get_call_transcriptions() should return transcriptions
.   list_calls() should return calls
.   play_audio_to_call() should play audio to a call
.   reject_call() should call update_call with right data
.   send_dtmf_to_call() should send dtmf data to a call
.   toggle_call_recording() should call get_call with the id
.   toggle_call_recording() should call get_call with the id
.   toggle_call_recording() should call get_call with the id
.   transfer_call() should call update_call with right data
.   transfer_call() should call update_call with right data (with callback url)
.   transfer_call() should call update_call with right data (with caller id)
.   transfer_call() should call update_call with right data (with whisper audio)
.   update_call() should update a call
.   update_call_gather() should update a gather
tests.bandwidth.voice.test_conference
  ConferenceTests
.   create_conference() should create a conference and return id
.   create_conference_member() should create a conference member
.   get_conference() should return a conference
.   get_conference_member() should return a conference member
.   hold_conference() should call update_conference() with right params
.   hold_conference_member() should call update_conference_member() with right params
.   list_conference_members() should return members of a conference
.   mute_conference() should call update_conference() with right params
.   mute_conference_member() should call update_conference_member() with right params
.   play_audio_file_to_conference_member() should call play_audio_to_conference_member() with right params
.   play_audio_to_conference() should play an audio to a conference
.   play_audio_to_conference_member() should play audio to a conference member
.   delete_conference_member() should call update_conference_member() with right params
.   speak_sentence_to_conference_member() should call play_audio_to_conference_member() with right params
.   terminate_conference() should call update_conference() with right params
.   update_conference() should update a conference
.   update_conference_member() should update a conference member
tests.bandwidth.voice.test_recording
  RecordingTests
.   get_recording() should return a recording
.   list_recordings() should return recordings
tests.bandwidth.voice.test_transcription
  TranscriptionTests
.   create_transcription() should create a transcription and return id
.   get_transcription() should return a transcription
.   list_transcriptions() should return transcriptions
tests.test_client
  ClientTests
.   Call of client() should cache client class name
.   Call of client() should return client instance for supported client name
.   Call of client() should return client instance for supported client name (case insensitive)
.   Call of client() should raise error for unsupported client name
tests.test_convert_camel
  ConvertCamelTests
.   convert_object_to_snake_case() should successfully transform a nested list
.   convert_object_to_snake_case() should return same object if not string, list, dict
.   convert_object_to_snake_case() should snake a dict
.   convert_object_to_snake_case() should snake a string

Ran 141 tests in 0.066s

OK (passes=141)

Name                                       Stmts   Miss  Cover   Missing
------------------------------------------------------------------------
bandwidth/__init__                             1      0   100%   
bandwidth/account/__init__                     2      0   100%   
bandwidth/account/api_exception_module         9      0   100%   
bandwidth/account/client_module              210      0   100%   
bandwidth/client_module                       12      0   100%   
bandwidth/convert_camel                       31      0   100%   
bandwidth/messaging/__init__                   2      0   100%   
bandwidth/messaging/api_exception_module       9      0   100%   
bandwidth/messaging/client_module             78      0   100%   
bandwidth/version                              1      0   100%   
bandwidth/voice/__init__                       2      0   100%   
bandwidth/voice/api_exception_module           9      0   100%   
bandwidth/voice/bxml                           9      0   100%   
bandwidth/voice/client_module                268      0   100%   
bandwidth/voice/decorators                    12      0   100%   
bandwidth/voice/lazy_enumerable               17      0   100%   
------------------------------------------------------------------------
TOTAL                                        672      0   100%   
jmulford@jmulford-mbp python-bandwidth (changed-api-response-header) $ 

def _check_response(self, response):
if response.status_code >= 400:
if response.headers.get('content-type') == 'application/json':
if "application/json" in response.headers.get('content-type'):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't you need to change _make_request in all these files?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about backup_init.py? not sure if that file's used

def _check_response(self, response):
if response.status_code >= 400:
if response.headers.get('content-type') == 'application/json':
if "application/json" in response.headers.get('content-type'):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to see a startsWith()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though what you have will likely work correctly in any conceivable case

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a try/catch without checking the content type. We’re either returning json or not, if the json parser works then we’re good. Catch any error and return some more context

@jmulford-bw
Copy link
Copy Markdown
Contributor Author

Won't merge

@Aubron Aubron reopened this Mar 12, 2019
@Aubron
Copy link
Copy Markdown
Contributor

Aubron commented Mar 12, 2019

Reopening this PR for DX-5

@Aubron
Copy link
Copy Markdown
Contributor

Aubron commented Mar 25, 2019

Can I get a re-review from @jpinnix-bandwidth and @jmulford-bandwidth

(informal for jmulford, since it's his PR he can't review it)

@jmulford-bw
Copy link
Copy Markdown
Contributor Author

@Aubron can you fix the unit tests?

@jmulford-bw
Copy link
Copy Markdown
Contributor Author

jmulford-bw commented Mar 25, 2019

Looks like the starts with syntax is str.startswith

https://www.tutorialspoint.com/python/string_startswith.htm

Also looks like there needs to be a None check

AttributeError: 'NoneType' object has no attribute 'startsWith'

I can show you how that's done

@Aubron Aubron merged commit 68d41f5 into Bandwidth:master Mar 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants