本文整理汇总了Python中model.db.create_all函数的典型用法代码示例。如果您正苦于以下问题:Python create_all函数的具体用法?Python create_all怎么用?Python create_all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_all函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
print "(setUp ran)"
self.client = server.app.test_client()
server.app.config['TESTING'] = True
connect_to_test_db(server.app)
db.create_all()
示例2: setUp
def setUp(self):
# Get the Flask test client
self.client = app.test_client()
# Show Flask errors that happen during tests
app.config['TESTING'] = True
# Connect to test database
connect_to_db(app, "postgresql:///testdb")
# Create tables from model
db.create_all()
# Import different types of data from seed file
seed.load_users()
seed.load_groups()
seed.load_usergroups()
seed.load_patterns()
seed.load_invites()
# Reset auto incrementing primary keys to start after seed data
seed.set_val_user_id()
seed.set_val_group_id()
seed.set_val_usergroup_id()
seed.set_val_pattern_id()
seed.set_val_invite_id()
示例3: setUp
def setUp(self):
"""Stuff to do before every test."""
self.client = app.test_client()
app.config['TESTING'] = True
# Connect to test database (uncomment when testing database)
connect_to_db(app, "postgresql:///testdb")
# Create tables and add sample data (uncomment when testing database)
db.create_all()
example_data()
with self.client as c:
with c.session_transaction() as sess:
sess['RSVP'] = True
def tearDown(self):
"""Do at end of every test."""
# (uncomment when testing database)
db.session.close()
db.drop_all()
def test_games(self):
result = self.client.get("/games")
self.assertIn("Clue", result.data)
示例4: setUp
def setUp(self):
print "(setUp ran)"
self.client = server.app.test_client() # Sets up fake test browser
server.app.config['TESTING'] = True # Makes a 500 error in a route raise an error in a test
connect_to_db(app, "postgresql:///testdb") # Connect to temporary DB
db.create_all()
示例5: init
def init(configfile):
app.config.from_pyfile('openmoves.cfg.default', silent=False)
if configfile:
if not os.path.exists(configfile):
with open(configfile, 'w') as f:
initialize_config(f)
print("created %s" % configfile)
app.config.from_pyfile(configfile, silent=False)
assert app.config['SECRET_KEY']
SESSION_VERSION = 1
app.config['SECRET_KEY'] = "%s-%d" % (app.config['SECRET_KEY'], SESSION_VERSION)
assert 'SQLALCHEMY_TRACK_MODIFICATIONS' not in app.config
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
with app.app_context():
if db.engine.name == 'sqlite':
db.create_all()
Bootstrap(app)
app_bcrypt.init_app(app)
login_manager.init_app(app)
login_manager.login_view = "login"
return app
示例6: setUp
def setUp(self):
"""Stuff to do before every test."""
# Get the Flask test client
self.client = app.test_client()
# Mock session
# Connect to temporary database
connect_to_db(app, "sqlite:///")
# Create tables and add sample data
db.create_all()
sample_data()
def _mock_grab_image_dimensions(filename):
return (920, 764)
self._old_grab_image_dimensions = server.grab_image_dimensions
server.grab_image_dimensions = _mock_grab_image_dimensions
def _mock_generate_thumb(filename, crop_thumb):
return None
self._old_generate_thumb = server.generate_thumb
server.generate_thumb = _mock_generate_thumb
示例7: setUp
def setUp(self):
"""Do before every test."""
# Get the Flask test client
self.client = app.test_client()
# Show Flask errors that happen during tests
app.config['TESTING'] = True
# Connect to test database
connect_to_db(app, "postgresql:///testdb")
db.create_all()
# Make mocks
def _mock_get_yelp_search_results(term, location, category_filter, limit):
"""Mocks search results of Yelp API call for one restaurant."""
search_results = {"businesses": [{"rating": 4.5, "rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png", "review_count": 547, "name": "Saru Sushi Bar", "rating_img_url_small": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/a5221e66bc70/ico/stars/v1/stars_small_4_half.png", "url": "http://www.yelp.com/biz/saru-sushi-bar-san-francisco?utm_campaign=yelp_api&utm_medium=api_v2_search&utm_source=6XuCRI2pZ5pIvcWc9SI3Yg", "image_url": "https://s3-media2.fl.yelpcdn.com/bphoto/5-ugy01zjSvudVsfdhmCsA/ms.jpg", "display_phone": "+1-415-400-4510", "id": "saru-sushi-bar-san-francisco", "location": {"city": "San Francisco", "postal_code": "94114", "country_code": "US", "address": ["3856 24th St"], "coordinate": {"latitude": 37.751706, "longitude": -122.4288283}, "state_code": "CA"}}]}
return search_results
def _mock_is_open_now_true(keyword, location):
"""Mocks Google Places API call to return True for current open status."""
return True
self._old_is_open_now = process_results.is_open_now
process_results.is_open_now = _mock_is_open_now_true
self.old_get_yelp_search_results = server.yelp.search_query
server.yelp.search_query = _mock_get_yelp_search_results
示例8: message
def message():
db.create_all()
if request.values.get('Body', None).strip().lower() == 'register':
user = Users.query.filter_by(number=request.values.get('From')).first()
if user:
user.active = 1
db.session.commit()
else:
user = Users(request.values.get('From'))
db.session.add(user)
db.session.commit()
resp = twilio.twiml.Response()
resp.message("Confirmed! Stay tuned for dog and cat pics! Text \"pause\" to stop hearing from us :( .")
return str(resp)
elif request.values.get('Body', None).strip().lower() == 'pause':
user = Users.query.filter_by(number=request.values.get('From')).first()
if not user:
resp = twilio.twiml.Response()
resp.message("Hmm - you're not in our system! Want to sign up? Reply with \"register\"")
return str(resp)
else:
user.active = 0
db.session.commit()
resp = twilio.twiml.Response()
resp.message("You won't get any more messages - for now. Reply with \"register\" to start receiving again.")
return str(resp)
else:
resp = twilio.twiml.Response()
resp.message("Sorry - I don't understand that command!")
return str(resp)
示例9: setUp
def setUp(self):
# init tables
db.create_all()
# do imports
from model import User
from model import ItemCategory, ItemManufacturer, Item
from model import LocationBuilding, Location
from model import AssetInfo, Asset
from model import Inventory
# create objects
u1 = User('bob')
cat = ItemCategory('Computer')
man = ItemManufacturer('Dell')
item = Item(cat,man,'Optiplex 360')
building = LocationBuilding('CEER')
location = Location(building,'008')
tag = AssetInfo('ee02547','13349')
asset = Asset(tag,0,item,owner=u1,current=location,ip='153.104.47.23')
import datetime
inv = Inventory(u1,asset,datetime.datetime.now(),location)
# add to database
db.session.add(u1)
db.session.add(cat)
db.session.add(man)
db.session.add(building)
db.session.add(tag)
db.session.add(item)
db.session.add(location)
db.session.add(asset)
db.session.add(inv)
db.session.commit()
示例10: setUp
def setUp(self):
"""Setup to do before every test."""
# Get the Flask test client
self.client = app.test_client()
# secret key to allow sessions to be used
app.config['SECRET_KEY'] = 'sekrit!'
# Show Flask errors that happen during tests
app.config['TESTING'] = True
# Connect to test database
connect_to_db(app, db_uri="postgresql:///testdb")
# Create tables and add sample data
db.create_all()
# create db records for yarns, users, baskets, basket_yarns,
# projects, and patterns
create_example_data()
# create db records for preferences and user_preferences
load_preferences("test_data/preference_data.txt")
load_user_preferences("test_data/user_preference_data.txt")
with self.client as c:
with c.session_transaction() as session:
session['username'] = 'u1'
示例11: create_app
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = os.environ.get("FLASK_SECRET_KEY", "abcdef")
db.init_app(app)
with app.test_request_context():
db.create_all()
return app
示例12: __init__
def __init__(self):
logger.info("Message Manager init...")
try:
Message.query.all()
except:
db.create_all()
logger.info("Message Manager init done...")
示例13: setUp
def setUp(self):
print "\n\n\n\n (2) DOING A SEARCH TEST \n\n\n\n"
self.client = app.test_client()
app.config['TESTING'] = True
postgrespassword = os.environ['POSTGRES_PASSWORD']
db_uri = 'postgresql://' + postgrespassword + '/test'
connect_to_db(app, db_uri)
db.create_all()
load_regions()
load_users()
load_bestuses()
load_categories()
load_brands()
load_products()
load_tents()
load_filltypes()
load_gendertypes()
load_sleepingbags()
load_padtypes()
load_sleepingpads()
load_ratings()
load_histories()
load_test_postalcodes()
示例14: setUp
def setUp(self):
self.client = app.test_client()
app.config["TESTING"] = True
app.config["SECRET_KEY"] = "key"
connect_to_db(app, db_uri="postgresql:///testdb")
db.create_all()
示例15: setUp
def setUp(self):
"""Set up app, session key, and fake client."""
app.config['TESTING'] = True
self.client = app.test_client()
connect_to_db(app, 'postgresql:///testdb')
db.create_all()