def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create normal user for tests.
        self.user = Users(id="testuser")
        self.user.first_name = "Test1"
        self.user.last_name = "User"
        self.user.email = "*****@*****.**"
        self.user.is_admin = False
        db.session.add(self.user)
        db.session.commit()
        self.user_token = self.user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create admin user for tests.
        self.admin_user = Users(id="adminuser")
        self.admin_user.first_name = "Admin"
        self.admin_user.last_name = "User"
        self.admin_user.email = "*****@*****.**"
        self.admin_user.is_admin = True
        db.session.add(self.admin_user)
        db.session.commit()
        self.admin_user_token = self.admin_user.generate_auth()
        self.admin_user_token = self.admin_user_token.decode('ascii')
Beispiel #2
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id = "adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id = "testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user for tests.
        user2 = Users(id = "testuser2")
        user2.first_name = "Test"
        user2.last_name = "User"
        user2.email = "*****@*****.**"
        user2.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user2 = user2
        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')

        # Create a test committee.
        committee = Committees(id = "testcommittee")
        committee.title = "Test Committee"
        committee.description = "Test Description"
        committee.location = "Test Location"
        committee.meeting_time = "1300"
        committee.meeting_day =  2
        committee.head = "testuser"
        self.committee = committee
        db.session.add(committee)
        db.session.commit()

        committee_note = CommitteeNotes(id = 10)
        committee_note.author = "testuser"
        committee_note.description = "Test Note"
        committee_note.committee = "testcommittee"
        committee_note.hidden = False
        self.committee_note = committee_note
        db.session.add(self.committee_note)
        db.session.commit()
    def setup_method(self, method):
        db.drop_all()
        db.create_all()
        self.user_data = {
            "user_id": "testuser",
            "committee_id": "testcommittee"
        }

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')
        self.user = user

        # Create second normal user for tests.
        user2 = Users(id="testuser2")
        user2.first_name = "Test2"
        user2.last_name = "User2"
        db.session.add(user2)
        db.session.commit()

        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')
        self.user2 = user2

        # Create a test committee.
        self.committee = Committees(id="testcommittee")
        self.committee.title = "Test Committee"
        self.committee.description = "Test Description"
        self.committee.location = "Test Location"
        self.committee.meeting_time = "1300"
        self.committee.meeting_day = 2
        self.committee.head = "adminuser"
        db.session.add(self.committee)
        db.session.commit()

        self.invite = Invitations(id=5)
        self.invite.user_name = "newuser1"
        self.invite.committee = self.committee
        self.invite.committee_id = "testcommittee"
        self.invite.isInvite = False
Beispiel #4
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        self.test_committee_dict = {
            "id": "testcommittee",
            "title": "testcommittee",
            "description": "Test Description",
            "location": "Test Location",
            "meeting_time": "1300",
            "meeting_day": 2,
            "head": "testuser",
            "committee_img":
            "R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
        }
        self.test_committee = Committees(id="testcommittee")
        self.test_committee.title = self.test_committee_dict["title"]
        self.test_committee.location = self.test_committee_dict["location"]
        self.test_committee.description = self.test_committee_dict[
            "description"]
        self.test_committee.meeting_time = self.test_committee_dict[
            "meeting_time"]
        self.test_committee.meeting_day = self.test_committee_dict[
            "meeting_day"]
        self.test_committee.head = self.test_committee_dict["head"]
        com_img = base64.b64decode(self.test_committee_dict["committee_img"])
        self.test_committee.com_image = com_img

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')
Beispiel #5
0
    def setup(self):
        db.create_all()
        db.session.add(
            Users(id=1,
                  username="******",
                  password="******",
                  email="*****@*****.**"))
        db.session.add(Role(id=1, name="admin"))
        db.session.add(UserRoles(id=1, user_id=1, role_id=1))
        db.session.add(Profile(id=1, avatar="jeff.jpg", user_id=1))
        db.session.add(
            Users(id=2,
                  username="******",
                  password="******",
                  email="*****@*****.**"))
        db.session.add(Role(id=2, name="player"))
        db.session.add(UserRoles(id=2, user_id=2, role_id=2))
        db.session.add(Profile(id=2, avatar="finn.jpg", user_id=2))
        db.session.commit()

        db.session.add(
            AwayTeamBet(id=1,
                        game_key=123,
                        bet_key=123,
                        away_team="BUF",
                        vs="BUF vs @NE",
                        away_ps=1,
                        amount=20,
                        user_id=1))
        db.session.add(
            HomeTeamBet(id=1,
                        game_key=123,
                        bet_key=123,
                        home_team="NE",
                        vs="BUF vs @NE",
                        home_ps=-1,
                        amount=20,
                        user_id=2))
        db.session.add(
            OverUnder(id=1,
                      game_key=123,
                      bet_key=123,
                      over_under="o",
                      total=40,
                      amount=20,
                      vs="BUF vs @NE",
                      user_id=1))
        db.session.commit()
 def create_object(self, user_data: dict):
     try:
         user = Users(**user_data)
         self.db.session.add(user)
     except (IntegrityError, FlushError):
         raise Exception(f'User {user.email} already exists')
     self.db.session.commit()
