def test__compute_snapshot_modify_docs_updated_doc_no_timechange(self): from google.cloud.firestore_v1.watch import WatchDocTree doc_tree = WatchDocTree() class DummyDoc(object): pass updated_doc_v1 = DummyDoc() updated_doc_v1.update_time = 1 updated_doc_v1._document_path = "/updated" updated_doc_v2 = DummyDoc() updated_doc_v2.update_time = 1 updated_doc_v2._document_path = "/updated" doc_tree = doc_tree.insert("/updated", updated_doc_v1) doc_map = {"/updated": updated_doc_v1} updated_snapshot = DummyDocumentSnapshot(updated_doc_v2, None, True, None, None, 1) delete_changes = [] add_changes = [] update_changes = [updated_snapshot] inst = self._makeOne() updated_tree, updated_map, applied_changes = inst._compute_snapshot( doc_tree, doc_map, delete_changes, add_changes, update_changes) self.assertEqual(updated_map, doc_map) # no change
def test__compute_snapshot_operation_relative_ordering(self): from google.cloud.firestore_v1.watch import WatchDocTree doc_tree = WatchDocTree() class DummyDoc(object): update_time = mock.sentinel deleted_doc = DummyDoc() added_doc = DummyDoc() added_doc._document_path = "/added" updated_doc = DummyDoc() updated_doc._document_path = "/updated" doc_tree = doc_tree.insert(deleted_doc, None) doc_tree = doc_tree.insert(updated_doc, None) doc_map = {"/deleted": deleted_doc, "/updated": updated_doc} added_snapshot = DummyDocumentSnapshot(added_doc, None, True, None, None, None) added_snapshot.reference = added_doc updated_snapshot = DummyDocumentSnapshot(updated_doc, None, True, None, None, None) updated_snapshot.reference = updated_doc delete_changes = ["/deleted"] add_changes = [added_snapshot] update_changes = [updated_snapshot] inst = self._makeOne() updated_tree, updated_map, applied_changes = inst._compute_snapshot( doc_tree, doc_map, delete_changes, add_changes, update_changes) # TODO: Verify that the assertion here is correct. self.assertEqual(updated_map, { "/updated": updated_snapshot, "/added": added_snapshot })
def test__compute_snapshot_modify_docs_updated_doc_no_timechange(self): from google.cloud.firestore_v1.watch import WatchDocTree doc_tree = WatchDocTree() class DummyDoc(object): pass updated_doc_v1 = DummyDoc() updated_doc_v1.update_time = 1 updated_doc_v1._document_path = "/updated" updated_doc_v2 = DummyDoc() updated_doc_v2.update_time = 1 updated_doc_v2._document_path = "/updated" doc_tree = doc_tree.insert("/updated", updated_doc_v1) doc_map = {"/updated": updated_doc_v1} updated_snapshot = DummyDocumentSnapshot( updated_doc_v2, None, True, None, None, 1 ) delete_changes = [] add_changes = [] update_changes = [updated_snapshot] inst = self._makeOne() updated_tree, updated_map, applied_changes = inst._compute_snapshot( doc_tree, doc_map, delete_changes, add_changes, update_changes ) self.assertEqual(updated_map, doc_map) # no change
def test__compute_snapshot_operation_relative_ordering(self): from google.cloud.firestore_v1.watch import WatchDocTree doc_tree = WatchDocTree() class DummyDoc(object): update_time = mock.sentinel deleted_doc = DummyDoc() added_doc = DummyDoc() added_doc._document_path = "/added" updated_doc = DummyDoc() updated_doc._document_path = "/updated" doc_tree = doc_tree.insert(deleted_doc, None) doc_tree = doc_tree.insert(updated_doc, None) doc_map = {"/deleted": deleted_doc, "/updated": updated_doc} added_snapshot = DummyDocumentSnapshot(added_doc, None, True, None, None, None) added_snapshot.reference = added_doc updated_snapshot = DummyDocumentSnapshot( updated_doc, None, True, None, None, None ) updated_snapshot.reference = updated_doc delete_changes = ["/deleted"] add_changes = [added_snapshot] update_changes = [updated_snapshot] inst = self._makeOne() updated_tree, updated_map, applied_changes = inst._compute_snapshot( doc_tree, doc_map, delete_changes, add_changes, update_changes ) # TODO: Verify that the assertion here is correct. self.assertEqual( updated_map, {"/updated": updated_snapshot, "/added": added_snapshot} )
def test__reset_docs(self): from google.cloud.firestore_v1.watch import ChangeType inst = self._makeOne() inst.change_map = {None: None} from google.cloud.firestore_v1.watch import WatchDocTree doc = DummyDocumentReference("doc") doc_tree = WatchDocTree() snapshot = DummyDocumentSnapshot(doc, None, True, None, None, None) snapshot.reference = doc doc_tree = doc_tree.insert(snapshot, None) inst.doc_tree = doc_tree inst._reset_docs() self.assertEqual(inst.change_map, {"/doc": ChangeType.REMOVED}) self.assertEqual(inst.resume_token, None) self.assertFalse(inst.current)
def test_watch__reset_docs(): from google.cloud.firestore_v1.watch import ChangeType inst = _make_watch() inst.change_map = {None: None} from google.cloud.firestore_v1.watch import WatchDocTree doc = DummyDocumentReference("doc") doc_tree = WatchDocTree() snapshot = DummyDocumentSnapshot(doc, None, True, None, None, None) snapshot.reference = doc doc_tree = doc_tree.insert(snapshot, None) inst.doc_tree = doc_tree inst._reset_docs() assert inst.change_map == {"/doc": ChangeType.REMOVED} assert inst.resume_token is None assert not inst.current
def test__compute_snapshot_deletes_w_real_comparator(self): from google.cloud.firestore_v1.watch import WatchDocTree doc_tree = WatchDocTree() class DummyDoc(object): update_time = mock.sentinel deleted_doc_1 = DummyDoc() deleted_doc_2 = DummyDoc() doc_tree = doc_tree.insert(deleted_doc_1, None) doc_tree = doc_tree.insert(deleted_doc_2, None) doc_map = {"/deleted_1": deleted_doc_1, "/deleted_2": deleted_doc_2} delete_changes = ["/deleted_1", "/deleted_2"] add_changes = [] update_changes = [] inst = self._makeOne(comparator=object()) updated_tree, updated_map, applied_changes = inst._compute_snapshot( doc_tree, doc_map, delete_changes, add_changes, update_changes) self.assertEqual(updated_map, {})