Пример #1
0
    def test_create_user(self):
        response = self.client.get('/bootstrap/')
        response = self.client.get('/user/create/')
        assert response.status_code == 200
        test_data = {
            "email": '*****@*****.**',
            "first_name": "create",
            "last_name": "test",
            "password": "******",
            "confirm": "password",
            "needs_password": True,
        }
        response = self.client.post('/user/save/',
                                    data=test_data,
                                    follow_redirects=True)
        assert response.status_code == 200
        user = PortalUser.find_by_email(test_data['email'])
        assert user
        assert user.first_name == test_data['first_name']
        assert user.last_name == test_data['last_name']

        # save with a new name, test false "needs_password" path
        test_data = {
            "email": '*****@*****.**',
            "first_name": "changed",
            "last_name": "test",
        }
        response = self.client.post('/user/save/',
                                    data=test_data,
                                    follow_redirects=True)
        assert response.status_code == 200
        user = PortalUser.find_by_email("*****@*****.**")
        assert user.first_name == "changed"

        # test error case -- first_name can't be blank
        test_data = {
            "email": '*****@*****.**',
            "first_name": "",
            "last_name": "test",
        }
        response = self.client.post('/user/save/',
                                    data=test_data,
                                    follow_redirects=True)
        assert response.status_code == 200
        user = PortalUser.find_by_email("*****@*****.**")
        assert user.first_name is not ""
Пример #2
0
    def test_user_model(self):
        user = PortalUser(email="*****@*****.**",
                          first_name="Test",
                          last_name="User")
        user.save()
        assert PortalUser.find_by_email("*****@*****.**")

        assert PortalUser.find_by_key(ObjectId()) == None
Пример #3
0
def change_password(email):
    if request.method == 'POST':
        form = PasswordForm(request.form)
        if form.validate():
            user = PortalUser.find_by_email(email)
            user.set_password(form.password.data)
            user.save()
            flash('Password changed')
            return redirect('/user/%s/' % email)
    else:
        form = PasswordForm()
    return render_template('change_password.html', form=form, email=email)
Пример #4
0
def change_password(email):
    if request.method == 'POST':
        form = PasswordForm(request.form)
        if form.validate():
            user = PortalUser.find_by_email(email)
            user.set_password(form.password.data)
            user.save()
            flash('Password changed')
            return redirect('/user/%s/' % email)
    else:
        form = PasswordForm()
    return render_template('change_password.html', form=form, email=email)
Пример #5
0
 def test_change_email(self):
     user = PortalUser(email="*****@*****.**", first_name="Test", last_name="User")
     user.set_password("password")
     user.save()
     login_data = { "email": "*****@*****.**", "password": "******"}
     response = self.client.post('/login', data=login_data, follow_redirects=True)
     test_data = { "email": '*****@*****.**',
                   "first_name": "Test",
                   "last_name": "User",
                   "id": str(user.id),
                 }
     response = self.client.post('/user/save/', data=test_data, follow_redirects=False)
     assert PortalUser.find_by_email("*****@*****.**")
     assert PortalUser.check_login("*****@*****.**", "password")
Пример #6
0
    def test_create_user(self):
        response = self.client.get('/bootstrap/')
        response = self.client.get('/user/create/')
        assert response.status_code == 200
        test_data = { "email": '*****@*****.**',
                      "first_name": "create",
                      "last_name": "test",
                      "password": "******",
                      "confirm": "password",
                      "needs_password": True,
                    }
        response = self.client.post('/user/save/', data=test_data, follow_redirects=True)
        assert response.status_code == 200
        user = PortalUser.find_by_email(test_data['email'])
        assert user
        assert user.first_name == test_data['first_name']
        assert user.last_name == test_data['last_name']

        # save with a new name, test false "needs_password" path
        test_data = { "email": '*****@*****.**',
                      "first_name": "changed",
                      "last_name": "test",
                    }
        response = self.client.post('/user/save/', data=test_data, follow_redirects=True)
        assert response.status_code == 200
        user = PortalUser.find_by_email("*****@*****.**")
        assert user.first_name == "changed"

        # test error case -- first_name can't be blank
        test_data = { "email": '*****@*****.**',
                      "first_name": "",
                      "last_name": "test",
                    }
        response = self.client.post('/user/save/', data=test_data, follow_redirects=True)
        assert response.status_code == 200
        user = PortalUser.find_by_email("*****@*****.**")
        assert user.first_name is not ""
Пример #7
0
def save_user():
    needs_password = '******' in request.form
    if needs_password:
        form = NewUserForm(request.form)
    else:
        form = UserForm(request.form)
    if form.validate():
        email = form.email.data
        if form.id.data:
            user = PortalUser.find_by_key(form.id.data)
        else:
            user = PortalUser.find_by_email(email)
        if not user:
            user = PortalUser(email=email)
        form.populate_obj(user)
        if 'password' in request.form:
            user.set_password(form.password.data)
        user.save()
        return redirect(url_for('list_users'))
    else:
        return render_template('user_detail.html', form=form, needs_password=needs_password)
Пример #8
0
 def test_change_email(self):
     user = PortalUser(email="*****@*****.**",
                       first_name="Test",
                       last_name="User")
     user.set_password("password")
     user.save()
     login_data = {"email": "*****@*****.**", "password": "******"}
     response = self.client.post('/login',
                                 data=login_data,
                                 follow_redirects=True)
     test_data = {
         "email": '*****@*****.**',
         "first_name": "Test",
         "last_name": "User",
         "id": str(user.id),
     }
     response = self.client.post('/user/save/',
                                 data=test_data,
                                 follow_redirects=False)
     assert PortalUser.find_by_email("*****@*****.**")
     assert PortalUser.check_login("*****@*****.**", "password")
Пример #9
0
def save_user():
    needs_password = '******' in request.form
    if needs_password:
        form = NewUserForm(request.form)
    else:
        form = UserForm(request.form)
    if form.validate():
        email = form.email.data
        if form.id.data:
            user = PortalUser.find_by_key(form.id.data)
        else:
            user = PortalUser.find_by_email(email)
        if not user:
            user = PortalUser(email=email)
        form.populate_obj(user)
        if 'password' in request.form:
            user.set_password(form.password.data)
        user.save()
        return redirect(url_for('list_users'))
    else:
        return render_template('user_detail.html',
                               form=form,
                               needs_password=needs_password)
Пример #10
0
    def test_user_model(self):
        user = PortalUser(email="*****@*****.**", first_name="Test", last_name="User")
        user.save()
        assert PortalUser.find_by_email("*****@*****.**")

        assert PortalUser.find_by_key(ObjectId()) == None
Пример #11
0
def edit_user(email):
    user = PortalUser.find_by_email(email)
    form = UserForm(request.args, user)
    return render_template('user_detail.html', form=form)
Пример #12
0
def edit_user(email):
    user = PortalUser.find_by_email(email)
    form = UserForm(request.args, user)
    return render_template('user_detail.html', form=form)