def test_api_post_message(self): count = Message.query().count() response = self.app.post('/api/messages/', data=self.post, follow_redirects=True) self.assertEqual(response.status_code, 201) load = json.loads(response.data) self.assertEqual(load['message_id'], self.post['message_id']) self.assertEqual(Message.query().count(), count + 1)
def test_put_message(self): msg = self.add_message() count = Message.query().count() url = '/api/messages/%s/' % msg.message_id response = self.app.put(url, data=self.put, follow_redirects=True) self.assertEqual(response.status_code, 200) load = json.loads(response.data) self.assertEqual(load['message_id'], self.put['message_id']) self.assertEqual(load['message_data'], self.put['message_data']) self.assertIn('created_on', load) # nothing should change self.assertEqual(Message.query().count(), count)
def test_api_delete_message(self): msg = self.add_message() pk = msg.message_id url = '/api/messages/%s/' % pk count = Message.query().count() response = self.app.delete(url, data={}, follow_redirects=True) self.assertEqual(response.status_code, 204) key = ndb.Key('Message', pk) msg = key.get() self.assertEqual(msg, None) self.assertEqual(Message.query().count(), count - 1)