def test_replace(self):
     json = ('{"params":{"object":{"data":{"object":{"name":"Laptop"}}}},'
             '"replace":{"collection":"widget"}}')
     self.assertJson(
         query.replace(query.collection("widget"),
                       {"data": {
                           "name": "Laptop"
                       }}), json)
Example #2
0
def update_event(event_id, data):
    try:
        client.query(
            q.replace(client.query(q.ref(q.collection("event"), event_id)),
                      {"data": data}))
        return True
    except:
        return False
Example #3
0
def update_project(project_id, data):
    try:
        client.query(
            q.replace(
                client.query(q.ref(q.collection("projects"), project_id)),
                {"data": data}))
        return True
    except:
        return False
Example #4
0
    def test_remove(self):
        document = self._create(n=0)
        ref = document["ref"]

        # Change it
        new_instance = self._q(query.replace(ref, {"data": {"n": 1}}))
        self.assertEqual(self._q(query.get(ref)), new_instance)

        # Delete that event
        self._q(query.remove(ref, new_instance["ts"], "create"))

        # Assert that it was undone
        self.assertEqual(self._q(query.get(ref)), document)
Example #5
0
 def test_replace(self):
     ref = self._create()["ref"]
     got = self._q(query.replace(ref, {"data": {"m": 1}}))
     self.assertEqual(got["data"], {"m": 1})
Example #6
0
 def replace_document(self, document: Document) -> Document:
     return self.client.query(
         q.replace(document.ref, {'data': document.as_query()})
     )