示例#1
0
def deploy():
    db.drop_all()
    db.create_all()
    actor1 = Actor(name='Robert Downey Jr.', age='52', gender='Male')
    actor2 = Actor(name='Scarlett Johansson', age='33', gender='Female')
    actor3 = Actor(name='Christian Bale', age='43', gender='Male')
    movie1 = Movie(title='Iron Man',
                   year="2008",
                   description="Man made of iron",
                   actor=actor1)
    movie2 = Movie(title='The Avengers',
                   year="2012",
                   description="Avengers save the world",
                   actor=actor2)
    movie3 = Movie(title='The Dark Knight',
                   year="2008",
                   description="Batman vs Joker",
                   actor=actor3)
    db.session.add(actor1)
    db.session.add(actor2)
    db.session.add(actor3)
    db.session.add(movie1)
    db.session.add(movie2)
    db.session.add(movie3)
    db.session.commit()
示例#2
0
def initdb(drop):
    '''
    Init the database.
    '''
    if drop:  # 判断是否输入了选项
        db.drop_all()
    db.create_all()
    click.echo('initialized database.')  # 输出提示信息
示例#3
0
def forge():
    '''Generate fake data.'''
    db.create_all()
    name = 'Han Star'

    movies = [
        {
            'title': 'My Neighbor Totoro',
            'year': '1988'
        },
        {
            'title': 'Dead Poets Society',
            'year': '1989'
        },
        {
            'title': 'A Perfect World',
            'year': '1993'
        },
        {
            'title': 'Leon',
            'year': '1994'
        },
        {
            'title': 'Mahjong',
            'year': '1996'
        },
        {
            'title': 'Swallowtail Butterfly',
            'year': '1996'
        },
        {
            'title': 'King of Comedy',
            'year': '1999'
        },
        {
            'title': 'Devils on the Doorstep',
            'year': '1999'
        },
        {
            'title': 'WALL-E',
            'year': '2008'
        },
        {
            'title': 'The Pork of Music',
            'year': '2012'
        },
    ]

    user = User(name=name)
    db.session.add(user)
    for m in movies:
        movie = Movie(title=m['title'], year=m['year'])
        db.session.add(movie)
    db.session.commit()
    click.echo("Done....")
示例#4
0
 def test_admin_command(self):
     """测试生成管理员"""
     db.drop_all()
     db.create_all()
     result = self.runner.invoke(
         args=['admin', '--username', 'hanguoxing', '--password', '123'])
     self.assertIn('Creating user...', result.output)
     self.assertIn('Admin Create over!!!', result.output)
     self.assertEqual(User.query.count(), 1)
     self.assertEqual(User.query.first().username, 'hanguoxing')
     self.assertTrue(User.query.first().validate_password('123'))
示例#5
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(project_dir, TEST_DB)
        self.app = app.test_client()
        db.drop_all()
        db.create_all()
 
        self.assertEqual(app.debug, False)
示例#6
0
def deploy():
    db.drop_all()
    db.create_all()
    actor1 = Actor(name='Coldplay', active='1999-present')
    actor2 = Actor(name='Maroon 5', active='2010-2017')
    movie1 = Movie(title='Yellow', year=2000, actor=actor1)
    movie2 = Movie(title='Suger', year=2014, actor=actor2)
    db.session.add(actor1)
    db.session.add(actor2)
    db.session.add(movie1)
    db.session.add(movie2)
    db.session.commit()
示例#7
0
def admin(username, password):
    '''创建管理员账户'''
    db.create_all()
    user = User.query.first()
    if user is not None:
        click.echo('Updating user...')
        user.username = username
        user.set_password(password)  # 设置密码
    else:
        click.echo('Creating user...')
        user = User(username=username, name='Admin')
        user.set_password(password)
        db.session.add(user)
    db.session.commit()
    click.echo('Admin Create over!!!')
示例#8
0
    def setUp(self):
        # 配置更新
        app.config.update(TESTING=True,
                          SQLALCHEMY_DATABASE_URI='sqlite:///:memory:')
        # 创建数据库和表
        db.create_all()
        # 创建测试数据
        user = User(name="Test", username='******')
        user.set_password('123')
        movie = Movie(title='Test Movie', year='2020')
        # 使用add_all放管服测试添加多个实例
        db.session.add_all([user, movie])
        db.session.commit()

        self.client = app.test_client()  # 创建客户端测试
        self.runner = app.test_cli_runner()  # 创建测试命令运行器
