예제 #1
0
    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)
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
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))
예제 #6
0
    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)
예제 #7
0
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]
예제 #8
0
 def test_password_validation(self):
     """ TEST PASSWORD CHECK """
     user = User(username='******', email='*****@*****.**', password='')
     user.set_password('test')
     self.assertFalse(user.validate_password('password'))
     self.assertTrue(user.validate_password('test'))