def test_get_content_calls_request_uri_with_correct_arguments(
            self, mock_request):
        file = File(Mock(), {"file_id": "fake_file_id"})

        file.get_content()

        mock_request.assert_called_with("content", headers={})
    def test_get_content_calls_request_uri_with_correct_arguments_when_download_link_is_True(
            self, mock_request):
        file = File(Mock(), {"file_id": "fake_file_id"})

        file.get_content(download_link=True)

        mock_request.assert_called_with("content",
                                        headers={"Accept": "text/uri-list"})
class TestFile(unittest.TestCase):
    def setUp(self):
        self.file = File(Mock(), {"file_id": "fake_file_id"})

    def test_constructor_creates_file_object_with_all_attributes_in_keys_list(
            self):
        self.assertTrue(hasattr(self.file, "size"))
        self.assertTrue(hasattr(self.file, "type"))
        self.assertTrue(hasattr(self.file, "subject"))
        self.assertTrue(hasattr(self.file, "date"))
        self.assertTrue(hasattr(self.file, "date_indexed"))
        self.assertTrue(hasattr(self.file, "addresses"))
        self.assertTrue(hasattr(self.file, "person_info"))
        self.assertTrue(hasattr(self.file, "file_name"))
        self.assertTrue(hasattr(self.file, "file_name_structure"))
        self.assertTrue(hasattr(self.file, "body_section"))
        self.assertTrue(hasattr(self.file, "file_id"))
        self.assertTrue(hasattr(self.file, "supports_preview"))
        self.assertTrue(hasattr(self.file, "is_embedded"))
        self.assertTrue(hasattr(self.file, "content_disposition"))
        self.assertTrue(hasattr(self.file, "content_id"))
        self.assertTrue(hasattr(self.file, "message_id"))
        self.assertTrue(hasattr(self.file, "email_message_id"))
        self.assertTrue(hasattr(self.file, "gmail_message_id"))
        self.assertTrue(hasattr(self.file, "gmail_thread_id"))

    @patch("contextio.lib.resources.file.File._request_uri")
    def test_get_content_calls_request_uri_with_correct_arguments(
            self, mock_request):
        file = File(Mock(), {"file_id": "fake_file_id"})

        file.get_content()

        mock_request.assert_called_with("content", headers={})

    @patch("contextio.lib.resources.file.File._request_uri")
    def test_get_content_calls_request_uri_with_correct_arguments_when_download_link_is_True(
            self, mock_request):
        file = File(Mock(), {"file_id": "fake_file_id"})

        file.get_content(download_link=True)

        mock_request.assert_called_with("content",
                                        headers={"Accept": "text/uri-list"})

    @patch("contextio.lib.resources.base_resource.BaseResource._request_uri")
    def test_get_related_returns_a_list_of_File_objects(self, mock_request):
        mock_request.return_value = [{"file_id": "related_file_id"}]

        related_files = self.file.get_related()

        self.assertEqual(1, len(related_files))
        self.assertIsInstance(related_files[0], File)
class TestFile(unittest.TestCase):
    def setUp(self):
        self.file = File(Mock(), {"file_id": "fake_file_id"})

    def test_constructor_creates_file_object_with_all_attributes_in_keys_list(self):
        self.assertTrue(hasattr(self.file, "size"))
        self.assertTrue(hasattr(self.file, "type"))
        self.assertTrue(hasattr(self.file, "subject"))
        self.assertTrue(hasattr(self.file, "date"))
        self.assertTrue(hasattr(self.file, "date_indexed"))
        self.assertTrue(hasattr(self.file, "addresses"))
        self.assertTrue(hasattr(self.file, "person_info"))
        self.assertTrue(hasattr(self.file, "file_name"))
        self.assertTrue(hasattr(self.file, "file_name_structure"))
        self.assertTrue(hasattr(self.file, "body_section"))
        self.assertTrue(hasattr(self.file, "file_id"))
        self.assertTrue(hasattr(self.file, "supports_preview"))
        self.assertTrue(hasattr(self.file, "is_embedded"))
        self.assertTrue(hasattr(self.file, "content_disposition"))
        self.assertTrue(hasattr(self.file, "content_id"))
        self.assertTrue(hasattr(self.file, "message_id"))
        self.assertTrue(hasattr(self.file, "email_message_id"))
        self.assertTrue(hasattr(self.file, "gmail_message_id"))
        self.assertTrue(hasattr(self.file, "gmail_thread_id"))

    @patch("contextio.lib.resources.file.File._request_uri")
    def test_get_content_calls_request_uri_with_correct_arguments(self, mock_request):
        file = File(Mock(), {"file_id": "fake_file_id"})

        file.get_content()

        mock_request.assert_called_with("content", headers={})

    @patch("contextio.lib.resources.file.File._request_uri")
    def test_get_content_calls_request_uri_with_correct_arguments_when_download_link_is_True(self, mock_request):
        file = File(Mock(), {"file_id": "fake_file_id"})

        file.get_content(download_link=True)

        mock_request.assert_called_with("content", headers={"Accept": "text/uri-list"})

    @patch("contextio.lib.resources.base_resource.BaseResource._request_uri")
    def test_get_related_returns_a_list_of_File_objects(self, mock_request):
        mock_request.return_value = [{"file_id": "related_file_id"}]

        related_files = self.file.get_related()

        self.assertEqual(1, len(related_files))
        self.assertIsInstance(related_files[0], File)
    def get_files(self, **params):
        """List files exchanges with a contact.

        Documentation: http://context.io/docs/2.0/accounts/contacts/files#get

        Optional Arguments:
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of File objects
        """
        all_args = ['limit', 'offset']
        params = helpers.sanitize_params(params, all_args)

        return [
            File(self.parent, obj)
            for obj in self._request_uri('files', params=params)
        ]
    def __init__(self, parent, definition):
        """Constructor.

        Required Arguments:
            parent: Account object - parent is an Account object.
            definition: a dictionary of parameters. The 'message_id' parameter is
                required to make method calls.
        """

        super(Message, self).__init__(parent, 'messages/{message_id}',
                                      definition)

        if 'files' in definition:
            self.files = [
                File(self.parent, file) for file in definition['files']
            ]

        # some calls optionally return a message with some extra data
        if 'body' in definition:
            self.body = definition['body']
        if 'flags' in definition:
            self.flags = definition['flags']
        if 'headers' in definition:
            self.headers = definition['headers']
