当前位置: 首页>>代码示例>>Python>>正文


Python document.Document类代码示例

本文整理汇总了Python中cloudant.document.Document的典型用法代码示例。如果您正苦于以下问题:Python Document类的具体用法?Python Document怎么用?Python Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_attachment_delete

    def test_attachment_delete(self):
        """
        _test_attachment_delete_
        """
        doc = Document(self.database, "DUCKUMENT")
        doc_id = 'DUCKUMENT'
        attachment = 'herpderp.txt'

        mock_get = mock.Mock()
        mock_get.raise_for_status = mock.Mock()
        mock_get.status_code = 200
        mock_get.json = mock.Mock()
        mock_get.json.return_value = {'_id': doc_id, '_rev': '2-def'}
        self.mock_session.get.return_value = mock_get

        mock_del = mock.Mock()
        mock_del.raise_for_status = mock.Mock()
        mock_del.status_code = 200
        mock_del.json = mock.Mock()
        mock_del.json.return_value = {'id': doc_id, 'rev': '3-ghi', 'ok': True}
        self.mock_session.delete.return_value = mock_del

        resp = doc.delete_attachment(attachment)

        self.assertEqual(resp['id'], doc_id)
        self.assertTrue(self.mock_session.get.called)
        self.assertTrue(self.mock_session.delete.called)
开发者ID:iblis17,项目名称:python-cloudant,代码行数:27,代码来源:document_test.py

示例2: test_rewrite_rule

 def test_rewrite_rule(self):
     """
     Test that design document URL is rewritten to the expected test document.
     """
     ddoc = DesignDocument(self.db, '_design/ddoc001')
     ddoc['rewrites'] = [
         {"from": "",
          "to": "/../../rewrite_doc",
          "method": "GET",
          "query": {}
          }
     ]
     self.assertIsInstance(ddoc.rewrites, list)
     self.assertIsInstance(ddoc.rewrites[0], dict)
     ddoc.save()
     doc = Document(self.db, 'rewrite_doc')
     doc.save()
     resp = self.client.r_session.get('/'.join([ddoc.document_url, '_rewrite']))
     self.assertEquals(
         resp.json(),
         {
             '_id': 'rewrite_doc',
             '_rev': doc['_rev']
         }
     )
开发者ID:drarvindsathi,项目名称:python-cloudant,代码行数:25,代码来源:design_document_tests.py

示例3: test_attachment_get

    def test_attachment_get(self):
        """
        _test_attachment_get_
        """
        doc = Document(self.database, "DUCKUMENT")
        doc_id = 'DUCKUMENT'
        attachment = 'herpderp.txt'

        mock_get = mock.Mock()
        mock_get.raise_for_status = mock.Mock()
        mock_get.status_code = 200
        mock_get.json = mock.Mock()
        mock_get.json.return_value = {'_id': doc_id, '_rev': '1-abc'}

        mock_get_attch = mock.Mock()
        mock_get_attch.raise_for_status = mock.Mock()
        mock_get_attch.status_code = 200
        mock_get_attch.content = 'herp derp foo bar'

        self.mock_session.get.side_effect = [mock_get, mock_get_attch]

        resp = doc.get_attachment(attachment, attachment_type='binary')

        self.assertEqual(resp, mock_get_attch.content)
        self.assertEqual(self.mock_session.get.call_count, 2)
开发者ID:iblis17,项目名称:python-cloudant,代码行数:25,代码来源:document_test.py

