Exemplo n.º 1
0
 def get(self, user_id):
     user = AccountModel.find_by_id(user_id)
     if not user:
         return {
             'message': "User with ['id': {}] not found".format(user_id)
         }, 404
     return {
         'reviews':
         [i.json()['review'] for i in ReviewModel.find_by_user(user_id)]
     }, 200
Exemplo n.º 2
0
 def test_model_find_review_by_user(self):
     response = self.app.post(
         'api/review',
         headers={
             'Authorization':
             'Basic ' + base64.b64encode(
                 bytes(
                     str(self.acc.id) + ":" +
                     json.loads(self.resp_account_admin.data)['token'],
                     'ascii')).decode('ascii')
         },
         data={
             "user_id": 1,
             "book_id": 1,
             "title": "asd",
             "date": "25/11/2090 11:25",
             "valuation": 5,
             "comment": "lel"
         },
         follow_redirects=True)
     self.assertEqual(201, response.status_code)
     rev = ReviewModel.find_by_user(1)
     self.assertEqual("lel", rev[0].comment)