Esempio n. 1
0
    def testEdit(self):
        ins = RestWidget(
            name='test widget',
            datetime=datetime.datetime.utcnow(),
            ref=ndb.Key('Random', 1))

        ins.put()

        ins.name = 'Updated name'
        ins.datetime += datetime.timedelta(days=60)
        ins.ref = ndb.Key('Random', 2)

        json_ins = json.dumps(ins, cls=DatastoreEncoder)

        r = self.testapp.put('/api/rest_widgets/:%s' % ins.key.urlsafe(), json_ins,
            headers={'Content-Type': 'application/json'})

        remote_ins = json.loads(r.body, cls=DatastoreDecoder)

        self.assertEqual(remote_ins.name, ins.name)
        self.assertEqual(remote_ins.ref, ins.ref)
        self.assertEqual(remote_ins.datetime.utctimetuple(), ins.datetime.utctimetuple())
Esempio n. 2
0
    def testAdd(self):
        ins = RestWidget(
            name='test widget',
            datetime=datetime.datetime.utcnow(),
            ref=ndb.Key('Random', 1))

        json_ins = json.dumps(ins, cls=DatastoreEncoder)

        r = self.testapp.post('/api/rest_widgets', json_ins,
            headers={'Content-Type': 'application/json'})

        remote_ins = json.loads(r.body, cls=DatastoreDecoder)
        self.assertEqual(remote_ins.name, ins.name)
        self.assertEqual(remote_ins.ref, ins.ref)
        self.assertEqual(remote_ins.datetime.utctimetuple(), ins.datetime.utctimetuple())
Esempio n. 3
0
    def testEdit(self):
        item = Person.query().get()
        data = json.dumps({'title': 'Captain Jack'})

        response = self.testapp.put('/api/people/:%s' % item.key.urlsafe(),
                                    data,
                                    content_type='application/json')

        assert response.content_type == 'application/json'
        data = json.loads(response.body)

        new_item = ndb.Key(urlsafe=data['key']['urlsafe']).get()

        assert new_item
        assert new_item.key == item.key
        assert new_item.content == item.content
        assert new_item.title == 'Captain Jack'
Esempio n. 4
0
    def testAdd(self):
        data = json.dumps({'title': 'Dalek', 'content': 'Exterminate!'})

        response = self.testapp.post('/api/people',
                                     data,
                                     content_type='application/json')

        assert response.content_type == 'application/json'
        data = json.loads(response.body)

        assert data['title'] == 'Dalek'

        item = ndb.Key(urlsafe=data['key']['urlsafe']).get()

        assert item
        assert item.title == data['title']
        assert item.content == data['content']