Beispiel #7
0
 def setUp(self):
     db.create_all()
     db.session.add(
         Users(username="******",
               email="*****@*****.**",
               password='******'))
     db.session.commit()
Beispiel #8
0
def registeruser():
    """ Build the view used to add new accounts """
    form = RegisterForm()

    if form.validate_on_submit():
        try:
            user = Users(username=form.username.data,
                         email=form.email.data,
                         specialties=form.specialties.data.split(','),
                         interests=form.interests.data.split(','))
            user.password = form.password.data
            user.save()
            token = user.generate_confirmation_token()
            send_email(user.email,
                       'Confirmare email',
                       'users/email/confirm',
                       user=user,
                       token=token)
            flash(
                'Contul a fost adaugat! Va rugam confirmati adresa de email!',
                category='alert-success')
        except Exception as err:
            flash('Contul nu poate fi creat!', category='alert-warning')
        return redirect(url_for('users.login'))

    return render_template('users/login.html',
                           pagetitle='Inregistrare',
                           form=form,
                           login=False)
Beispiel #9
0
    def post(self):
        raw_dict = request.get_json(force=True)
        try:
            schema.validate(raw_dict)
            request_dict = raw_dict['data']['attributes']
            payload = parse_token(request)
            logged_user = Users.query.get(payload['sub'])
            createdby = logged_user.name
            updatedby = logged_user.name
            password = generate_password_hash(request_dict['password'])

            user = Users(
                request_dict['email'],
                password,
                request_dict['name'],
                createdby,
                updatedby,
            )
            user.add(user)
            # Should not return password hash
            query = Users.query.get(user.id)
            results = schema.dump(query).data
            return results, 201

        except ValidationError as err:
            resp = jsonify({"error": err.messages})
            resp.status_code = 403
            return resp

        except SQLAlchemyError as e:
            db.session.rollback()
            resp = jsonify({"error": str(e)})
            resp.status_code = 403
            return resp
def login_from_acs(acs):
    
    if acs.get('errors'):
        return jsonify({'errors': acs.get('errors')})
    elif not acs.get('logged_in'):
        return jsonify({"error": "login failed"})
    else:
        attributes = list(acs.get("attributes"))
        username = attributes[0][1][0]
        firstname = attributes[1][1][0]
        lastname = attributes[2][1][0]
        email = attributes[3][1][0]

        user = Users.query.filter_by(id = username).first()

        if user is None:
            user = Users(id = username)
            user.first_name = firstname
            user.last_name = lastname
            user.email = email

            db.session.add(user)
            db.session.commit()
        
        login_user(user)
        return redirect('/')
Beispiel #11
0
    def post(self):
        raw_dict = request.get_json(force=True)
        try:
            schema.validate(raw_dict)
            request_dict = raw_dict['data']['attributes']
            role = None
            active = 0
            user = Users(request_dict['email'],
                         generate_password_hash(request_dict['password']),
                         request_dict['name'], active, role)
            user.add(user)
            # Should not return password hash
            query = Users.query.get(user.id)
            results = schema.dump(query).data
            return results, 201

        except ValidationError as err:
            resp = jsonify({"error": err.messages})
            resp.status_code = 403
            return resp

        except SQLAlchemyError as e:
            db.session.rollback()
            resp = jsonify({"error": str(e)})
            resp.status_code = 403
            return resp
