<s> from mock import Mock , patch <EOL> import unittest <EOL> from contextio . lib . resources . account import Account <EOL> from contextio . lib . resources . contact import Contact <EOL> from contextio . lib . resources . connect_token import ConnectToken <EOL> from contextio . lib . resources . email_address import EmailAddress <EOL> from contextio . lib . resources . message import Message <EOL> from contextio . lib . resources . source import Source <EOL> from contextio . lib . resources . thread import Thread <EOL> from contextio . lib . resources . webhook import WebHook <EOL> from contextio . lib . resources . file import File <EOL> from contextio . lib . helpers import ArgumentError <EOL> class TestAccount ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . account = Account ( Mock ( spec = [ ] ) , { "<STR_LIT:id>" : "<STR_LIT>" } ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_updates_first_and_last_name ( self , mock_post ) : <EOL> mock_post . return_value = True <EOL> params = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> response = self . account . post ( ** params ) <EOL> self . assertEqual ( self . account . first_name , "<STR_LIT>" ) <EOL> self . assertEqual ( self . account . last_name , "<STR_LIT>" ) <EOL> mock_post . assert_called_with ( all_args = [ '<STR_LIT>' , '<STR_LIT>' ] , params = params ) <EOL> self . assertTrue ( response ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_connect_tokens_returns_list_of_connect_tokens ( self , mock_request ) : <EOL> mock_request . return_value = [ { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT>" } } ] <EOL> account_connect_tokens = self . account . get_connect_tokens ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( account_connect_tokens ) ) <EOL> self . assertIsInstance ( account_connect_tokens [ <NUM_LIT:0> ] , ConnectToken ) <EOL> self . assertIsInstance ( account_connect_tokens [ <NUM_LIT:0> ] . account , Account ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_contacts_returns_list_of_contacts ( self , mock_get ) : <EOL> mock_get . return_value = { "<STR_LIT>" : [ { "<STR_LIT:email>" : "<STR_LIT>" } ] } <EOL> account_contacts = self . account . get_contacts ( ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( account_contacts ) ) <EOL> self . assertIsInstance ( account_contacts [ <NUM_LIT:0> ] , Contact ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_email_addresses_returns_list_of_EmailAddresses ( self , mock_request ) : <EOL> mock_request . return_value = [ { "<STR_LIT:email>" : "<STR_LIT>" } ] <EOL> response = self . account . get_email_addresses ( ) <EOL> self . assertIsInstance ( response [ <NUM_LIT:0> ] , EmailAddress ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_files_returns_list_of_Files ( self , mock_request ) : <EOL> mock_request . return_value = [ { "<STR_LIT>" : "<STR_LIT>" } ] <EOL> response = self . account . get_files ( ) <EOL> self . assertIsInstance ( response [ <NUM_LIT:0> ] , File ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_messages_returns_list_of_Messages ( self , mock_request ) : <EOL> mock_request . return_value = [ { "<STR_LIT>" : "<STR_LIT>" } ] <EOL> response = self . account . get_messages ( ) <EOL> self . assertIsInstance ( response [ <NUM_LIT:0> ] , Message ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_sources_returns_list_of_Sources ( self , mock_request ) : <EOL> mock_request . return_value = [ { "<STR_LIT:label>" : "<STR_LIT>" } ] <EOL> response = self . account . get_sources ( ) <EOL> self . assertIsInstance ( response [ <NUM_LIT:0> ] , Source ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_sync_returns_a_dictionary ( self , mock_request ) : <EOL> mock_request . return_value = { "<STR_LIT:foo>" : "<STR_LIT:bar>" } <EOL> response = self . account . get_sync ( ) <EOL> self . assertIsInstance ( response , dict ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_threads_returns_list_of_Threads ( self , mock_request ) : <EOL> mock_request . return_value = [ "<STR_LIT>" ] <EOL> response = self . account . get_threads ( ) <EOL> self . assertIsInstance ( response [ <NUM_LIT:0> ] , Thread ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_get_webhooks_returns_list_of_WebHooks ( self , mock_request ) : <EOL> mock_request . return_value = [ { "<STR_LIT>" : "<STR_LIT>" } ] <EOL> response = self . account . get_webhooks ( ) <EOL> self . assertIsInstance ( response [ <NUM_LIT:0> ] , WebHook ) <EOL> def test_post_connect_token_requires_callback_url ( self ) : <EOL> with self . assertRaises ( ArgumentError ) : <EOL> self . account . post_connect_token ( ) <EOL> def test_post_email_address_requires_email_address ( self ) : <EOL> with self . assertRaises ( ArgumentError ) : <EOL> self . account . post_email_address ( ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_email_address_returns_EmailAddress ( self , mock_post ) : <EOL> mock_post . return_value = { "<STR_LIT:email>" : "<STR_LIT>" } <EOL> email_address = self . account . post_email_address ( email_address = "<STR_LIT>" ) <EOL> self . assertIsInstance ( email_address , EmailAddress ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_message_requires_certain_args ( self , mock_post ) : <EOL> all_args = [ <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:message>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" <EOL> ] <EOL> req_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:message>" ] <EOL> self . account . post_message ( ) <EOL> mock_post . assert_called_with ( <EOL> all_args = all_args , headers = { "<STR_LIT:Content-Type>" : "<STR_LIT>" } , <EOL> params = { } , <EOL> required_args = req_args , <EOL> return_bool = False , <EOL> uri = "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_source_requires_certain_args ( self , mock_post ) : <EOL> all_args = [ <EOL> '<STR_LIT:email>' , '<STR_LIT>' , '<STR_LIT:username>' , '<STR_LIT:port>' , '<STR_LIT:type>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:password>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ] <EOL> req_args = [ '<STR_LIT:email>' , '<STR_LIT>' , '<STR_LIT:username>' , '<STR_LIT:port>' , '<STR_LIT:type>' , '<STR_LIT>' ] <EOL> self . account . post_source ( ) <EOL> mock_post . assert_called_with ( <EOL> return_bool = False , <EOL> all_args = all_args , <EOL> params = { "<STR_LIT>" : <NUM_LIT:1> , "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:port>" : <NUM_LIT> } , <EOL> required_args = req_args , <EOL> uri = "<STR_LIT>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_source_returns_Source_object ( self , mock_post ) : <EOL> mock_post . return_value = { "<STR_LIT:label>" : "<STR_LIT>" } <EOL> source = self . account . post_source ( ) <EOL> self . assertIsInstance ( source , Source ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_source_returns_False_if_creation_failed ( self , mock_post ) : <EOL> mock_post . return_value = { "<STR_LIT:success>" : False } <EOL> response = self . account . post_source ( ) <EOL> self . assertFalse ( response ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_sync_calls_request_uri_with_correct_args ( self , mock_request ) : <EOL> self . account . post_sync ( ) <EOL> mock_request . assert_called_with ( "<STR_LIT>" , method = "<STR_LIT:POST>" ) <EOL> def test_post_webhook_requires_args ( self ) : <EOL> with self . assertRaises ( ArgumentError ) : <EOL> self . account . post_webhook ( ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_webhook_returns_WebHook_object ( self , mock_post ) : <EOL> mock_post . return_value = { "<STR_LIT:success>" : True , "<STR_LIT>" : "<STR_LIT>" } <EOL> webhook = self . account . post_webhook ( ) <EOL> self . assertIsInstance ( webhook , WebHook ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_post_webhook_returns_False_if_creation_failed ( self , mock_post ) : <EOL> mock_post . return_value = { "<STR_LIT:success>" : False } <EOL> response = self . account . post_webhook ( ) <EOL> self . assertFalse ( response ) </s>
