Ejemplo n.º 1
0
 def test_users_delete(self):
     """Test to delete a user"""
     with app.app_context():
         User.create('todelete', '*****@*****.**', 'password')
         db.session.commit()
     status, data = self.delete('{}/{}'.format(USERS_URL, 'todelete'))
     self.assertEqual(status, 204)
Ejemplo n.º 2
0
def create_user(username, email_addr, password, **kwargs):
    try:
        User.create(username, email_addr, password)
    except ValueError as e:
        print(e, file=sys.stderr)
        sys.exit(1)
    db.session.commit()
    print('User {} created'.format(username))
Ejemplo n.º 3
0
 def post(self):
     """
     Create a new user
     """
     args = user_create_parser.parse_args()
     try:
         user = User.create(args.username, args.email_addr, args.password)
     except ValueError as e:
         api.abort(400,
                   'Cannot create the user. More information: {}'.format(e))
     db.session.commit()
     return user, 200
Ejemplo n.º 4
0
 def setUp(self):
     self.app = app
     with self.app.app_context():
         db.drop_all()
         db.create_all()
         if os.path.isfile('./tests/app.conf'):
             self.app.config.from_pyfile('../tests/app.conf')
         # Create our test user
         user = User.create(self.app.config.get('TEST_USER'),
                            self.app.config.get('TEST_USERS_EMAIL'),
                            self.app.config.get('TEST_USERS_PASSWORD'))
         for right_name in rights:
             user.rights.append(Right.create(right_name))
         db.session.add(user)
         self._basic = b64encode('{0}:{1}'.format(
             self.app.config.get('TEST_USER'),
             self.app.config.get('TEST_USERS_PASSWORD')).encode(
                 'utf8')).decode('utf8')
         g.current_user = None
         db.session.commit()