Beispiel #12
0
def adduser():
    """ Build the view used to add new accounts """
    form = RegisterForm()

    if form.validate_on_submit():
        try:
            user = Users(username=form.username.data,
                         email=form.email.data,
                         specialties=form.specialties.data.split(','),
                         interests=form.interests.data.split(','))
            user.password = form.password.data
            user.save()
            token = user.generate_confirmation_token()
            send_email(user.email,
                       'Confirmare email',
                       'users/email/confirm',
                       user=user,
                       token=token)
            flash('Contul a fost adaugat!', category='alert-success')
        except Exception as err:
            flash('Utilizatorul are deja cont!', category='alert-warning')
        return redirect(url_for('users.list'))

    return render_template('users/add.html',
                           pagetitle='Adauga utilizator',
                           form=form)
def test_add():
    crud = CRUD()
    try:
        users = Users('test', 'test', 'test')
        result = crud.add(users, USERS_SCHEMA)
    except Exception as err:
        print(err)
    assert True
Beispiel #14
0
def login_ldap(credentials):

    ldap_server = "ldaps://ldap.rit.edu"

    if credentials.get("username", "") == "" or credentials.get(
            "password", "") == "":

        emit('auth', {'error': "Authentication error."})
        return

    user_dn = "uid=" + credentials.get("username",
                                       "") + ",ou=People,dc=rit,dc=edu"
    search_filter = "uid=" + credentials.get("username", "")
    connect = ldap.initialize(ldap_server)

    try:

        connect.bind_s(user_dn, credentials.get("password", ""))
        result = connect.search_s(user_dn, ldap.SCOPE_SUBTREE, search_filter)
        connect.unbind_s()

        values = result[0][1]
        username = values["uid"][0].decode('utf-8')
        firstname = values["givenName"][0].decode('utf-8')
        lastname = values["sn"][0].decode('utf-8')
        email = values["mail"][0].decode('utf-8')

        # Check if a user exists.
        if Users.query.filter_by(id=username).first() is not None:

            user = Users.query.filter_by(id=username).first()
            token = user.generate_auth()
            admin = user.is_admin
            emit(
                'auth', {
                    'token': token.decode('ascii'),
                    'admin': admin,
                    'super': user.is_super,
                    'username': username
                })

        else:

            user = Users(id=username)
            user.first_name = firstname
            user.last_name = lastname
            user.email = email

            db.session.add(user)
            db.session.commit()
            token = user.generate_auth()
            emit('auth', {'token': token.decode('ascii')})

    except ldap.LDAPError:
        connect.unbind_s()
        emit('auth', Response.AuthError)
        return
Beispiel #15
0
def create_admins(admin):

    from app.users.models import Users
    
    try:
        user = Users.objects(email=admin['email']).get()
    except:
        user = Users(email=admin['email'],username=admin['username'],permissions='full',status=True)
        user.password = admin['password']
        user.save()
Beispiel #16
0
 def test_confirm_token_route_expired_token(self):
     # Ensure user cannot confirm account with expired token.
     user = Users(username="******",
                  email='*****@*****.**',
                  password='******',
                  confirmed=False)
     db.session.add(user)
     db.session.commit()
     token = generate_confirmation_token('*****@*****.**')
     self.assertFalse(confirm_token(token, -1))
Beispiel #17
0
def signup():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    form = SignupForm()
    if form.validate_on_submit():
        new_user = Users(form.username.data, form.name.data, form.email.data,
                         form.password.data)
        db.session.add(new_user)
        db.session.commit()
        flash('Signup in successfully.', category='success')
        return redirect(url_for('users.login'))
    return render_template('signup.html', form=form)
Beispiel #18
0
    def post(self):
        raw_dict = request.get_json(force=True)
        try:
            schema.validate(raw_dict)
            request_dict = raw_dict['data']['attributes']
            role = None
            active = 0
            classified = 0
            in_queue = 0

            #Check for existing entry
            userCheck = Users.query.filter_by(
                email=request_dict['email']).first()
            if userCheck is None:

                user = Users(request_dict['email'],
                             generate_password_hash(request_dict['password']),
                             request_dict['name'], active, role, classified,
                             in_queue)
                user.add(user)
                query = Users.query.get(user.id)
                # Should not return password hash
                query.password = "******"
                results = schema.dump(query).data
                fp = os.getcwd()
                fp = fp.rsplit('/', 1)[0]  # go back one dir
                direct = fp + "/GT_USERS/USER_" + str(query.id)
                if not os.path.exists(direct):
                    os.makedirs(direct)
                    os.makedirs(direct + "/cropped")
                    os.makedirs(direct + "/images")
                    os.makedirs(direct + "/json")
                    os.makedirs(direct + "/labelled")
                    os.makedirs(direct + "/packaged")
                    os.makedirs(direct + "/segmented")
                return results, 201

            else:
                resp = jsonify({"error": "Email already taken"})
                resp.status_code = 403
                return resp

        except ValidationError as err:
            resp = jsonify({"error": err.messages})
            resp.status_code = 403
            return resp

        except SQLAlchemyError as e:
            db.session.rollback()
            resp = jsonify({"error": str(e)})
            resp.status_code = 403
            return resp
