Beispiel #1
0
 def save_page(data):
     """ Save Page """
     page = AboutPage(**data)
     db.session.add(page)
     db.session.commit()
     res = Response('Success').__dict__
     return res, 200
Beispiel #2
0
 def save_new_user(data):
     """ Save new User """
     user = User.query.filter_by(email=data['email']).first()
     if not user:
         new_user = User(public_id=str(uuid.uuid4()),
                         email=data['email'],
                         username=data['username'],
                         password=data['password'],
                         registered_on=datetime.datetime.utcnow())
         db.session.add(new_user)
         db.session.commit()
         return Response(status='Success',
                         message=USER_MSG['USER_SAVED']).__dict__, 201
     else:
         return ErrorResponse(), 409
Beispiel #3
0
 def test_basic_error_response_no_body(self):
     response_dict = {'status': 'failed', 'error': 'Unknown error', 'code': HTTPStatus.BAD_REQUEST}
     expected = (response_dict, response_dict['code'])
     response = Response(None, code=HTTPStatus.BAD_REQUEST)
     actual = response.flask
     self.assertEqual(expected, actual)
Beispiel #4
0
 def test_basic_error_response(self):
     response_dict = {'status': 'failed', 'error': 'sumthin broke', 'code': HTTPStatus.BAD_REQUEST}
     expected = (response_dict, response_dict['code'])
     response = Response('sumthin broke', code=HTTPStatus.BAD_REQUEST)
     actual = response.flask
     self.assertEqual(expected, actual)
Beispiel #5
0
 def test_basic_response_no_body(self):
     response_dict = {'status': 'ok', 'code': HTTPStatus.OK}
     expected = (response_dict, response_dict['code'])
     response = Response(None)
     actual = response.flask
     self.assertEqual(expected, actual)
Beispiel #6
0
 def test_basic_response(self):
     response_dict = {'status': 'ok', 'result': 'all good', 'code': HTTPStatus.OK}
     expected = (response_dict, response_dict['code'])
     response = Response('all good')
     actual = response.flask
     self.assertEqual(expected, actual)
Beispiel #7
0
 def get_all_users():
     """ Get all users """
     user = User.query.all()
     return Response(status='Success',
                     data=user,
                     message=USER_MSG['USER_FETCH']).__dict__, 200
Beispiel #8
0
 def get_page():
     """ Getting Page """
     raise Forbidden
     pages = AboutPage.query.all()
     res = Response('Success', data=pages, message='List of Pages').__dict__
     return res, 200