示例#1
0
 def post(self, username):
     # get the json from the request, it's already validated
     req_json = request.get_json(force=True)
     # validate the request data given a schema for the entity
     err = validate(req_json, self.schema)
     # if it could not be validated, return why
     if err:
         return jsonify(message=err), 400
     # if everything went smootly, create the new entity
     UserViewMapper.to_model_from_json(req_json)
     # indicate success
     return jsonify(message=strings.API_SUCCESS), 200
示例#2
0
 def post(self, username):
     # get the json from the request, it's already validated
     req_json = request.get_json(force=True)
     # validate the request data given a schema for the entity
     err = validate(req_json, self.schema)
     # if it could not be validated, return why
     if err:
         return jsonify(message=err), 400
     # if everything went smootly, create the new entity
     UserViewMapper.to_model_from_json(req_json)
     # indicate success
     return jsonify(message=strings.API_SUCCESS), 200
示例#3
0
 def test_non_required_output(self):
     js = {
         'username': '******',
         'password': '******',
     }
     model = UserViewMapper.to_model_from_json(js)
     assert model.username == 'username'
     assert model.password == 'password'
     assert model.is_admin is False
示例#4
0
 def test_non_required_output(self):
     js = {
         'username': '******',
         'password': '******',
     }
     model = UserViewMapper.to_model_from_json(js)
     assert model.username == 'username'
     assert model.password == 'password'
     assert model.is_admin is False
示例#5
0
 def test_non_required_output(self):
     user = User(
         username='******',
         password='******',
         salt='salt',
         is_admin=False,
     )
     js = UserViewMapper.to_json_from_model(user)
     assert js['username'] == 'username'
     assert js['first_name'] is None
     assert js['last_name'] is None
     assert js['institution'] is None
     assert js['email'] is None
     assert js['is_admin'] is False
     assert 'password' not in js
     assert 'salt' not in js
示例#6
0
 def test_non_required_output(self):
     user = User(
         username='******',
         password='******',
         salt='salt',
         is_admin=False,
     )
     js = UserViewMapper.to_json_from_model(user)
     assert js['username'] == 'username'
     assert js['first_name'] is None
     assert js['last_name'] is None
     assert js['institution'] is None
     assert js['email'] is None
     assert js['is_admin'] is False
     assert 'password' not in js
     assert 'salt' not in js
示例#7
0
 def test_correct_model_output(self):
     js = {
         'username': '******',
         'password': '******',
         'first_name': 'first',
         'last_name': 'last',
         'institution': 'university',
         'email': '*****@*****.**',
         'is_admin': False,
     }
     model = UserViewMapper.to_model_from_json(js)
     assert model.username == 'username'
     assert model.password == 'password'
     assert model.first_name == 'first'
     assert model.last_name == 'last'
     assert model.institution == 'university'
     assert model.email == '*****@*****.**'
     assert model.is_admin is False
示例#8
0
 def test_correct_model_output(self):
     js = {
         'username': '******',
         'password': '******',
         'first_name': 'first',
         'last_name': 'last',
         'institution': 'university',
         'email': '*****@*****.**',
         'is_admin': False,
     }
     model = UserViewMapper.to_model_from_json(js)
     assert model.username == 'username'
     assert model.password == 'password'
     assert model.first_name == 'first'
     assert model.last_name == 'last'
     assert model.institution == 'university'
     assert model.email == '*****@*****.**'
     assert model.is_admin is False
示例#9
0
 def test_correct_json_output(self):
     user = User(
         username='******',
         password='******',
         salt='salt',
         first_name='first',
         last_name='last',
         institution='university',
         email='*****@*****.**',
         is_admin=False,
     )
     js = UserViewMapper.to_json_from_model(user)
     assert js['username'] == 'username'
     assert js['first_name'] == 'first'
     assert js['last_name'] == 'last'
     assert js['institution'] == 'university'
     assert js['email'] == '*****@*****.**'
     assert js['is_admin'] is False
     assert 'password' not in js
     assert 'salt' not in js
示例#10
0
 def get(self, username):
     if not username:
         return jsonify(message=strings.USER_NO_USERNAME), 400
     # try and get the object from the database
     try:
         user = UserService.get_user(username)
     # if we get more than one, something is horribly wrong
     except User.MultipleObjectsReturned:
         res = jsonify(message=strings.ENTITY_MULTIPLE_RESULTS)
         res.status_code = 500
     # if it doesn't exist, inform the user
     except User.DoesNotExist:
         res = jsonify(message=strings.ENTITY_NOT_FOUND)
         res.status_code = 404
         return res
     # return the object
     json = UserViewMapper.to_json_from_model(user)
     res = jsonify(json)
     res.status_code = 200
     return res
示例#11
0
 def test_correct_json_output(self):
     user = User(
         username='******',
         password='******',
         salt='salt',
         first_name='first',
         last_name='last',
         institution='university',
         email='*****@*****.**',
         is_admin=False,
     )
     js = UserViewMapper.to_json_from_model(user)
     assert js['username'] == 'username'
     assert js['first_name'] == 'first'
     assert js['last_name'] == 'last'
     assert js['institution'] == 'university'
     assert js['email'] == '*****@*****.**'
     assert js['is_admin'] is False
     assert 'password' not in js
     assert 'salt' not in js
示例#12
0
 def get(self, username):
     if not username:
         return jsonify(message=strings.USER_NO_USERNAME), 400
     # try and get the object from the database
     try:
         user = UserService.get_user(username)
     # if we get more than one, something is horribly wrong
     except User.MultipleObjectsReturned:
         res = jsonify(message=strings.ENTITY_MULTIPLE_RESULTS)
         res.status_code = 500
     # if it doesn't exist, inform the user
     except User.DoesNotExist:
         res = jsonify(message=strings.ENTITY_NOT_FOUND)
         res.status_code = 404
         return res
     # return the object
     json = UserViewMapper.to_json_from_model(user)
     res = jsonify(json)
     res.status_code = 200
     return res