Beispiel #1
0
def initdb():
    """Initialize MySQL databse."""
    from app.libs.db import init_db
    from app.models import Permission, User, Topic
    from app.base.roles import Roles
    from app.settings import Admins, Topics
    from app.libs.utils import encrypt_password

    click.echo('[2L] {0}..'.format(initdb.__doc__))
    init_db()

    click.echo('\n\n[2L] init permisions...')
    for attr, role in Roles.__dict__.items():
        if (not attr.startswith('__') and '{0}' not in role and
                role != 'root'):
            click.echo(' -> {0}'.format(role))
            Permission.create(role)

    click.echo('\n\n[2L] init master chief...')
    bit_sum = Permission.root_permission()
    for admin in Admins:
        click.echo(' -> {0}'.format(admin))
        if admin['role'] == 'root':
            admin['role'] = bit_sum
        else:
            admin['role'] = (Permission.get_by_role(admin['role']).bit |
                             Permission.get_by_role('comment').bit |
                             Permission.get_by_role('vote').bit)
        admin['password'] = encrypt_password(admin['password'])
        User.create(**admin)

    click.echo('\n\n[2L] create default topics...')
    for topic in Topics:
        click.echo(' -> {0}'.format(topic))
        Topic.create(**topic)
Beispiel #2
0
 def setUp(self):
     super(RegisterTests, self).setUp()
     init_db()
     User.create(
         username='******',
         password='******',
         email='*****@*****.**'
     )
Beispiel #3
0
 def setUp(self):
     super(RegisterTests, self).setUp()
     init_db()
     self._data = {
         'username': '******',
         'password': '******',
         'email': '*****@*****.**',
     }
     User.create(**self._data)
Beispiel #4
0
 def setUp(self):
     super(BaseTestCase, self).setUp()
     init_db()