From f36761ef2dad19d0436ce6ea31d2cafe2196a88d Mon Sep 17 00:00:00 2001 From: Alexis Crespo Date: Fri, 10 Dec 2021 08:55:42 -0500 Subject: [PATCH] Fix python tests runner --- requirements.txt | 1 + tools/snippet-testing/language_handler/python.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b8bdc7dcce..7be82a0747 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ mccabe==0.6.1 pycodestyle==2.6.0 pyflakes==2.2.0 yapf==0.30.0 +twilio==7.3.2 diff --git a/tools/snippet-testing/language_handler/python.rb b/tools/snippet-testing/language_handler/python.rb index d4d6523129..35cdc3e97b 100644 --- a/tools/snippet-testing/language_handler/python.rb +++ b/tools/snippet-testing/language_handler/python.rb @@ -16,7 +16,20 @@ def self.run_before_test(directory) end private - + def text_with_custom_header(file_content) + cert_path = ENV['FAKE_CERT_PATH'] + file_content.prepend( + "import twilio.rest.resources.base\n"\ + "import sys\n"\ + "twilio.rest.resources.base.get_cert_file = lambda: '#{cert_path}'\n"\ + "sys.modules['twilio.rest.base.resources'] = twilio.rest.resources.base\n" + ) + end + def replace_twilio_client_initialization(file_content) + cert_path = ENV['FAKE_CERT_PATH'] + file_content.gsub! 'Client(account_sid, auth_token)', + 'Client(account_sid, auth_token, http_client=FakerHttpClient())' || file_content + end def execute_command(file) command = bash_string_command( 'source /usr/local/bin/virtualenvwrapper.sh &&'\