Exemple #7
0
    def get_files(self, **params):
        """List of files found as email attachments.

        GET method for the files resource.

        Documentation: http://context.io/docs/2.0/accounts/files

        Each of the email, to, from, cc and bcc parameters can be set to a
        comma-separated list of email addresses. These multiple addresses
        are treated as an OR combination.

        You can set more than one parameter when doing this call. Multiple
        parameters are treated as an AND combination.

        Optional Arguments:
            file_name: string - Search for files based on their name. You can
                filter names using typical shell wildcards such as *, ? and []
                or regular expressions by enclosing the search expression in a
                leading / and trailing /. For example, *.pdf would give you
                all PDF files while /\.jpe?g$/ would return all files whose
                name ends with .jpg or .jpeg
            file_size_min: integer - Search for files based on their size (in bytes).
            file_size_max: integer - Search for files based on their size (in bytes).
            email: string - Email address of the contact for whom you want the
                latest files exchanged with. By "exchanged with contact X" we
                mean any email received from contact X, sent to contact X or
                sent by anyone to both contact X and the source owner.
            to: string - Email address of a contact files have been sent to.
            from: string - Email address of a contact files have been received
                from.
            cc: string - Email address of a contact CC'ed on the messages.
            bcc: string - Email address of a contact BCC'ed on the messages.
            date_before: integer (unix time) - Only include files attached to
                messages sent before a given timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            date_after: integer (unix time) - Only include files attached to
                messages sent after a given timestamp. The value this filter
                is applied to is the Date: header of the message which refers
                to the time the message is sent from the origin.
            indexed_before: integer (unix time) - Only include files attached
                to messages indexed before a given timestamp. This is not the
                same as the date of the email, it is the time Context.IO
                indexed this message.
            indexed_after: integer (unix time) - Only include files attached
                to messages indexed after a given timestamp. This is not the
                same as the date of the email, it is the time Context.IO
                indexed this message.
            source: string - Filter messages by the account source label.
            sort_order: string - The sort order of the returned results.
                Possible values are asc and desc
            limit: integer - The maximum number of results to return.
            offset: integer - Start the list at this offset (zero-based).

        Returns:
            A list of File objects
        """
        all_args = [
            'file_name', 'file_size_min', 'file_size_max', 'email', 'to',
            'from', 'cc', 'bcc', 'date_before', 'date_after', 'indexed_before',
            'indexed_after', 'source', 'limit', 'offset'
        ]

        params = helpers.sanitize_params(params, all_args)

        return [
            File(self, obj)
            for obj in self._request_uri('files', params=params)
        ]
 def setUp(self):
     self.file = File(Mock(), {"file_id": "fake_file_id"})
    def test_get_content_calls_request_uri_with_correct_arguments_when_download_link_is_True(self, mock_request):
        file = File(Mock(), {"file_id": "fake_file_id"})

        file.get_content(download_link=True)

        mock_request.assert_called_with("content", headers={"Accept": "text/uri-list"})
    def test_get_content_calls_request_uri_with_correct_arguments(self, mock_request):
        file = File(Mock(), {"file_id": "fake_file_id"})

        file.get_content()

        mock_request.assert_called_with("content", headers={})
 def setUp(self):
     self.file = File(Mock(), {"file_id": "fake_file_id"})