Beispiel #19
0
def api_create_user():
    data = request.args.to_dict(flat=True)
    hashed_password = generate_password_hash(data['password'], method='sha256')
    try:
        new_user = Users(public_id=str(uuid.uuid4()),
                         name=data['name'],
                         password=hashed_password,)
        new_user.id_role = 3
        session.add(new_user)
        session.commit()
        return jsonify({'message': None, 'data': None, 'status': 'success'}), 201
    except Exception as e:
        session.rollback()
        return jsonify({'message': 'Unexpected error', 'data': None, 'status': 'error'}), 400
Beispiel #20
0
def user_add():
    if request.method == 'POST':
        #Validate form values by de-serializing the request, http://marshmallow.readthedocs.org/en/latest/quickstart.html#validation
        form_errors = schema.validate(request.form.to_dict())
        if not form_errors:
            name = request.form['name']
            email = request.form['email']
            user = Users(email, name)
            return add(user,
                       success_url='users.user_index',
                       fail_url='users.user_add')
        else:
            flash(form_errors)

    return render_template('/users/add.html')
def register():
    """
	Registration page
	"""
    page = {'page': 'Register', 'error': ''}

    if request.method != 'POST':
        return render_template('front/register.html', page=page)

    form_data = request.form

    user_data = {
        'username': form_data['username'],
        'email': form_data['email'],
        'password': form_data['password']
    }

    for key, value in user_data.items():
        if value == '':
            page['error'] = 'All fields must be filled'
            return render_template('front/register.html', page=page)

    check_username = Users.query.filter_by(
        username=user_data['username']).count()
    check_email = Users.query.filter_by(email=user_data['email']).count()

    if check_email > 0:
        page['error'] = 'An account with this email already exists'

    if check_username > 0:
        page['error'] = 'This username already exists'

    if not page['error']:
        user_data['password'] = pbkdf2_sha256.encrypt(user_data['password'],
                                                      rounds=200000,
                                                      salt_size=16)
        user = Users(**user_data)
        db.session.add(user)
        db.session.commit()
        session['user_id'] = user.id
        flash('Thanks for registering')
        return redirect(url_for('.index'))
    print(page)
    return render_template('front/register.html', page=page)
Beispiel #22
0
def user_add():
    if request.method == 'POST':
        #http://marshmallow.readthedocs.org/en/latest/quickstart.html#validation
        form_errors = schema.validate(request.form.to_dict())
        if not form_errors:
            name=request.form['name']
            email=request.form['email'].lower()
            password=generate_password_hash(request.form['password'])
            is_enabled=request.form['is_enabled']
            user=Users(email, name,password, is_enabled)
            roles = request.form.getlist('role')
            for r in roles:
                role = Roles.query.filter_by(name=r).first()
                user.roles.append(role)
            return add(user, success_url = 'users.user_index', fail_url = 'users.user_add')
        else:
           flash(form_errors)

    return render_template('/users/add.html')
Beispiel #23
0
def register():
    if request.method == 'GET':
        return render_template('users/register.html')
    elif request.method == 'POST':
        name = request.form.get('name', '')
        username = request.form.get('username', '')
        email = request.form.get('email', '')
        password = pbkdf2_sha256.encrypt(request.form.get('password', ''), rounds=8000, salt_size=10)
        user = Users(name=name, username=username, email=email, password=password)
        #  TODO: Make more flexible based on the UI for this view
        if request.form.get('role', '') == "2":
            role = Roles.by_id(2)
            user.roles.append(role)
        db.session.add(user)
        db.session.commit()
        if not current_user.is_anonymous():
            return redirect(url_for('STUFF'))
        else:
            return redirect(url_for('handle_splash'))
