def test_delete_collection(self): client = fake_firestore.FakeFirestore() col_ref = client.collection('test_collection') self.assertIn('test_collection', client._data) col_ref.delete() self.assertNotIn('test_collection', client._data)
def setUp(self): super().setUp() self.db = fake_firestore.FakeFirestore() self.topic_path = 'MockTopicPath' self.max_parallel_tasks = 3 self.mock_pubsub = mock.Mock() self.mock_pubsub.topic_path.return_value = self.topic_path
def test_delete_document(self): client = fake_firestore.FakeFirestore() col_ref = client.collection('test_collection') doc_ref = col_ref.document('test_doc') doc_ref.set({'foo': 'bar'}) self.assertIn('test_doc', col_ref._data) doc_ref.delete() self.assertNotIn('test_doc', col_ref._data)
def test_set_values(self): client = fake_firestore.FakeFirestore() doc_ref = client.collection('test_collection').document('test_doc') doc_ref.set({'foo': 'bar'}) doc = doc_ref.get().to_dict() self.assertDictEqual(doc, {'foo': 'bar'}, 'should add a new document') doc_ref.set({'bar': 'baz'}) doc2 = doc_ref.get().to_dict() self.assertDictEqual(doc2, {'bar': 'baz'}, 'should overwrite an existing document')
def setUp(self): super().setUp() self.addCleanup(mock.patch.stopall) mock_auth = mock.patch.object(google.auth, 'default', autospec=True).start() mock_auth.return_value = (None, 'test_project') self.mock_api = mock.Mock() mock_discovery = mock.patch.object( discovery, 'build', autospec=True).start() mock_discovery.return_value = self.mock_api self.db = fake_firestore.FakeFirestore()
def test_no_update_in_transaction(self): client = fake_firestore.FakeFirestore() doc_ref = client.collection('test_collection').document('test_doc') doc_ref.set({'foo': 'bar'}) @firestore.transactional def trans_func(transaction): snapshot = doc_ref.get(transaction=transaction) if snapshot.get('foo') == 'baz': transaction.update(doc_ref, {'bar': 'baz'}) trans_func(client.transaction()) doc = doc_ref.get().to_dict() self.assertDictEqual(doc, {'foo': 'bar'}, 'transaction should not update data')
def test_update_values(self): client = fake_firestore.FakeFirestore() doc_ref = client.collection('test_collection').document('test_doc') doc_ref.set({'foo': 'bar'}) doc_ref.update({'bar': 'baz'}) doc = doc_ref.get().to_dict() self.assertDictEqual(doc, { 'foo': 'bar', 'bar': 'baz' }, 'should add a new key') doc_ref.update({'bar': 'baz2'}) doc2 = doc_ref.get().to_dict() self.assertDictEqual(doc2, { 'foo': 'bar', 'bar': 'baz2' }, 'should update an existing key')
def test_create_db_client(self): client = fake_firestore.FakeFirestore() self.assertIsNotNone(client) self.assertIsNotNone(client._data)