def test_good_transaction(self): from google.cloud.firestore_v1beta1.transaction import Transaction transaction = Transaction(mock.sentinel.client) txn_id = b'doubt-it' transaction._id = txn_id self.assertTrue(transaction.in_progress) self.assertEqual(self._call_fut(transaction), txn_id)
def test_after_writes_allowed(self): from google.cloud.firestore_v1beta1.transaction import Transaction transaction = Transaction(mock.sentinel.client) txn_id = b'we-are-0fine' transaction._id = txn_id transaction._write_pbs.append(mock.sentinel.write) ret_val = self._call_fut(transaction, read_operation=False) self.assertEqual(ret_val, txn_id)
def test_after_writes_not_allowed(self): from google.cloud.firestore_v1beta1._helpers import ReadAfterWriteError from google.cloud.firestore_v1beta1.transaction import Transaction transaction = Transaction(mock.sentinel.client) transaction._id = b'under-hook' transaction._write_pbs.append(mock.sentinel.write) with self.assertRaises(ReadAfterWriteError): self._call_fut(transaction)
def test_get_with_transaction(self): from google.cloud.firestore_v1beta1.client import Client from google.cloud.firestore_v1beta1.transaction import Transaction # Create a minimal fake client with a dummy response. response_iterator = iter([mock.sentinel.snapshot]) client = mock.create_autospec(Client, instance=True) client.get_all.return_value = response_iterator # Actually make a document and call get(). document = self._make_one('yellow', 'mellow', client=client) transaction = Transaction(client) transaction._id = b'asking-me-2' snapshot = document.get(transaction=transaction) # Verify the response and the mocks. self.assertIs(snapshot, mock.sentinel.snapshot) client.get_all.assert_called_once_with( [document], field_paths=None, transaction=transaction)
def test_get_with_transaction(self): from google.cloud.firestore_v1beta1.client import Client from google.cloud.firestore_v1beta1.transaction import Transaction # Create a minimal fake client with a dummy response. response_iterator = iter([mock.sentinel.snapshot]) client = mock.create_autospec(Client, instance=True) client.get_all.return_value = response_iterator # Actually make a document and call get(). document = self._make_one('yellow', 'mellow', client=client) transaction = Transaction(client) transaction._id = b'asking-me-2' snapshot = document.get(transaction=transaction) # Verify the response and the mocks. self.assertIs(snapshot, mock.sentinel.snapshot) client.get_all.assert_called_once_with( [document], field_paths=None, transaction=transaction)