New unittests
This commit is contained in:
parent
ce702e6178
commit
be52ca5ddf
53
migrations/versions/9643649cdb9c_.py
Normal file
53
migrations/versions/9643649cdb9c_.py
Normal file
@ -0,0 +1,53 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 9643649cdb9c
|
||||
Revises: None
|
||||
Create Date: 2016-07-20 23:52:07.223110
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '9643649cdb9c'
|
||||
down_revision = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('roles',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(length=64), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('name')
|
||||
)
|
||||
op.create_table('users',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('email', sa.String(length=128), nullable=True),
|
||||
sa.Column('username', sa.String(length=64), nullable=True),
|
||||
sa.Column('password_hash', sa.String(length=128), nullable=True),
|
||||
sa.Column('full_name', sa.String(length=255), nullable=True),
|
||||
sa.Column('avatar', sa.String(length=255), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('role_id', sa.Integer(), nullable=True),
|
||||
sa.Column('confirmed', sa.Boolean(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_users_avatar'), 'users', ['avatar'], unique=False)
|
||||
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
||||
op.create_index(op.f('ix_users_full_name'), 'users', ['full_name'], unique=False)
|
||||
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
|
||||
### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_users_username'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_full_name'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_email'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_avatar'), table_name='users')
|
||||
op.drop_table('users')
|
||||
op.drop_table('roles')
|
||||
### end Alembic commands ###
|
58
tests/test_view_functions.py
Normal file
58
tests/test_view_functions.py
Normal file
@ -0,0 +1,58 @@
|
||||
import datetime
|
||||
import unittest
|
||||
import tempfile
|
||||
import dash
|
||||
|
||||
from flask import current_app
|
||||
from flask_testing import TestCase
|
||||
from flask_login import login_user, logout_user, login_required, \
|
||||
current_user
|
||||
|
||||
from dash import create_app, db
|
||||
from dash.models import User
|
||||
|
||||
class ViewFunctionsTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.dash = create_app('testing')
|
||||
self.app_context = self.dash.app_context()
|
||||
self.app_context.push()
|
||||
self.app_test_client = self.dash.test_client()
|
||||
db.create_all()
|
||||
# create user for testing
|
||||
u = User(email="test@dash-stack.org",
|
||||
username="test",
|
||||
full_name="Dash Stack",
|
||||
password="test",
|
||||
avatar="/static/img/user2-160x160.jpg",
|
||||
created_at=datetime.datetime.now())
|
||||
db.session.add(u)
|
||||
|
||||
def tearDown(self):
|
||||
db.session.remove()
|
||||
db.drop_all()
|
||||
self.app_context.pop()
|
||||
|
||||
# user login function
|
||||
def login(self, email, password):
|
||||
return self.app_test_client.post('/auth/login',
|
||||
data=dict(
|
||||
email=email,
|
||||
password=password), follow_redirects=True)
|
||||
|
||||
# user logout function
|
||||
def logout(self):
|
||||
return self.app_test_client.get('/auth/logout', follow_redirects=True)
|
||||
|
||||
# test user login and logout
|
||||
def test_login_logout(self):
|
||||
rv = self.login('test@dash-stack.org', 'test')
|
||||
assert 'Dash Stack - Web Developer' in rv.data
|
||||
#rv = self.logout()
|
||||
#assert 'You were logged out' in rv.data
|
||||
#rv = self.login('testx@dash-stack.org', 'test')
|
||||
#assert 'Invalid username' in rv.data
|
||||
#rv = self.login('test@dash-stack.org', 'testx')
|
||||
#assert 'Invalid password' in rv.data
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
x
Reference in New Issue
Block a user