示例#1
0
    def _makeOne(
        self,
        document_reference=None,
        firestore=None,
        target=None,
        comparator=None,
        snapshot_callback=None,
        snapshot_class=None,
        reference_class=None,
    ):  # pragma: NO COVER
        from google.cloud.firestore_v1.watch import Watch

        if document_reference is None:
            document_reference = DummyDocumentReference()
        if firestore is None:
            firestore = DummyFirestore()
        if target is None:
            WATCH_TARGET_ID = 0x5079  # "Py"
            target = {
                "documents": {
                    "documents": ["/"]
                },
                "target_id": WATCH_TARGET_ID
            }
        if comparator is None:
            comparator = self._document_watch_comparator
        if snapshot_callback is None:
            snapshot_callback = self._snapshot_callback
        if snapshot_class is None:
            snapshot_class = DummyDocumentSnapshot
        if reference_class is None:
            reference_class = DummyDocumentReference
        inst = Watch(
            document_reference,
            firestore,
            target,
            comparator,
            snapshot_callback,
            snapshot_class,
            reference_class,
            BackgroundConsumer=DummyBackgroundConsumer,
            ResumableBidiRpc=DummyRpc,
        )
        return inst
示例#2
0
def _make_watch_no_mocks(
    snapshots=None,
    comparator=_document_watch_comparator,
):
    from google.cloud.firestore_v1.watch import Watch

    WATCH_TARGET_ID = 0x5079  # "Py"
    target = {"documents": {"documents": ["/"]}, "target_id": WATCH_TARGET_ID}

    if snapshots is None:
        snapshots = []

    def snapshot_callback(*args):
        snapshots.append(args)

    return Watch(
        document_reference=DummyDocumentReference(),
        firestore=DummyFirestore(),
        target=target,
        comparator=comparator,
        snapshot_callback=snapshot_callback,
        document_snapshot_cls=DummyDocumentSnapshot,
    )