Skip to content

Commit

Permalink
wip: add test to check if a Path can be used as directory parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
nioncode committed Mar 11, 2020
1 parent aa05b83 commit d4d8101
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/app_custom_directory_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)

import sys
directory = 'temp_folder/temp_migrations'
if sys.version_info >= (3, 4):
# For newer Python versions, we want to test that
# a Path can be passed as directory parameter.
from pathlib import Path
directory = Path(directory)


migrate = Migrate(app, db, directory=directory)

manager = Manager(app)
manager.add_command('db', MigrateCommand)


class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(128))


@manager.command
def add():
db.session.add(User(name='test'))
db.session.commit()


if __name__ == '__main__':
manager.run()
10 changes: 10 additions & 0 deletions tests/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ def test_custom_directory(self):
(o, e, s) = run_cmd(sys.executable + ' app_custom_directory.py add')
self.assertTrue(s == 0)

def test_custom_directory_path(self):
(o, e, s) = run_cmd(sys.executable + ' app_custom_directory_path.py db init')
self.assertTrue(s == 0)
(o, e, s) = run_cmd(sys.executable + ' app_custom_directory_path.py db migrate')
self.assertTrue(s == 0)
(o, e, s) = run_cmd(sys.executable + ' app_custom_directory_path.py db upgrade')
self.assertTrue(s == 0)
(o, e, s) = run_cmd(sys.executable + ' app_custom_directory_path.py add')
self.assertTrue(s == 0)

def test_compare_type(self):
(o, e, s) = run_cmd(sys.executable + ' app_compare_type1.py db init')
self.assertTrue(s == 0)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_migrate_flaskcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ def test_custom_directory(self):
db.session.add(User(name='test'))
db.session.commit()

def test_custom_directory_path(self):
(o, e, s) = run_cmd('app_custom_directory_path.py', 'flask db init')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('app_custom_directory_path.py', 'flask db migrate')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('app_custom_directory_path.py', 'flask db upgrade')
self.assertTrue(s == 0)

from .app_custom_directory_path import db, User
db.session.add(User(name='test'))
db.session.commit()

def test_compare_type(self):
(o, e, s) = run_cmd('app_compare_type1.py', 'flask db init')
self.assertTrue(s == 0)
Expand Down

0 comments on commit d4d8101

Please sign in to comment.