Exemple #1
0
    def test_build_round_trip_more_unicode(self):
        bano = "baño"
        chinese_characters = "殷周金文集成引得"
        query = self._bundled_query_helper(data=[{
            "bano": bano
        }, {
            "international":
            chinese_characters
        }], )
        bundle = FirestoreBundle("test")
        bundle.add_named_query("asdf", query)
        serialized = bundle.build()
        reserialized_bundle = _helpers.deserialize_bundle(
            serialized, query._client)

        self.assertEqual(
            bundle.documents[
                "projects/project-project/databases/(default)/documents/col/doc-1"]
            .snapshot._data["bano"],
            bano,
        )
        self.assertEqual(
            bundle.documents[
                "projects/project-project/databases/(default)/documents/col/doc-2"]
            .snapshot._data["international"],
            chinese_characters,
        )
        self.assertEqual(
            serialized,
            reserialized_bundle.build(),
        )
    def test_build_round_trip_more_unicode(self):
        from google.cloud.firestore_bundle import FirestoreBundle
        from google.cloud.firestore_v1 import _helpers

        bano = "baño"
        chinese_characters = "殷周金文集成引得"
        query = self._bundled_query_helper(data=[{
            "bano": bano
        }, {
            "international":
            chinese_characters
        }], )
        bundle = FirestoreBundle("test")
        bundle.add_named_query("asdf", query)
        serialized = bundle.build()
        reserialized_bundle = _helpers.deserialize_bundle(
            serialized, query._client)

        assert (bundle.documents[
            "projects/project-project/databases/(default)/documents/col/doc-1"]
                .snapshot._data["bano"] == bano)
        assert (bundle.documents[
            "projects/project-project/databases/(default)/documents/col/doc-2"]
                .snapshot._data["international"] == chinese_characters)
        assert serialized == reserialized_bundle.build()
Exemple #3
0
    def test_build_round_trip_emojis(self):
        smile = "😂"
        mermaid = "🧜🏿‍♀️"
        query = self._bundled_query_helper(data=[{
            "smile": smile
        }, {
            "compound": mermaid
        }], )
        bundle = FirestoreBundle("test")
        bundle.add_named_query("asdf", query)
        serialized = bundle.build()
        reserialized_bundle = _helpers.deserialize_bundle(
            serialized, query._client)

        self.assertEqual(
            bundle.documents[
                "projects/project-project/databases/(default)/documents/col/doc-1"]
            .snapshot._data["smile"],
            smile,
        )
        self.assertEqual(
            bundle.documents[
                "projects/project-project/databases/(default)/documents/col/doc-2"]
            .snapshot._data["compound"],
            mermaid,
        )
        self.assertEqual(
            serialized,
            reserialized_bundle.build(),
        )
Exemple #4
0
 def test_build_round_trip(self):
     query = self._bundled_query_helper()
     bundle = FirestoreBundle("test")
     bundle.add_named_query("asdf", query)
     serialized = bundle.build()
     self.assertEqual(
         serialized,
         _helpers.deserialize_bundle(serialized, query._client).build(),
     )
Exemple #5
0
 def test_deserialized_bundle_cached_metadata(self):
     query = self._bundled_query_helper()
     bundle = FirestoreBundle("test")
     bundle.add_named_query("asdf", query)
     bundle_copy = _helpers.deserialize_bundle(bundle.build(),
                                               query._client)
     self.assertIsInstance(bundle_copy, FirestoreBundle)
     self.assertIsNotNone(bundle_copy._deserialized_metadata)
     bundle_copy.add_named_query("second query", query)
     self.assertIsNone(bundle_copy._deserialized_metadata)
    def test_build_round_trip(self):
        from google.cloud.firestore_bundle import FirestoreBundle
        from google.cloud.firestore_v1 import _helpers

        query = self._bundled_query_helper()
        bundle = FirestoreBundle("test")
        bundle.add_named_query("asdf", query)
        serialized = bundle.build()
        assert (serialized == _helpers.deserialize_bundle(
            serialized, query._client).build())
    def test_deserialized_bundle_cached_metadata(self):
        from google.cloud.firestore_bundle import FirestoreBundle
        from google.cloud.firestore_v1 import _helpers

        query = self._bundled_query_helper()
        bundle = FirestoreBundle("test")
        bundle.add_named_query("asdf", query)
        bundle_copy = _helpers.deserialize_bundle(bundle.build(),
                                                  query._client)
        assert isinstance(bundle_copy, FirestoreBundle)
        assert bundle_copy._deserialized_metadata is not None
        bundle_copy.add_named_query("second query", query)
        assert bundle_copy._deserialized_metadata is None
Exemple #8
0
 def test_roundtrip_binary_data(self):
     query = self._bundled_query_helper(data=[{"binary_data": b"\x0f"}], )
     bundle = FirestoreBundle("test")
     bundle.add_named_query("asdf", query)
     serialized = bundle.build()
     reserialized_bundle = _helpers.deserialize_bundle(
         serialized, query._client)
     gen = _helpers._get_documents_from_bundle(reserialized_bundle)
     snapshot = next(gen)
     self.assertEqual(
         int.from_bytes(snapshot._data["binary_data"],
                        byteorder=sys.byteorder),
         15,
     )
    def test_roundtrip_binary_data(self):
        import sys
        from google.cloud.firestore_bundle import FirestoreBundle
        from google.cloud.firestore_v1 import _helpers

        query = self._bundled_query_helper(data=[{"binary_data": b"\x0f"}], )
        bundle = FirestoreBundle("test")
        bundle.add_named_query("asdf", query)
        serialized = bundle.build()
        reserialized_bundle = _helpers.deserialize_bundle(
            serialized, query._client)
        gen = _helpers._get_documents_from_bundle(reserialized_bundle)
        snapshot = next(gen)
        assert (int.from_bytes(snapshot._data["binary_data"],
                               byteorder=sys.byteorder) == 15)
    def test_build_round_trip_emojis(self):
        from google.cloud.firestore_bundle import FirestoreBundle
        from google.cloud.firestore_v1 import _helpers

        smile = "😂"
        mermaid = "🧜🏿‍♀️"
        query = self._bundled_query_helper(data=[{
            "smile": smile
        }, {
            "compound": mermaid
        }], )
        bundle = FirestoreBundle("test")
        bundle.add_named_query("asdf", query)
        serialized = bundle.build()
        reserialized_bundle = _helpers.deserialize_bundle(
            serialized, query._client)

        assert (bundle.documents[
            "projects/project-project/databases/(default)/documents/col/doc-1"]
                .snapshot._data["smile"] == smile)
        assert (bundle.documents[
            "projects/project-project/databases/(default)/documents/col/doc-2"]
                .snapshot._data["compound"] == mermaid)
        assert serialized == reserialized_bundle.build()
Exemple #11
0
 def test_bundle_build(self):
     bundle = FirestoreBundle("test")
     bundle.add_named_query("best name", self._bundled_query_helper())
     self.assertIsInstance(bundle.build(), str)
    def test_bundle_build(self):
        from google.cloud.firestore_bundle import FirestoreBundle

        bundle = FirestoreBundle("test")
        bundle.add_named_query("best name", self._bundled_query_helper())
        assert isinstance(bundle.build(), str)