Beispiel #1
0
 def put(self, id):
     app.logger.info(
         f'Получен запрос на редактирование регистрационных данных пациента с id = {id}'
     )
     if g.current_user.id != id:
         abort(403)
     data = request.get_json() or {}
     user = UserSchema().load(data,
                              instance=User.query.get_or_404(id),
                              partial=True)
     db.session.commit()
     return UserSchema().dump(user)
Beispiel #2
0
 def post(self):
     data = request.get_json() or {}
     if 'email' not in data or 'password' not in data:
         return 'must include email and password fields!'
     if User.query.filter_by(email=data['email']).first():
         return 'use different email!'
     data.update({"password_hash": set_password(data['password'])})
     user = UserSchema().make_instance(data, partial=False)
     app.logger.info(
         f'Получен запрос на регистрацию нового пациента с id = {user.id}')
     db.session.add(user)
     db.session.commit()
     return UserSchema().dump(user)
Beispiel #3
0
 def get(self, id):
     app.logger.info(
         f'Получен запрос на информацию о регистрационных данных пациента с id = {id}'
     )
     if g.current_user.id != id:
         abort(403)
     return UserSchema().dump(User.query.get_or_404(id))
Beispiel #4
0
 def test_exist(self):
     with app.app_context() as context:
         context.push()
         db.session.remove()
         db.drop_all()
         db.create_all()
         card1.update({"password_hash": set_password(card1['password'])})
         user = UserSchema().make_instance(card1, partial=False)
         db.session.add(user)
         db.session.commit()
         exist = User.query.get(card1["id"])
         self.assertEqual(user.id, exist.id)
         db.session.remove()
Beispiel #5
0
 def test_post_exist_user(self, mock_post):
     with app.app_context() as context:
         with app.test_request_context('/api', json=card1):
             context.push()
             db.session.remove()
             db.drop_all()
             db.create_all()
             card1.update(
                 {"password_hash": set_password(card1['password'])})
             user = UserSchema().make_instance(card1, partial=False)
             db.session.add(user)
             db.session.commit()
             mock_post.return_value = 'use different email!'
             resp = FirstResourse().post()
             self.assertEqual(resp, 'use different email!')
Beispiel #6
0
 def test_user_get_card(self, mock_get):
     with app.app_context() as context:
         with app.test_request_context(
                 '/api/users/1/card',
                 headers=dict(Authorization=f"{authent}")):
             context.push()
             db.session.remove()
             db.drop_all()
             db.create_all()
             card1.update(
                 {"password_hash": set_password(card1['password'])})
             user = UserSchema().make_instance(card1, partial=False)
             db.session.add(user)
             db.session.commit()
             mock_get.return_value = make_response(jsonify([patient1]), 200)
             resp = GateCardResourse().get(id=1)
             self.assertEqual(resp.status_code, 200)
Beispiel #7
0
 def test_post_user(self):
     with app.app_context() as context:
         with app.test_client() as client:
             context.push()
             db.session.remove()
             db.drop_all()
             db.create_all()
             card1.update(
                 {"password_hash": set_password(card1['password'])})
             user = UserSchema().make_instance(card1, partial=False)
             db.session.add(user)
             db.session.commit()
             response = client.get('/api/users/1',
                                   headers=dict(Authorization=f"{authent}"))
             self.assertEqual(response.status_code, 200)
             self.assertEqual(response.json["email"], card1["email"])
             db.session.remove()