예제 #1
0
 def test_update_role(self):
     self.role1.save()
     role1 = Role.get(id=1)
     role1.update({'title': 'new_role_title'})
     self.assertEqual('new_role_title', Role.get(id=1).title)
     self.assertTrue(isinstance(role1.update({'random': 'bad field'}),
                                dict))
예제 #2
0
 def test_add_and_remove_users_from_role(self):
     self.user1.save()
     self.user2.save()
     self.role1.save()
     role1 = Role.get(id=1)
     self.assertEqual(0, len(role1.users))
     users = User.get_all()
     role1.insert('users', users)
     self.assertEqual(True, isinstance(role1.users[0], User))
     role1.remove('users', id=1)
     self.assertEqual(1, len(role1.users))
     role1.remove('users')
     self.assertEqual(0, len(role1.users))
예제 #3
0
 def post(self):
     """
     Create a new user.
     """
     payload = request.get_json()
     required = ['email', 'name', 'password', 'phone_number']
     result = validate_json(required, payload)
     if isinstance(result, bool) is True:
         new_user = User(name=payload['name'],
                         phone_number=payload['phone_number'],
                         email=payload['email'],
                         password=digest(payload['password']))
         basic_role = Role.get(title='basic')
         new_wallet = Wallet()
         new_user.insert('roles', [basic_role])
         new_user.insert('wallet', new_wallet)
         new_user_id = new_user.save()
         return {
             'status': 'success',
             'message': 'User with id {} was created.'.format(new_user_id)
         }, 201
     return {'status': 'fail', 'data': {'missing': result}}, 400
예제 #4
0
 def test_delete(self, new_user, new_role, request_ctx,
                 mock_request_obj_decoded_token):
     new_role.delete()
     assert Role.get(new_role.id) is None
예제 #5
0
 def test_get_role(self):
     self.assertEqual(True, isinstance(Role.get(id=1), dict))
     self.role1.save()
     self.assertEqual(True, isinstance(Role.get(id=1), Role))