Beispiel #24
0
    def post(self):
        raw_dict = request.get_json(force=True)
        try:
            schema.validate(raw_dict)
            user_dict = raw_dict['data']['attributes']
            user = Users(user_dict['firstname'], user_dict['lastname'],
                         user_dict['dob'], user_dict['zipcode'])
            user.add(user)
            query = Users.query.get(user.id)
            results = schema.dump(query).data
            return results, 201

        except ValidationError as err:
            resp = jsonify({"error": err.messages})
            resp.status_code = 403
            return resp

        except SQLAlchemyError as e:
            db.session.rollback()
            resp = jsonify({"error": str(e)})
            resp.status_code = 403
            return resp
Beispiel #25
0
    def post(self):
        raw_dict = request.get_json(force=True)

        try:
            schema.validate(raw_dict)
            request_dict = raw_dict['data']['attributes']
            createdby = "Self Signup"
            updatedby = "Self Signup"

            password = generate_password_hash(request_dict['password'])

            user = Users(
                request_dict['email'],
                password,
                request_dict['name'],
                createdby,
                updatedby,
            )
            user.add(user)
            # Should not return password hash
            query = Users.query.get(user.id)
            results = schema.dump(query).data
            return results, 201

        except ValidationError as err:
            print(err.messages)
            resp = jsonify({"error": err.messages})
            resp.status_code = 403
            return resp

        except SQLAlchemyError as e:

            db.session.rollback()
            resp = jsonify({"error": str(e.orig.args)})
            print(str(e))

            resp.status_code = 403
            return resp
Beispiel #26
0
def create_user():
    try:
        username = request.form['username']
        password = request.form['password']
        name = request.form['name']
        date_of_birth = request.form['date_of_birth']
        email = request.form['email']
        photo_link = request.form['photo_link']
        print(photo_link)

    except KeyError as e:
        return jsonify(success=False,
                       message="%s not sent in the request" % e.args), 400

    username = username.replace('<', '&lt')
    username = username.replace('>', '&gt')
    password = password.replace('<', '&lt')
    password = password.replace('>', '&gt')
    name = name.replace('<', '&lt')
    name = name.replace('>', '&gt')
    date_of_birth = date_of_birth.replace('<', '&lt')
    date_of_birth = date_of_birth.replace('>', '&gt')
    email = email.replace('<', '&lt')
    email = email.replace('>', '&gt')
    photo_link = photo_link.replace('<', '&lt')
    photo_link = photo_link.replace('>', '&gt')
    dob = date(int(date_of_birth[0:4]), int(date_of_birth[5:7]),
               int(date_of_birth[8:10]))
    u = Users(username, name, email, dob, photo_link, password)
    try:
        db.session.add(u)
        db.session.commit()
    except IntegrityError as e:
        return jsonify(success=False,
                       message="This username already exists"), 400

    return jsonify(success=True)
Beispiel #27
0
    def post(self):
        raw_dict = request.get_json(force=True)
        user_dict = raw_dict['data']['attributes']
        try:
            schema.validate(user_dict)
            user = Users(user_dict['name'], user_dict['email'],
                         user_dict['address'], user_dict['website'],
                         user_dict['is_active'], user_dict['mobile'],
                         user_dict['Birthday'])
            user.add(user)
            query = Users.query.get(user.id)
            results = schema.dump(query).data
            return results, 201

        except ValidationError as err:
            resp = jsonify({"error": err.messages})
            resp.status_code = 403
            return resp

        except SQLAlchemyError as e:
            db.session.rollback()
            resp = jsonify({"error": str(e)})
            resp.status_code = 403
            return resp