示例4: test_attachment_put

    def test_attachment_put(self):
        """
        _test_attachment_put_
        """
        doc = Document(self.database, "DUCKUMENT")
        doc_id = 'DUCKUMENT'
        attachment = 'herpderp.txt'
        data = '/path/to/herpderp.txt'

        mock_get = mock.Mock()
        mock_get.raise_for_status = mock.Mock()
        mock_get.status_code = 200
        mock_get.json = mock.Mock()
        mock_get.json.return_value = {'_id': doc_id, '_rev': '1-abc'}
        self.mock_session.get.return_value = mock_get

        mock_put = mock.Mock()
        mock_put.raise_for_status = mock.Mock()
        mock_put.status_code = 201
        mock_put.json = mock.Mock()
        mock_put.json.return_value = {'id': doc_id, 'rev': '2-def', 'ok': True}
        self.mock_session.put.return_value = mock_put

        resp = doc.put_attachment(
            attachment,
            content_type='text/plain',
            data=data
        )

        self.assertEqual(resp['id'], doc_id)
        self.assertTrue(self.mock_session.get.called)
        self.assertTrue(self.mock_session.put.called)
开发者ID:iblis17,项目名称:python-cloudant,代码行数:32,代码来源:document_test.py

示例5: test_appended_error_message_using_save_with_invalid_key

 def test_appended_error_message_using_save_with_invalid_key(self):
     """
     Test that saving a document with an invalid remote key will
     throw an HTTPError with additional error details from util
     method append_response_error_content.
     """
     # First create the document
     doc = Document(self.db, 'julia006')
     # Add an invalid key and try to save document
     doc['_invalid_key'] = 'jules'
     with self.assertRaises(requests.HTTPError) as cm:
         doc.save()
     err = cm.exception
     # Should be a 400 error code, but CouchDB 1.6 issues a 500
     if err.response.status_code == 500:
         #Check this is CouchDB 1.6
         self.assertTrue(self.client.r_session.head(self.url).headers['Server'].find('CouchDB/1.6.') >= 0,
                         '500 returned but was not CouchDB 1.6.x')
         self.assertEqual(
             str(err.response.reason),
             'Internal Server Error doc_validation Bad special document member: _invalid_key'
         )
     else:
         self.assertEqual(
             str(err.response.reason),
             'Bad Request doc_validation Bad special document member: _invalid_key'
         )
         self.assertEqual(
             err.response.status_code,
             400
         )
开发者ID:cloudant,项目名称:python-cloudant,代码行数:31,代码来源:document_tests.py

示例6: doc_exist

    def doc_exist(self, docid):
        """Test if document exists in a database

        @param docid: str, document id
        @return: boolean, True if document exist
        """
        doc = Document(self.cloudant_database, docid)
        return doc.exists()
开发者ID:dimagi,项目名称:couchdbkit,代码行数:8,代码来源:client.py

示例7: test_constructor_with_docid

 def test_constructor_with_docid(self):
     """
     Test instantiating a Document providing an id
     """
     doc = Document(self.db, 'julia006')
     self.assertIsInstance(doc, Document)
     self.assertEqual(doc.r_session, self.db.r_session)
     self.assertEqual(doc.get('_id'), 'julia006')
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:8,代码来源:document_tests.py

示例8: test_constructor_without_docid

 def test_constructor_without_docid(self):
     """
     Test instantiating a Document without providing an id
     """
     doc = Document(self.db)
     self.assertIsInstance(doc, Document)
     self.assertEqual(doc.r_session, self.db.r_session)
     self.assertIsNone(doc.get('_id'))
     self.assertIsNone(doc.document_url)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:9,代码来源:document_tests.py

示例9: test_removing_id

 def test_removing_id(self):
     """
     Ensure that proper processing occurs when removing the _id
     """
     doc = Document(self.db)
     doc['_id'] = 'julia006'
     del doc['_id']
     self.assertIsNone(doc.get('_id'))
     self.assertEqual(doc._document_id, None)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:9,代码来源:document_tests.py

示例10: test_fetch_non_existing_document

 def test_fetch_non_existing_document(self):
     """
     Test fetching document content from a non-existing document
     """
     doc = Document(self.db, 'julia006')
     try:
         doc.fetch()
         self.fail('Above statement should raise an Exception')
     except requests.HTTPError as err:
         self.assertEqual(err.response.status_code, 404)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:10,代码来源:document_tests.py

