def test_user_login_fail(test_client, init_database): """ GIVEN a Flask application WHEN the '/users/login or / (index) page is posted to (POST) with INVALID creds THEN login the user """ #add a test user user = User('*****@*****.**', 'password') user.grades = '1' # a valid user needs a grade(s) db.session.add(user) db.session.commit() #try to login wtih bad password response = test_client.post('/', data=dict(email='*****@*****.**', password='******'), follow_redirects=True) assert response.status_code == 200 assert 'メールアドレスまたはパスワードが一致しません。'.encode('utf-8') in response.data #try to login wtih bad username response = test_client.post('/', data=dict(email='*****@*****.**', password='******'), follow_redirects=True) assert response.status_code == 200 assert 'メールアドレスまたはパスワードが一致しません。'.encode('utf-8') in response.data
def add(): if 'A' not in current_user.grades: flash(_('This functionality is only available to Administrators'), category='danger') return redirect(url_for('root.home')) form = AdminAddForm() if form.validate_on_submit(): new_user = User(form.email.data, form.password.data) new_user.name = form.name.data new_user.grades = form.grades.data db.session.add(new_user) db.session.commit() return redirect(url_for('users.admin_list_users')) return render_template('admin_user_add.html', form=form)
def test_user_login(test_client, init_database): """ GIVEN a Flask application WHEN the '/users/login or / (index) page is posted to (POST) with valid creds THEN login the user """ #add a test user user = User('*****@*****.**', 'password') user.grades = '1' # a valid user needs a grade(s) db.session.add(user) db.session.commit() #try to login response = test_client.post('/', data=dict(email='*****@*****.**', password='******'), follow_redirects=True) assert response.status_code == 200 assert 'ログインに成功しました。'.encode('utf-8') in response.data
def register(): form = RegistrationForm() if form.validate_on_submit(): check_user = User.query.filter_by(email=form.email.data).first() if isinstance(check_user, User): flash(_('This email address is already registered'), category='danger') return redirect(url_for('root.index')) else: user = User(email=form.email.data, password=form.password.data) db.session.add(user) db.session.commit() flash(_( 'Your account have been created. You will recieve an email once it has been validated and activated. Thank you.' ), category='warning') return redirect(url_for('root.index')) return render_template('register.html', form=form)
def existing_user(): user = User('*****@*****.**', 'password') user.grades = '1' db.session.add(user) db.session.commit()
def add_data(init_database): material_type1 = MaterialType('KJTS', 'Kanji Test', 'Instruction for Kanji Test') material_type2 = MaterialType('TRCP', 'Tracing', 'Instruction for Tracing') material_type3 = MaterialType('KJWR', 'Kanji Writing', 'Instruction for Kanji Writing') material_type4 = MaterialType('KJRD', 'Kanji Reading', 'Instruction for Kanji Reading') material_type5 = MaterialType('NWRD', 'New Reading', 'Instruction for New Reading') material_type6 = MaterialType('KT36', 'Kanji Test 3-6', 'Instruction for Kanji Test grades 3-6') user1 = User('*****@*****.**', 'password') user1.grades = '1' user2 = User('*****@*****.**', 'password') user2.grades = '2,6' user3 = User('*****@*****.**', 'password') user3.grades = '3' user4 = User('*****@*****.**', 'password') userAdmin = User('*****@*****.**', 'password') userAdmin.grades = 'A123456789' lesson11 = Lesson('Grade 1 - Lesson 1', '1') lesson12 = Lesson('Grade 1 - Lesson 2', '1') lesson21 = Lesson('Grade 2 - Lesson 1', '2') lesson22 = Lesson('Grade 2 - Lesson 2', '2') lesson61 = Lesson('Grade 6 - Lesson 1', '6') db.session.add_all([ material_type1, material_type2, material_type3, material_type4, material_type5, material_type6 ]) db.session.add_all([user1, user2, user3, user4, userAdmin]) db.session.add_all([lesson11, lesson12, lesson21, lesson22, lesson61]) db.session.commit() lesson_mat_11_1 = LessonMaterial('Lesson 1 Material 1', 'something', lesson11.id, 'KJTS') db.session.add(lesson_mat_11_1) db.session.commit()
def authenticated_request(test_client): user = User('*****@*****.**', 'password') user.grades = '1' db.session.add(user) db.session.commit()