def test_create_user(self): """ TEST CREATE USER """ user = User(username='******', email='*****@*****.**', password='') user.set_password('test') user.save_user() db_user = User.query.filter_by(username='******').first() self.assertEqual(user, db_user)
def test_create_task_view(self): '''TEST CREATE TASK''' user = User(username='******', email='*****@*****.**', password='******') user.set_password('pass123') user.save_user() self.client.post('/login', data=dict(username='******', password='******'), follow_redirects=True) get_create_task_view_response = self.client.get('/task/create') self.assertEqual(get_create_task_view_response.status_code, 200) start_date = datetime.now() end_date = start_date + timedelta(minutes=10) response = self.create_task( title='create task', priority=1, description='testing create task', start_date=start_date.strftime("%Y-%m-%dT%H:%M"), # noqa: E501 end_date=end_date.strftime("%Y-%m-%dT%H:%M")) # noqa: E501 self.assertEqual(response.status_code, 200) invalid_form = self.create_task( title=None, priority=1, description='testing create task', start_date=start_date.strftime("%Y-%m-%dT%H:%M"), # noqa: E501 end_date=end_date.strftime("%Y-%m-%dT%H:%M")) # noqa: E501 self.assertEqual(invalid_form.status_code, 200)
def test_invalid_login(self): '''TEST INVALID LOGIN''' user = User(username='******', email='*****@*****.**', password='******') user.set_password('pass123') user.save_user() response = self.login('testlogin', 'pass') self.assertEqual(response.status_code, 200)
def test_get_user(self): '''TEST GET USER ''' user = User(username='******', email='*****@*****.**', password='') user.save_user() test_id = user.id url = '/user/{}'.format(test_id) response = self.client.get(url) self.assertEqual(response.data, b'{"user":{"id":1,"username":"******"}}\n')
def test_login_logout(self): '''TEST LOGIN-LOGOUT''' user = User(username='******', email='*****@*****.**', password='******') user.set_password('pass123') user.save_user() response = self.login('testlogin', 'pass123') self.assertEqual(response.status_code, 200) response = self.client.get('/logout') self.assertEqual(response.status_code, 302)
def test_delete_user(self): """ TEST DELETE USER """ user = User(username='******', email='*****@*****.**', password='') user.save_user() #user.delete_user() # removing this so that we can test our function instead path = '/user/delete/{}'.format(user.id) response = self.client.get(path, follow_redirects=True) self.assertEqual(response.status_code, 200) response = self.client.post(path, follow_redirects=True) self.assertEqual(response.status_code, 200) db_user = User.query.filter_by(username='******').first() self.assertEqual(db_user, None)
def register(): if current_user.is_authenticated: return redirect(url_for('index')) form = RegistrationForm() if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) User.save_user(user) flash('Congratulations, you are now a registered user!') return redirect(url_for('login')) return make_response( render_template('register.html', title='Register', form=form))
def test_update_task_view(self): '''TEST UPDATE TASK''' user = User(username='******', email='*****@*****.**', password='******') user.set_password('pass123') user.save_user() self.client.post('/login', data=dict(username='******', password='******'), follow_redirects=True) task = Task(title="old task", priority=1, description="old task description", start_time=datetime.now(), end_time=datetime.now()) db.session.add(task) db.session.commit() path = '/task/update/{}'.format(task.id) get_task_view_response = self.client.get(path) self.assertEqual(get_task_view_response.status_code, 200) start_date = datetime.now() end_date = start_date + timedelta(minutes=10) response = self.update_task( task_id=task.id, title='new task', priority=5, description='new task description', start_date=start_date.strftime("%Y-%m-%dT%H:%M"), # noqa: E501 end_date=end_date.strftime("%Y-%m-%dT%H:%M")) # noqa: E501 self.assertEqual(response.status_code, 200) end_date = start_date + timedelta(minutes=-10) invalid_form = self.update_task( task_id=task.id, title=None, priority=5, description='new task description', start_date=start_date.strftime("%Y-%m-%dT%H:%M"), # noqa: E501 end_date=end_date.strftime("%Y-%m-%dT%H:%M")) # noqa: E501 self.assertEqual(invalid_form.status_code, 200)
def login(self): user = User(username='******', email='*****@*****.**', password='******') user.set_password('pass123') user.save_user() #ret = [user.id] response = self.client.post('/login', data=dict(username='******', password='******'), follow_redirects=True) #ret.append(response.status_code) return [user.id, response.status_code]