示例#9
0
def deploy():
    db.drop_all()
    db.create_all()
    StevenSpielberg = Director(name='Steven Spielberg', about='Steven Spielberg is an American filmmaker and the highest grossing filmmaker of all time')
    RyanCoogler = Director(name='Ryan Coogler', about='Ryan Coogler is an up and coming director known for his movies Creed and Black Panther')
    JJAbrams = Director(name='JJ Abrams', about='JJ Abrams is a director well known for his Star Trek and Star Wars movies')
    movie1 = Movie(name='Jurassic Park', year=1993, ratings="IMDb: 8.1, Rotten Tomatoes: 92%", director=StevenSpielberg)
    movie2 = Movie(name='BlackPanther', year=2018, ratings="IMDb: 7.6, Rotten Tomatoes: 97%", director=RyanCoogler)
    movie3 = Movie(name='Star Wars: The Force Awakens', year=2015, ratings="IMDb: 8, Rotten Tomatoes: 93%", director=JJAbrams)
    db.session.add(StevenSpielberg)
    db.session.add(RyanCoogler)
    db.session.add(JJAbrams)
    db.session.add(movie1)
    db.session.add(movie2)
    db.session.add(movie3)
    db.session.commit()
示例#10
0
def deploy():
    print("resetting database....")
    db.drop_all()
    db.create_all()

    gosling = Actor(name="Ryan Gosling", age="37")
    evans = Actor(name="Chris Evans", age="36")
    lawrence = Actor(name="Jennifer Lawrence", age="27")

    notebook = Movie(
        title="The Notebook",
        year="2004",
        description=
        "This movie is incredibly romantic. I would reccomend seeing this with a loved one, or if its a girls night and you want to cry. This is such a beautiful movie!",
        actor=gosling)
    avengers = Movie(
        title="The Avengers",
        year="2012",
        description=
        "The Avengers is the best superhero movie ever made so far. Different superheros come together to fight in an awesome squad to beat aliens and villians.",
        actor=evans)
    sparrow = Movie(
        title="Red Sparrow",
        year="2018",
        description=
        "The Red Sparrow is definitely not your average movie, it is action packed, bloody and sexual all at the same time.",
        actor=lawrence)

    db.session.add(gosling)
    db.session.add(evans)
    db.session.add(lawrence)

    db.session.add(notebook)
    db.session.add(avengers)
    db.session.add(sparrow)

    db.session.commit()
示例#11
0
def deploy():
    db.drop_all()
    db.create_all()
    director1 = Director(name='Kenny Ortega', years_active='1980-Present')
    director2 = Director(name='Seth Gordon', years_active='2005-Present')
    director3 = Director(name='John Polson', years_active='1999-2011')
    director4 = Director(name="King Vidor", years_active="1913-1980")
    director5 = Director(name="Griffin Dunne", years_active="1975-Present")
    director6 = Director(name="John Carpenter", years_active="1969-Present")
    movie1 = Movie(
        title='Hocus Pocus',
        genre='Comedy',
        year='1993',
        description=
        "After three centuries, three witch sisters are resurrected in Salem, Massachusetts on Halloween night, and it is up to two teenagers, a young girl, and an immortal cat to put an end to their reign of terror once and for all.",
        director=director1)
    movie2 = Movie(
        title='Horrible Bosses',
        genre='Comedy',
        year='2011',
        description=
        "Three friends conspire to murder their awful bosses when they realize they are standing in the way of their happiness.",
        director=director2)
    movie3 = Movie(
        title='Swimfan',
        genre='Thriller',
        year='2002',
        description=
        "A high school senior with a promising swimming career has a one-night stand with consequences.",
        director=director3)
    movie4 = Movie(
        title="The Wizard of Oz",
        genre="Science Fiction",
        year="1939",
        description=
        "An innocent farm girl whisked out of her mundane earthbound existence into a land of pure imagination.",
        director=director4)
    movie5 = Movie(
        title="Practical Magic",
        genre="Fantasy",
        year="1998",
        description=
        "Sally and Gillian Owens, born into a magical family, have mostly avoided witchcraft themselves. But when Gillian's vicious boyfriend, Jimmy Angelov, dies unexpectedly, the Owens sisters give themselves a crash course in hard magic.",
        director=director5)
    movie6 = Movie(
        title="Halloween",
        genre="Thriller",
        year="1978",
        description=
        "Fifteen years after murdering his sister on Halloween night 1963, Michael Myers escapes from a mental hospital and returns to the small town of Haddonfield to kill again.",
        director=director6)
    db.session.add(director1)
    db.session.add(director2)
    db.session.add(director3)
    db.session.add(director4)
    db.session.add(director5)
    db.session.add(director6)
    db.session.add(movie1)
    db.session.add(movie2)
    db.session.add(movie3)
    db.session.add(movie4)
    db.session.add(movie5)
    db.session.add(movie6)
    db.session.commit()