示例11: test_setting_id

 def test_setting_id(self):
     """
     Ensure that proper processing occurs when setting the _id
     """
     doc = Document(self.db)
     self.assertIsNone(doc.get('_id'))
     self.assertEqual(doc._document_id, None)
     doc['_id'] = 'julia006'
     self.assertEqual(doc['_id'], 'julia006')
     self.assertEqual(doc._document_id, 'julia006')
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:10,代码来源:document_tests.py

示例12: test_list_field_remove_successfully

 def test_list_field_remove_successfully(self):
     """
     Test the static helper method to successfully remove from a list field.
     """
     doc = Document(self.db)
     self.assertEqual(doc, {})
     doc.list_field_append(doc, 'pets', 'cat')
     doc.list_field_append(doc, 'pets', 'dog')
     self.assertEqual(doc, {'pets': ['cat', 'dog']})
     doc.list_field_remove(doc, 'pets', 'dog')
     self.assertEqual(doc, {'pets': ['cat']})
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:11,代码来源:document_tests.py

示例13: test_document_update_field

    def test_document_update_field(self):
        """
        _test_document_update_field_

        Tests for the field update functions.
        """

        # Setup a routine for testing conflict handing.
        errors = {'conflicts': 0}

        def raise_conflict(conflicts=3):
            if errors['conflicts'] < conflicts:
                errors['conflicts'] += 1
                err = requests.HTTPError()
                err.response = mock.Mock()
                err.response.status_code = 409
                raise err

        # Mock our our doc
        doc = Document(self.database, "HOWARD")

        mock_put_resp = mock.Mock()
        mock_put_resp.side_effect = mock.Mock()
        mock_put_resp.status_code = 200
        mock_put_resp.raise_for_status = raise_conflict
        mock_put_resp.json.side_effect = lambda: {'id': "ID", "rev": "updated"}
        self.mock_session.put.return_value = mock_put_resp
        mock_get_resp = mock.Mock()
        mock_get_resp.status_code = 200
        mock_get_resp.json.side_effect = lambda: {"foo": "baz"}
        self.mock_session.get.return_value = mock_get_resp

        # Verify that our mock doc has the old value
        doc.fetch()
        self.assertEqual(doc["foo"], "baz")

        # And that we replace it with an updated value
        doc.update_field(doc.field_set, "foo", "bar")
        self.assertEqual(doc["foo"], "bar")

        # And verify that we called mock_session.put
        self.assertTrue(self.mock_session.put.called)

        # Try again, verifing that excessive conflicts get raised
        errors['conflicts'] = 0
        mock_put_resp.raise_for_status = lambda: raise_conflict(conflicts=11)

        self.assertRaises(
            requests.HTTPError,
            doc.update_field,
            doc.field_set,
            "foo",
            "bar"
        )
开发者ID:iblis17,项目名称:python-cloudant,代码行数:54,代码来源:document_test.py

示例14: test_retrieve_document_json

 def test_retrieve_document_json(self):
     """
     Test the document dictionary renders as json appropriately
     """
     doc = Document(self.db)
     doc['_id'] = 'julia006'
     doc['name'] = 'julia'
     doc['age'] = 6
     doc_as_json = doc.json()
     self.assertIsInstance(doc_as_json, str)
     self.assertEqual(json.loads(doc_as_json), doc)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:11,代码来源:document_tests.py

示例15: test_create_existing_document

 def test_create_existing_document(self):
     """
     Test creating an already existing document
     """
     doc = Document(self.db, 'julia006')
     doc.create()
     try:
         doc.create()
         self.fail('Above statement should raise an Exception')
     except requests.HTTPError as err:
         self.assertEqual(err.response.status_code, 409)
开发者ID:dqdgardener,项目名称:python-cloudant,代码行数:11,代码来源:document_tests.py


注:本文中的cloudant.document.Document类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。