Пример #1
0
def db(app):
    """A database for the tests."""
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    # Explicitly close DB connection
    _db.session.close()
    _db.drop_all()
Пример #2
0
def deploy(dropdb):
    if dropdb:
        db.drop_all()
        print("Database is droped.")
    db.create_all()
    print("---------- Start update. ----------")
    update_posts([], update_all=True)
    print("----------- End update. -----------")

    # 在 redis 中存储最后更新时间
    redis.set("last_update_at", datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
Пример #3
0
def db(app):
    """A database for the tests."""
    _db.app = app
    with app.app_context():
        _db.create_all()

    yield _db

    # Explicitly close DB connection
    _db.session.close()
    _db.drop_all()
Пример #4
0
    def setUp(self):
        db.drop_all()
        db.create_all()

        tag1 = Tag(value="tag1")
        db.session.add(tag1)

        tag2 = Tag(value="tag2")
        db.session.add(tag2)

        user = User(user_name="user1",
                    first_name="First Name",
                    last_name="Last Name",
                    password=generate_password_hash("1234"))
        db.session.add(user)

        post = Post(
            title="Post title",
            summary="""Post summary""",
            body="""Post body""",
            author=user,
            created=datetime(2020, 1, 15, 10, 30),
            updated=datetime(2020, 1, 15, 10, 30),
        )
        post_with_tags = Post(title="Second post title",
                              summary="""Second post summary""",
                              body="""Second post body""",
                              author=user,
                              created=datetime(2020, 1, 15, 10, 30),
                              updated=datetime(2020, 1, 15, 10, 30),
                              tags=[tag1, tag2])

        db.session.add(post)
        db.session.add(post_with_tags)
        db.session.commit()

        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument("--no-sandbox")
        chrome_options.add_argument("--disable-dev-shm-usage")

        self.driver = webdriver.Chrome(options=chrome_options)
        self.driver.get(self.get_server_url())
Пример #5
0
    def setUp(self):
        db.drop_all()
        db.create_all()

        user = User(user_name="user1",
                    first_name="First Name",
                    last_name="Last Name",
                    password=generate_password_hash("1234"))
        db.session.add(user)

        post = Post(
            title="Post title",
            summary="""Post summary""",
            body="""Post body""",
            author=user,
            created=datetime(2020, 1, 15, 10, 30) + timedelta(days=1),
            updated=datetime(2020, 1, 15, 10, 30) + timedelta(days=1),
        )
        db.session.add(post)
        db.session.commit()
Пример #6
0
def init_database():
    # create the database and the database table
    db.create_all()

    # Insert user data
    user1 = User()
    user1.username = '******'
    user1.email = '*****@*****.**'
    user1.password = '******'
    db.session.add(user1)

    user2 = User()
    user2.username = '******'
    user2.email = '*****@*****.**'
    user2.password = '******'
    db.session.add(user2)

    # commit the changes for the users
    db.session.commit()

    yield db  # this is where testing happens!
    db.drop_all()
Пример #7
0
 def tearDown(self):
   with self.app.app_context():
     db.session.remove()
     db.drop_all()
Пример #8
0
 def tearDown(self):
   with self.app.app_context():
     db.session.remove()
     db.drop_all()
Пример #9
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Пример #10
0
from blog.models import User, Post, db


# Create the database
db.drop_all()
# re-create
db.create_all()

# Create two users
user1 = User(username = '******', email = '*****@*****.**', password = '******')
user2 = User(username = '******', email = '*****@*****.**', password = '******')

db.session.add(user1)
db.session.add(user2)

db.session.commit()

# Query db
print(User.query.all())

print(User.query.first())

print(User.query.filter_by(username = '******').all())

dsr =  User.query.filter_by(username = '******').first()
print(dsr)
print(dsr.id, dsr.password, dsr.image_file, dsr.username, sep=":")

ak = User.query.get(2)
print(ak)