Example #1
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
Example #2
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
Example #3
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
Example #4
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
Example #5
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
Example #6
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