Beispiel #28
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user for tests.
        user2 = Users(id="testuser2")
        user2.first_name = "Test"
        user2.last_name = "User"
        user2.email = "*****@*****.**"
        user2.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user2 = user2
        self.user_token2 = user2.generate_auth()
        self.user_token2 = self.user_token2.decode('ascii')

        # Create normal user for tests.
        user3 = Users(id="activemember")
        user3.first_name = "Active"
        user3.last_name = "Member"
        user3.email = "*****@*****.**"
        user3.is_admin = False
        db.session.add(user2)
        db.session.commit()
        self.test_user3 = user3
        self.user_token3 = user3.generate_auth()
        self.user_token3 = self.user_token3.decode('ascii')

        # Create a test committee.
        committee = Committees(id="testcommittee")
        committee.title = "Test Committee"
        committee.description = "Test Description"
        committee.location = "Test Location"
        committee.meeting_time = "1300"
        committee.meeting_day = 2
        committee.head = "testuser"
        self.committee = committee

        # Create a test committee.
        committee2 = Committees(id="testcommittee2")
        committee2.title = "Test Committee2"
        committee2.description = "Test Description"
        committee2.location = "Test Location"
        committee2.meeting_time = "1300"
        committee2.meeting_day = 2
        committee2.head = "testuser"
        self.committee2 = committee2

        # Add user3 to committee.
        role = Members(role=Roles.ActiveMember)
        role.member = self.test_user3
        self.committee.members.append(role)
        db.session.add(self.committee)
        db.session.add(self.committee2)
        db.session.commit()

        self.charge_dict = {
            'id': 10,
            'title': 'Test Charge',
            'description': 'Test Description',
            'committee': 'testcommittee',
            'status': 0,
            'priority': 0,
            'private': True,
            'paw_links': "https://testlink.com"
        }

        # Create a test charge.
        charge = Charges(id=10)
        charge.author = "testuser"
        charge.title = "Test Charge"
        charge.description = "Test Description"
        charge.committee = "testcommittee"
        charge.paw_links = "https://testlink.com"
        charge.priority = 0
        charge.status = 0
        charge.private = True
        self.charge = charge

        db.session.add(charge)
        db.session.commit()
        self.charge_dict["created_at"] = self.charge.created_at.isoformat()
Beispiel #29
0
    def setup_method(self, method):
        db.drop_all()
        db.create_all()
        self.socketio = socketio.test_client(app)
        self.socketio.connect()

        db.event.remove(Committees, "after_insert", new_committee)
        db.event.remove(Actions, "after_insert", new_action)

        # Create admin user for tests.
        admin = Users(id="adminuser")
        admin.first_name = "Admin"
        admin.last_name = "User"
        admin.email = "*****@*****.**"
        admin.is_admin = True
        db.session.add(admin)
        db.session.commit()
        self.admin_token = admin.generate_auth()
        self.admin_token = self.admin_token.decode('ascii')

        # Create normal user for tests.
        user = Users(id="testuser")
        user.first_name = "Test1"
        user.last_name = "User"
        user.email = "*****@*****.**"
        user.is_admin = False
        db.session.add(user)
        db.session.commit()
        self.test_user = user
        self.user_token = user.generate_auth()
        self.user_token = self.user_token.decode('ascii')

        # Create normal user for tests.
        user_two = Users(id="testuser2")
        user_two.first_name = "Test2"
        user_two.last_name = "User"
        user_two.email = "*****@*****.**"
        user_two.is_admin = False
        db.session.add(user_two)
        db.session.commit()
        self.test_user_two = user_two
        self.user_token_two = user_two.generate_auth()
        self.user_token_two = self.user_token_two.decode('ascii')

        # Create a test committee.
        committee = Committees(id="testcommittee")
        committee.title = "Test Committee"
        committee.description = "Test Description"
        committee.location = "Test Location"
        committee.meeting_time = "1300"
        committee.meeting_day = 2
        committee.head = "testuser"
        self.committee = committee
        db.session.add(committee)
        db.session.commit()

        # Create a test charge.
        charge = Charges(id=10)
        charge.author = "testuser"
        charge.title = "Test Charge"
        charge.description = "Test Description"
        charge.committee = "testcommittee"
        charge.paw_links = "https://testlink.com"
        charge.priority = 0
        charge.status = 0
        self.charge = charge
        db.session.add(charge)
        db.session.commit()

        # Create a test action.
        action = Actions(id=10)
        action.author = admin.id
        action.title = "Test Action"
        action.description = "Test Description"
        action.charge = 10
        action.status = 0
        self.test_action = action
        db.session.add(self.test_action)
        db.session.commit()

        db.event.listen(Committees, "after_insert", new_committee)
        db.event.listen(Actions, "after_insert", new_action)

        # Test committee dictionary
        self.test_committee_dict = {
            "id": "testcommittee1",
            "title": "testcommittee1",
            "description": "Test Description",
            "location": "Test Location",
            "meeting_time": "1300",
            "meeting_day": 2,
            "head": "testuser",
            "committee_img":
            "R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
        }

        # Test action dict
        self.test_action_dict = {
            "token": self.user_token,
            "charge": 10,
            "assigned_to": "testuser",
            "title": "test title",
            "description": "test description"
        }
 def post(self):
     args_ = self.parser.parse_args()
     password = args_['user_password']
     hash_pw = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt())
     user = Users(args_['user_id'], hash_pw, args_['user_email'])
     return user.add(user, USERS_SCHEMA)