示例#1
0
    async def test_get_all_unknown_result(self):
        from google.cloud.firestore_v1.base_client import _BAD_DOC_TEMPLATE

        client = self._make_default_one()

        expected_document = client.document("pineapple", "lamp1")

        data = {"z": 28.5}
        wrong_document = client.document("pineapple", "lamp2")
        document_pb, read_time = _doc_get_info(wrong_document._document_path, data)
        response = _make_batch_response(found=document_pb, read_time=read_time)

        # Exercise the mocked ``batch_get_documents``.
        with self.assertRaises(ValueError) as exc_info:
            await self._invoke_get_all(client, [expected_document], [response])

        err_msg = _BAD_DOC_TEMPLATE.format(response.found.name)
        self.assertEqual(exc_info.exception.args, (err_msg,))

        # Verify the call to the mock.
        doc_paths = [expected_document._document_path]
        client._firestore_api.batch_get_documents.assert_called_once_with(
            request={
                "database": client._database_string,
                "documents": doc_paths,
                "mask": None,
                "transaction": None,
            },
            metadata=client._rpc_metadata,
        )
示例#2
0
    def test_failure(self):
        from google.cloud.firestore_v1.base_client import _BAD_DOC_TEMPLATE

        doc_path = "1/888/call-now"
        with self.assertRaises(ValueError) as exc_info:
            self._call_fut(doc_path, {})

        err_msg = _BAD_DOC_TEMPLATE.format(doc_path)
        self.assertEqual(exc_info.exception.args, (err_msg,))
示例#3
0
def test__get_reference_failure():
    from google.cloud.firestore_v1.base_client import _BAD_DOC_TEMPLATE
    from google.cloud.firestore_v1.base_client import _get_reference

    doc_path = "1/888/call-now"
    with pytest.raises(ValueError) as exc_info:
        _get_reference(doc_path, {})

    err_msg = _BAD_DOC_TEMPLATE.format(doc_path)
    assert exc_info.value.args == (err_msg, )
    async def test_get_all_unknown_result(self):
        from google.cloud.firestore_v1.base_client import _BAD_DOC_TEMPLATE

        info = self._info_for_get_all({"z": 28.5}, {})
        client, document, _, _, response = info

        # Exercise the mocked ``batch_get_documents``.
        with self.assertRaises(ValueError) as exc_info:
            await self._get_all_helper(client, [document], [response])

        err_msg = _BAD_DOC_TEMPLATE.format(response.found.name)
        self.assertEqual(exc_info.exception.args, (err_msg, ))

        # Verify the call to the mock.
        doc_paths = [document._document_path]
        client._firestore_api.batch_get_documents.assert_called_once_with(
            request={
                "database": client._database_string,
                "documents": doc_paths,
                "mask": None,
                "transaction": None,
            },
            metadata=client._rpc_metadata,
        )