Example #1
0
 def create_messages(self):
     messages = [
         Message.create(user=self.admin, content='admin'),
         Message.create(user=self.normal, content='normal'),
     ]
     self.admin_message, self.normal_message = messages
     return messages
Example #2
0
 def setUp(self):
     Note.drop_table(True)
     Message.drop_table(True)
     User.drop_table(True)
     User.create_table()
     Message.create_table()
     Note.create_table()
     
     self.flask_app = test_app.app
     self.flask_app._template_context = {}
     
     self.app = test_app.app.test_client() 
Example #3
0
 def test_delete(self):
     self.create_messages()
     
     url = '/api/message/%s/' % self.normal_message.id
     
     # authorized as an admin
     resp = self.app.delete(url, headers=self.auth_headers('normal', 'normal'))
     self.assertEqual(resp.status_code, 200)
     
     self.assertEqual(Message.select().count(), 1)
     
     resp_json = self.response_json(resp)
     self.assertEqual(resp_json, {'deleted': 1})
Example #4
0
 def test_create(self):
     message_data = {'content': 'test'}
     serialized = json.dumps(message_data)
     
     # authorized as an admin
     resp = self.app.post('/api/message/', data=serialized, headers=self.auth_headers('normal', 'normal'))
     self.assertEqual(resp.status_code, 200)
     
     new_message = Message.get(content='test')
     self.assertEqual(new_message.user, self.normal)
     
     resp_json = self.response_json(resp)
     self.assertAPIMessage(resp_json, new_message)
Example #5
0
 def test_edit(self):
     self.create_messages()
     
     message_data = {'content': 'edited'}
     serialized = json.dumps(message_data)
     
     url = '/api/message/%s/' % self.normal_message.id
     
     # authorized as normal
     resp = self.app.put(url, data=serialized, headers=self.auth_headers('normal', 'normal'))
     self.assertEqual(resp.status_code, 200)
     
     message = Message.get(id=self.normal_message.id)
     self.assertEqual(message.content, 'edited')
     
     resp_json = self.response_json(resp)
     self.assertAPIMessage(resp_json, message)
Example #6
0
 def create_message(self, user, content, **kwargs):
     return Message.create(user=user, content=content, **kwargs)