def get_accounts(self, **params): """List of Accounts. GET method for the accounts resource. Documentation: http://context.io/docs/2.0/accounts#get Optional Arguments: email: string - Only return account associated to this email address status: string - Only return accounts with sources whose status is of a specific value. If an account has many sources, only those matching the given value will be included in the response. Possible statuses are: INVALID_CREDENTIALS, CONNECTION_IMPOSSIBLE, NO_ACCESS_TO_ALL_MAIL, OK, TEMP_DISABLED and DISABLED status_ok: int - Only return accounts with sources whose status is of a specific value. If an account has many sources, only those matching the given value will be included in the response. Possible statuses are: INVALID_CREDENTIALS, CONNECTION_IMPOSSIBLE, NO_ACCESS_TO_ALL_MAIL, OK, TEMP_DISABLED and DISABLED limit: int - The maximum number of results to return offset: int - Start the list at this offset (zero-based) Returns: A list of Account objects """ all_args = ["email", "status", "status_ok", "limit", "offset"] params = helpers.sanitize_params(params, all_args) return [ Account(self, obj) for obj in self._request_uri("accounts", params=params) ]
def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) self.connect_token = ConnectToken(self.account, {"token": "fake_token"}) self.uri = "https://api.context.io/2.0/accounts/fake_id/sources/foobar/folders/fake_folder_name/"
def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) contact_definition = { "email": "*****@*****.**", "count": 1, "sent_count": 0, "received_count": 1, "sent_from_account_count": 0, "thumbnail": "https://some.url", "last_sent": None, "last_received": 1455649370 } self.contact = Contact(self.account, contact_definition)
def test_constructor_sets_account_attribute_to_none_if_empty_dict(self): definition = { "token": "fake_token", "email": "*****@*****.**", "created": 1458569718, "used": 1458569718, "expires": False, "callback_url": "https://some.url", "first_name": "fake", "last_name": "name", "account": {} } account = Account(Mock(), {"id": "fake_id"}) connect_token = ConnectToken(account, definition) self.assertEqual(None, connect_token.account)
def __init__(self, parent, definition): """Constructor. Required Arguments: parent: ContextIO object - parent is an ContextIO object. definition: a dictionary of parameters. The 'token' parameter is required to make method calls. """ super(ConnectToken, self).__init__(parent, 'connect_tokens/{token}', definition) # yes this is gross account = definition.get("account") if account is not None and len(account) > 0: if isinstance(definition["account"], basestring): account_details = {"id": account} else: account_details = account from contextio.lib.v2_0.resources.account import Account self.account = Account(self.parent, account_details) else: self.account = None
def post_account(self, **params): """Add a new account. POST method for the accounts resource. You can optionally pass in the params to simultaneously add a source with just this one call. In order to accomplish this you must include all of the required parameters to create a source AS WELL AS one of the following: - the password for the source - the provider_refresh_token AND provider_consumer_key *see https://context.io/docs/2.0/accounts/sources#post for more information* Documentation: http://context.io/docs/2.0/accounts#post Required Arguments: email: string - The primary email address of the account holder. migrate_account_id: string - Existing user_id (from lite) you want to migrate to 2.0. Either migrate_account_id or email must be specified Optional Arguments: first_name: string - First name of the account holder. last_name: string - Last name of the account holder. If adding a source in the same call: Required Arguments: server: string - Name or IP of the IMAP server, eg. imap.gmail.com username: string - The username used to authenticate an IMAP connection. On some servers, this is the same thing as the primary email address. use_ssl: integer - Set to 1 if you want SSL encryption to be used when opening connections to the IMAP server. Any other value will be considered as "do not use SSL" port: integer - Port number to connect to on the server. Keep in mind that most IMAP servers will have one port for standard connection and another one for encrypted connection (see use-ssl parameter above) type: string - Currently, the only supported type is IMAP Optional Arguments: origin_ip: string - IP address of the end user requesting the account to be created expunge_on_deleted_flag: integer - By default, we don't filter out messages flagged as deleted. Set this parameter to 1 to turn on this filtering. sync_all_folders: integer - By default, we filter out some folders like 'Deleted Items' and 'Drafts'. Set this parameter to 1 to turn off this filtering and show every single folder. sync_folders: string - By default, we filter out some folders like 'Deleted Items' and 'Drafts'. Set this parameter to 'All,Trash' to show the 'Deleted Items' folder. sync_flags: integer By default, we don't synchronize IMAP flags. Set this parameter to 1 to turn on IMAP flag syncing for the 'seen' and 'flagged' flags. raw_file_list: integer - By default, we filter out files like signature images or those winmail.dat files form the files list. Set this parameter to 1 to turn off this filtering and show every single file attachments. password: string - Password for authentication on the IMAP server. Ignored if any of the provider_* parameters are set below. provider_refresh_token: An OAuth2 refresh token obtained from the IMAP account provider to be used to authenticate on this email account. provider_consumer_key: string - The OAuth consumer key used to obtain the the token and token secret above for that account. That consumer key and secret must be configured in your Context.IO account. callback_url: string (url) - If specified, we'll make a POST request to this URL when the initial sync is completed. status_callback_url: string (url) - If specified, we'll make a POST request to this URL if the connection status of the source changes. Returns: An Account object """ req_args = ["email"] all_args = [ "email", "migrate_account_id", "first_name", "last_name", "server", "username", "use_ssl", "port", "type", "origin_ip", "expunge_on_deleted_flag", "sync_all_folders", "sync_folders", "sync_flags", "raw_file_list", "password", "provider_refresh_token", "provider_consumer_key", "callback_url", "status_callback_url" ] params = helpers.sanitize_params(params, all_args, req_args) return Account( self, self._request_uri("accounts", method="POST", params=params))
def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) self.source = Source(self.account, {"label": "foobar"}) self.folder = Folder(self.source, {"name": "fake_folder_name"})
def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) self.uri = "https://api.context.io/2.0/accounts/fake_id/"
class TestAccountResource(unittest.TestCase): def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) self.uri = "https://api.context.io/2.0/accounts/fake_id/" @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_updates_first_and_last_name(self, mock_post): mock_post.return_value = True params = { "first_name": "Leeroy", "last_name": "Jenkins" } response = self.account.post(**params) self.assertEqual(self.account.first_name, "Leeroy") self.assertEqual(self.account.last_name, "Jenkins") mock_post.assert_called_with(all_args=['first_name', 'last_name'], params=params) self.assertTrue(response) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_get_connect_tokens_returns_list_of_connect_tokens(self, mock_request): mock_request.return_value = [{"token": "fake_token", "account": {"id": "foobar"}}] account_connect_tokens = self.account.get_connect_tokens() self.assertEqual(1, len(account_connect_tokens)) self.assertIsInstance(account_connect_tokens[0], ConnectToken) self.assertIsInstance(account_connect_tokens[0].account, Account) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.get") def test_get_contacts_returns_list_of_contacts(self, mock_get): mock_get.return_value = {"matches": [{"email": "*****@*****.**"}]} account_contacts = self.account.get_contacts() self.assertEqual(1, len(account_contacts)) self.assertIsInstance(account_contacts[0], Contact) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_get_email_addresses_returns_list_of_EmailAddresses(self, mock_request): mock_request.return_value = [{"email": "fake_token"}] response = self.account.get_email_addresses() self.assertIsInstance(response[0], EmailAddress) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_get_files_returns_list_of_Files(self, mock_request): mock_request.return_value = [{"file_id": "foobar"}] response = self.account.get_files() self.assertIsInstance(response[0], File) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_get_messages_returns_list_of_Messages(self, mock_request): mock_request.return_value = [{"message_id": "foobar"}] response = self.account.get_messages() self.assertIsInstance(response[0], Message) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_get_sources_returns_list_of_Sources(self, mock_request): mock_request.return_value = [{"label": "foobar"}] response = self.account.get_sources() self.assertIsInstance(response[0], Source) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_get_sync_returns_a_dictionary(self, mock_request): mock_request.return_value = {"foo": "bar"} response = self.account.get_sync() self.assertIsInstance(response, dict) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_get_threads_returns_list_of_Threads(self, mock_request): mock_request.return_value = ["foo/bar"] response = self.account.get_threads() self.assertIsInstance(response[0], Thread) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_get_webhooks_returns_list_of_WebHooks(self, mock_request): mock_request.return_value = [{"webhook_id": "foobar"}] response = self.account.get_webhooks() self.assertIsInstance(response[0], WebHook) def test_post_connect_token_requires_callback_url(self): with self.assertRaises(ArgumentError): self.account.post_connect_token() def test_post_email_address_requires_email_address(self): with self.assertRaises(ArgumentError): self.account.post_email_address() @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_email_address_returns_EmailAddress(self, mock_post): mock_post.return_value = {"email": "*****@*****.**"} email_address = self.account.post_email_address(email_address="*****@*****.**") self.assertIsInstance(email_address, EmailAddress) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_message_requires_certain_args(self, mock_post): all_args = [ "dst_source", "dst_folder", "message", "flag_seen", "flag_answered", "flag_flagged", "flag_deleted", "flag_draft" ] req_args = ["dst_source", "dst_folder", "message"] self.account.post_message() mock_post.assert_called_with( all_args=all_args, headers={"Content-Type": "multipart/form-data"}, params={}, required_args=req_args, return_bool=False, uri="messages") @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_source_requires_certain_args(self, mock_post): all_args = [ 'email', 'server', 'username', 'port', 'type', 'use_ssl', 'origin_ip', 'expunge_on_deleted_flag', 'sync_all_folders', 'sync_folders', 'sync_flags', 'raw_file_list', 'password', 'provider_refresh_token', 'provider_consumer_key', 'callback_url', 'status_callback_url' ] req_args = ['email', 'server', 'username', 'port', 'type', 'use_ssl'] self.account.post_source() mock_post.assert_called_with( return_bool=False, all_args=all_args, params={"use_ssl": 1, "type": "IMAP", "port": 993}, required_args=req_args, uri="sources") @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_source_returns_Source_object(self, mock_post): mock_post.return_value = {"label": "foobar"} source = self.account.post_source() self.assertIsInstance(source, Source) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_source_returns_False_if_creation_failed(self, mock_post): mock_post.return_value = {"success": False} response = self.account.post_source() self.assertFalse(response) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource._request_uri") def test_post_sync_calls_request_uri_with_correct_args(self, mock_request): self.account.post_sync() mock_request.assert_called_with("sync", method="POST") @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_webhook_requires_certain_args(self, mock_post): req_args = ['callback_url', 'failure_notif_url'] all_args = [ 'callback_url', 'failure_notif_url', 'filter_to', 'filter_from', 'filter_cc', 'filter_subject', 'filter_thread', 'filter_new_important', 'filter_file_name', 'filter_folder_added', 'filter_folder_removed', 'filter_to_domain', 'filter_from_domain', 'include_body', 'body_type', 'include_parsed_receipts' ] self.account.post_webhook() mock_post.assert_called_with( return_bool=False, all_args=all_args, params={}, required_args=req_args, uri="webhooks") @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_webhook_returns_WebHook_object(self, mock_post): mock_post.return_value = {"success": True, "webhook_id": "foobar"} webhook = self.account.post_webhook() self.assertIsInstance(webhook, WebHook) @patch("contextio.lib.v2_0.resources.base_resource.BaseResource.post") def test_post_webhook_returns_False_if_creation_failed(self, mock_post): mock_post.return_value = {"success": False} response = self.account.post_webhook() self.assertFalse(response)
def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) self.webhook = WebHook(self.account, {"webhook_id": "fake_webhook_id"})
def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) self.file = File(self.account, {"file_id": "fake_file_id"})
def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) self.message = Message(self.account, {"message_id": "fake_message_id"})
def setUp(self): self.contextio = ContextIO(consumer_key="foo", consumer_secret="bar") self.account = Account(self.contextio, {"id": "fake_id"}) self.thread = Thread(self.account, {"gmail_thread_id": "foobar"})