示例#12
0
def bootstrap_data():
    """Populates database with data"""
    db.drop_all()
    db.create_all()

    m = Movie(
        title="Evil Dead", release_date=datetime.strptime("Oct 15 1981", "%b %d %Y")
    )

    m2 = Movie(
        title="Darkman", release_date=datetime.strptime("Aug 24 1990", "%b %d %Y")
    )

    m3 = Movie(
        title="The Quick and the Dead",
        release_date=datetime.strptime("Feb 10 1995", "%b %d %Y"),
    )

    m4 = Movie(
        title="The Gift", release_date=datetime.strptime("Jan 19 2001", "%b %d %Y")
    )

    m5 = Movie(
        title="Army of Darkness",
        release_date=datetime.strptime("Feb 19 1993", "%b %d %Y"),
    )

    db.session.add(m)
    db.session.add(m2)
    db.session.add(m3)
    db.session.add(m4)
    db.session.add(m5)

    d = Director(
        first_name="Sam", last_name="Raimi", guild=GuildMembership(guild="Raimi DGA")
    )
    m.director = d
    m2.director = d
    m3.director = d
    m4.director = d
    m5.director = d
    db.session.add(d)

    bruce = Actor(
        first_name="Bruce",
        last_name="Campbell",
        guild=GuildMembership(guild="Campbell SAG"),
    )
    ellen = Actor(
        first_name="Ellen",
        last_name="Sandweiss",
        guild=GuildMembership(guild="Sandweiss SAG"),
    )
    hal = Actor(
        first_name="Hal",
        last_name="Delrich",
        guild=GuildMembership(guild="Delrich SAG"),
    )
    betsy = Actor(
        first_name="Betsy", last_name="Baker", guild=GuildMembership(guild="Baker SAG")
    )
    sarah = Actor(
        first_name="Sarah", last_name="York", guild=GuildMembership(guild="York SAG")
    )

    # darkman actors
    liam = Actor(
        first_name="Liam", last_name="Neeson", guild=GuildMembership(guild="Neeson SAG")
    )
    frances = Actor(
        first_name="Frances",
        last_name="McDormand",
        guild=GuildMembership(guild="McDormand SAG"),
    )

    # Quick and the Dead Actors
    sharon = Actor(
        first_name="Sharon", last_name="Stone", guild=GuildMembership(guild="Stone Sag")
    )
    gene = Actor(
        first_name="Gene",
        last_name="Hackman",
        guild=GuildMembership(guild="Hackman Sag"),
    )

    # The Gift Actors
    cate = Actor(
        first_name="Cate",
        last_name="Blanchett",
        guild=GuildMembership(guild="Blanchett Sag"),
    )
    keanu = Actor(
        first_name="Keanu",
        last_name="Reeves",
        guild=GuildMembership(guild="Reeves Sag"),
    )

    db.session.add(bruce)
    db.session.add(ellen)
    db.session.add(hal)
    db.session.add(betsy)
    db.session.add(sarah)
    db.session.add(liam)
    db.session.add(frances)
    db.session.add(sharon)
    db.session.add(gene)
    db.session.add(cate)
    db.session.add(keanu)

    m.actors.extend((bruce, ellen, hal, betsy, sarah))
    m2.actors.extend((bruce, liam, frances))
    m3.actors.extend((bruce, sharon, gene))
    m4.actors.extend((bruce, cate, keanu))
    m5.actors.append(bruce)

    db.session.commit()

    print("Added development dataset")
示例#13
0
def reset_db():
    """Drops and Creates fresh database"""
    db.drop_all()
    db.create_all()

    print("Initialized default DB")