def test_insert(self):
     json = (
         '{"action":"create","insert":{"collection":"widget"},'
         '"params":{"object":{"data":{"object":{"name":"Laptop"}}}},"ts":123}'
     )
     self.assertJson(
         query.insert(query.collection("widget"),
                      ts=123,
                      action="create",
                      params={"data": {
                          "name": "Laptop"
                      }}), json)
Пример #2
0
    def test_insert(self):
        document = self._create(n=1)
        ref = document["ref"]
        ts = document["ts"]
        prev_ts = ts - 1

        # Add previous event
        inserted = {"data": {"n": 0}}
        self._q(query.insert(ref, prev_ts, "create", inserted))

        # Get version from previous event
        old = self._q(query.get(ref, ts=prev_ts))
        self.assertEqual(old["data"], {"n": 0})
Пример #3
0
    def test_at(self):
        document = self._create(n=1)
        ref = document["ref"]
        ts = document["ts"]
        prev_ts = ts - 1

        # Add previous event
        data = {"n": 0}
        self._q(query.insert(ref, prev_ts, "create", {"data": data}))

        # Get version from previous event
        old = self._q(query.at(prev_ts, query.get(ref)))
        self.assertEqual(old["data"], data)
Пример #4
0
    def post(self, *args, **kwargs):
        title = self.get_argument('subject')
        suggester = self.get_argument('suggester')
        resource = self.get_argument('resources')
        token = ''.join(random.choice('1234567890') for i in range(18))
        hashed = md5(title.encode('utf-8')).hexdigest()

        client.query(
            q.insert(
                q.ref(q.collection('Subjects'), token), 1, 'create', {
                    'data': {
                        'title': title,
                        'suggester': suggester,
                        'hash': hashed,
                        'resource': resource,
                        'confirmed': 'False'
                    }
                }))

        self.write(hashed)