Exemplo n.º 1
0
 def initdb(drop):
     if drop:
         click.confirm(
             'This operation will delete the database, doyou want to continue?',
             abort=True)
         db.drop_all()
         click.echo('Drop tables.')
     db.create_all()
     click.echo('Initialized database.')
Exemplo n.º 2
0
    def forge(message):
        """Generate fake data."""
        import random
        from sqlalchemy.exc import IntegrityError

        from faker import Faker

        fake = Faker()

        click.echo('Initializing the database...')
        db.drop_all()
        db.create_all()

        click.echo('Forging the data')
        admin = User(nickname="admin", email="*****@*****.**")
        admin.password = "******"
        db.session.add(admin)
        db.session.commit()

        click.echo('Generating users...')
        for i in range(50):
            user = User(nickname=fake.name(),
                        bio=fake.sentence(),
                        github=fake.url(),
                        website=fake.url(),
                        email=fake.email())
            user.password = user.email
            db.session.add(user)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()

        click.echo('Generating messages...')
        for i in range(message):
            message = Message(
                author=User.query.get(random.randint(1, User.query.count())),
                body=fake.sentence(),
                timestamp=fake.date_time_between('-30d', '-2d'),
            )
            db.session.add(message)
        db.session.commit()
        click.echo('Done.')
Exemplo n.º 3
0
    def forge(message):
        import random
        from sqlalchemy.exc import IntegrityError

        from faker import Faker

        fake = Faker('zh_CN')

        click.echo('Initializing the database...')
        db.drop_all()
        db.create_all()

        click.echo('Forging the data...')
        admin = User(nickname='CoderShui', email='*****@*****.**')
        admin.set_password('123456')
        db.session.add(admin)
        db.session.commit()

        click.echo('Generating users...')
        for i in range(50):
            user = User(nickname=fake.name(),
                        bio=fake.sentence(),
                        github=fake.url(),
                        website=fake.url(),
                        email=fake.email())
            user.set_password('123456')
            db.session.add(user)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()

        click.echo('Generating messges....')
        for i in range(message):
            message = Message(
                author=User.query.get(random.randint(1, User.query.count())),
                body=fake.sentence(),
                timestamp=fake.date_time_between('-30d', '-2d'),
            )
            db.session.add(message)
        db.session.commit()
        click.echo('Done.')
Exemplo n.º 4
0
    def forge(message):
        """Generate fake data."""
        import random
        from sqlalchemy.exc import IntegrityError

        from faker import Faker

        fake = Faker()

        click.echo('Initializing the database...')
        db.drop_all()
        db.create_all()

        click.echo('Forging the data...')
        admin = User(nickname='Grey Li', email='*****@*****.**')
        admin.set_password('helloflask')
        db.session.add(admin)
        db.session.commit()

        click.echo('Generating users...')
        for i in range(2, 52):
            user = User(id=i,
                        nickname=fake.name(),
                        bio=fake.sentence(),
                        github=fake.url(),
                        website=fake.url(),
                        email=fake.email())
            db.session.add(user)
            try:
                db.session.commit()
            except IntegrityError:
                db.session.rollback()

        click.echo("creating a room containing these users.")
        room = Room(id=1,
                    name="Family - All",
                    cur_user_total=0,
                    user_total=0,
                    owner=admin.id)
        for i in range(2, 52):
            user_room = UserRoom(
                user_id=i,
                room_id=1,
            )
            db.session.add(user_room)
            room.user_total += 1
        db.session.add(room)

        db.session.commit()

        click.echo('Generating messages...')
        for i in range(message):
            message = Message(author=User.query.get(
                random.randint(1, User.query.count())),
                              body=fake.sentence(),
                              timestamp=fake.date_time_between('-30d', '-2d'),
                              room_id=1)
            db.session.add(message)

        db.session.commit()
        click.echo('Done.')
Exemplo n.º 5
0
 def tearDown(self) -> None:
     db.drop_all()
     self.context.pop()
Exemplo n.º 6
0
 def setUp(self):
     super(CLITestCase, self).setUp()
     db.drop_all()