Пример #1
0
def db_create_models():
    "Creates database tables."
    # db_createall doesn't work if the models aren't imported
    import_string('models', silent=True)
    for blueprint_name, blueprint in app.blueprints.iteritems():
        import_string('%s.models' % blueprint.import_name, silent=True)
    db.create_all()
Пример #2
0
    def test_update_2(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        b = Brewery(name="Austin's Brew House")

        db.session.add(b)
        db.session.commit()
        b.website = "http://www.austinbrew.com/"
        db.session.commit()

        result = db.session.query(Brewery).filter_by(name="Austin's Brew House").first()
        self.assertEqual(result.website, "http://www.austinbrew.com/")
Пример #3
0
    def test_update_3(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        s = Style(name="Old Western Ale", description="Taste's like the old west")

        db.session.add(s)
        db.session.commit()
        s.name = "Old Eastern Ale"
        db.session.commit()

        result = db.session.query(Style).filter_by(name="Old Eastern Ale").first()
        self.assertEqual(result.description, "Taste's like the old west")
Пример #4
0
    def test_delete_1(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        beer1 = Beer(name='Coors Light', description="Taste's like urine.",
            is_organic="N", abv=11.1, ibu=30)

        db.session.add(beer1)
        db.session.commit()
        self.assertEqual(beer1._sa_instance_state.persistent, True)

        db.session.delete(beer1)
        db.session.commit()
        self.assertEqual(beer1._sa_instance_state.persistent, False)
Пример #5
0
    def test_update_1(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        beer1 = Beer(name='Coors Light', description="Taste's like urine.",
            is_organic="N", abv=11.1, ibu=30)

        db.session.add(beer1)
        db.session.commit()
        beer1.abv = 1234
        db.session.commit()

        result = db.session.query(Beer).filter_by(name="Coors Light").first()
        self.assertEqual(result.abv, 1234)
Пример #6
0
    def test_relationship_1(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        coors_light = Beer(name='Coors Light', description="Taste's like urine.",
            is_organic="N", abv=11.1, ibu=30)
        austin_brew = Brewery(name="Austin's Brew House")
        db.session.add(coors_light)
        db.session.add(austin_brew)

        self.assertEqual(austin_brew.beers, [])
        austin_brew.beers = [coors_light]
        db.session.commit()

        self.assertEqual(austin_brew.beers[0].name, "Coors Light")
Пример #7
0
    def test_delete_3(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        style1 = Style(name="Old Western Ales")
        style2 = Style(name='Russian Blends', description="It's pretty much just vodka")

        db.session.add(style1)
        db.session.add(style2)
        db.session.commit()

        db.session.delete(style1)
        db.session.commit()

        self.assertEqual(style1._sa_instance_state.persistent, False)
        self.assertEqual(style2._sa_instance_state.persistent, True)
Пример #8
0
    def test_add_3(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        style1 = Style(name="Old Western Ales")
        style2 = Style(name='Russian Blends', description="It's pretty much just vodka")

        db.session.add(style1)
        db.session.add(style2)
        db.session.commit()

        result = db.session.query(Style).filter_by(name="Old Western Ales").first()
        self.assertEqual(result.name, "Old Western Ales")

        result = db.session.query(Style).filter_by(style_id=2).first()
        self.assertEqual(result.description, "It's pretty much just vodka")

        self.assertEqual(style1.style_id, 1)
        self.assertEqual(style2.style_id, 2)
Пример #9
0
    def test_add_2(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        brewery1 = Brewery(name="Austin's Brew House")
        brewery2 = Brewery(name='The Brewski on 6th', description="Making good stuff",
            website="http://www.brew6th.com/")

        db.session.add(brewery1)
        db.session.add(brewery2)
        db.session.commit()

        result = db.session.query(Brewery).filter_by(name="Austin's Brew House").first()
        self.assertEqual(result.name, "Austin's Brew House")

        result = db.session.query(Brewery).filter_by(brewery_id=2).first()
        self.assertEqual(result.name, "The Brewski on 6th")

        self.assertEqual(brewery1.brewery_id, 1)
        self.assertEqual(brewery2.brewery_id, 2)
Пример #10
0
    def test_delete_2(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        brewery1 = Brewery(name="Austin's Brew House")
        brewery2 = Brewery(name='The Brewski on 6th', description="Making good stuff",
            website="http://www.brew6th.com/")

        db.session.add(brewery1)
        db.session.add(brewery2)
        db.session.commit()

        self.assertEqual(brewery1._sa_instance_state.persistent, True)
        self.assertEqual(brewery2._sa_instance_state.persistent, True)

        db.session.delete(brewery1)
        db.session.commit()

        self.assertEqual(brewery1._sa_instance_state.persistent, False)
        self.assertEqual(brewery2._sa_instance_state.persistent, True)
Пример #11
0
    def test_add_1(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        beer1 = Beer(name='Coors Light', description="Taste's like urine.",
            is_organic="N", abv=12.2, ibu=30)
        beer2 = Beer(name='Blue Moon Original', description="A gift from heaven",
            is_organic="N", abv=9.8, ibu=70)

        db.session.add(beer1)
        db.session.add(beer2)
        db.session.commit()

        result = db.session.query(Beer).filter_by(abv=9.8).first()
        self.assertEqual(result.name, "Blue Moon Original")

        result = db.session.query(Beer).filter_by(name="Coors Light").first()
        self.assertEqual(result.ibu, 30)

        self.assertEqual(beer1.beer_id, 1)
        self.assertEqual(beer2.beer_id, 2)
Пример #12
0
    def test_relationship_2(self) :
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
        db.drop_all()
        db.create_all()

        coors_light = Beer(name='Coors Light', description="Taste's like urine.",
            is_organic="N", abv=11.1, ibu=30)
        blue_moon = Beer(name='Blue Moon', description="Pretty good.",
            is_organic="N", abv=6.3, ibu=50)
        light_lager = Style(name="Light Hail Lager")

        self.assertEqual(light_lager.beers, [])
        light_lager.beers = [coors_light, blue_moon]
        db.session.add(blue_moon)
        db.session.add(coors_light)
        db.session.add(light_lager)

        self.assertEqual(light_lager.beers[0], coors_light)
        self.assertEqual(light_lager.beers[1], blue_moon)
        self.assertEqual(light_lager.style_id, blue_moon.style_id)

        db.session.commit()
Пример #13
0
from config import db

class Content(db.Model):
	'''
	write a news story to the database specified in __init__.py
	'''
	__tablename__ = 'content'

	id = db.Column(db.Integer, primary_key=True)
	title = db.Column(db.String)
	repeat_count = db.Column(db.Integer)
	image = db.Column(db.String)
	link = db.Column(db.String)
	time_scraped = db.Column(db.DateTime)

	def __repr__(self):
		return "<Content(title='{0}', link='{1}', time_scraped='{2}')>".format(self.title, self.link, self.time_scraped)

db.create_all()

Пример #14
0
def main():
    db.create_all()
Пример #15
0
def db_createall():
    """Creates databases.
    Use migrations instead.
    """
    db.create_all()
Пример #16
0
def create_db():
    if not os.path.isdir(db_path):
        os.makedirs(db_path)
    db.create_all()
Пример #17
0
def create_db():
    app.config['SQLALCHEMY_ECHO'] = True
    db.drop_all()
    db.create_all()
Пример #18
0
 def setUp(self):
     with self.app.app_context():
         db.create_all()
Пример #19
0
def create_table():
    db.create_all()


#deploy link rest-api
#https://stores-python-flask-api.herokuapp.com/items
Пример #20
0
def db_createall():
    "Creates database"
    db.create_all()
Пример #21
0
import os
from config import db, create_app
from models import Product, Rule

db.create_all(app=create_app())
app = create_app()
app.app_context().push()

# Data to initialize database with
PRODUCTS = [{
    'sku': 'AZ00001',
    'description': 'Paraguas de señora estampado',
    'price': 10
}, {
    'sku': 'AZ00002',
    'description': 'Helado de sabor fresa',
    'price': 1
}]

RULES = [{
    'city': 'Leon',
    'country': 'ni',
    'sku': 'AZ00001',
    'min_condition': 500,
    'max_condition': 599,
    'variation': 1.5
}, {
    'city': 'Leon',
    'country': 'ni',
    'sku': 'AZ00002',
    'min_condition': 500,
Пример #22
0
def create_tables():
    db.create_all()
Пример #23
0
def create_db():
    db.create_all()
Пример #24
0
 def setUp(self):
     self.app = app.test_client()
     db.create_all()
Пример #25
0
from models.User import User
from models.product import Product
from models.ProductOrder import ProductOrder
import views_user
import views_product
import datetime


@app.route('/test')
def test():
    return render_template('index.html', uname=req.args['uname'])


if __name__ == '__main__':
    # 如果修改了表结构,需要Ctrl+C退出程序,重新运行
    db.create_all()  # 生成数据库表结构

    # 在这里写测试代码

    user1 = User('yangjin', '111111', datetime.date(1997, 8, 27), 1, 0,
                 '湖北省武汉市武汉理工大学余家头校区', '18672019299', 0)
    user2 = User('yj', '111111', datetime.date(1997, 8, 27), 1, 0,
                 '湖北省武汉市武汉理工大学南湖校区', '18672019299', 0)
    product1 = Product(
        2, '优衣库羽绒服女装', 499, '武汉', 195, 202,
        'D:\\tomcat9\\webapps\\managerSys\\pictures\\UNIQLO women coat.jpg',
        'UNIQLO', '冬装 衣服', '填充白鸭绒,材料不错,不会钻毛,三色可以选择')
    product2 = Product(
        2, '优衣库牛仔裤女装', 299, '武汉', 10, 210,
        'D:\\tomcat9\\webapps\managerSys\\pictures\\women jeans1.jpg',
        'UNIQLO', '秋冬 裤子', '100%棉')
Пример #26
0
def create_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
Пример #27
0
def db_createall():
    "Creates database"
    db.create_all()
Пример #28
0
def create_db():
    """need to run this just ONCE to create the database
    """
    db.create_all()
Пример #29
0
def seed_data():
    db.drop_all()
    db.create_all()

    hashed_password = bcrypt.hashpw(b'secretpassword', bcrypt.gensalt(12))

    ronny = User(username='******', email='*****@*****.**', password=hashed_password, createdAt=datetime(2020, 3, 3))
    brandon = User(username='******', email='*****@*****.**', password=hashed_password, createdAt=datetime(2020, 3, 3))
    kaiser = User(username='******', email='*****@*****.**', password=hashed_password, createdAt=datetime(2020, 3, 18))
    db.session.add(ronny)
    db.session.add(brandon)
    db.session.add(kaiser)
    db.session.commit()

    cards = []
    decks = []
    deck_of_cards = []

    # UW Control (RTR Standard)
    cards.append(Card(name="Azorius Charm", image="https://img.scryfall.com/cards/large/front/9/7/9740ceaf-4ef9-48dd-ab7d-cd5eb3be8cec.jpg?1562851619"))
    cards.append(Card(name="Dissolve", image="https://img.scryfall.com/cards/large/front/b/4/b4fb87ab-8595-459a-a5f2-087296d9b120.jpg?1562853056"))
    cards.append(Card(name="Doom Blade", image="https://img.scryfall.com/cards/large/front/9/0/90699423-2556-40f7-b8f5-c9d82f22d52e.jpg?1562851557"))
    cards.append(Card(name="Hero's Downfall", image="https://img.scryfall.com/cards/large/front/5/9/596822f6-dbd4-4cc8-aa50-9331ff42544e.jpg?1562818494"))
    cards.append(Card(name="Sphinx's Revelation", image="https://img.scryfall.com/cards/large/front/0/0/0038ea4d-d0a6-44a4-bee6-24c03313d2bc.jpg?1561759805"))
    cards.append(Card(name="Supreme Verdict", image="https://img.scryfall.com/cards/large/front/a/6/a679cc74-6119-468f-8c64-5dcf216438d1.jpg?1562852509"))
    cards.append(Card(name="Detention Sphere", image="https://img.scryfall.com/cards/large/front/a/f/afee5464-83b7-4d7a-b407-9ee7de21535b.jpg?1562791607"))
    cards.append(Card(name="Elspeth, Sun's Champion", image="https://img.scryfall.com/cards/large/front/f/d/fd5b1633-c41d-42b1-af1b-4a872077ffbd.jpg?1562839369"))
    cards.append(Card(name="Jace, Architect of Thought", image="https://img.scryfall.com/cards/large/front/d/4/d4df3a38-678e-42dc-a3fd-d1d399368f07.jpg?1562793747"))
    cards.append(Card(name="Aetherling", image="https://img.scryfall.com/cards/large/front/9/c/9c93313b-cf43-47e9-a911-717b4d14b0b5.jpg?1562924171"))
    cards.append(Card(name="Blood Baron of Vizkopa", image="https://img.scryfall.com/cards/large/front/5/6/56955e63-db6f-4f1d-b3c4-dd268c902653.jpg?1562848962"))
    cards.append(Card(name="Godless Shrine", image="https://img.scryfall.com/cards/large/front/6/f/6fd672bb-18cf-44e3-8dda-5310b1e0fffe.jpg?1561831123"))
    cards.append(Card(name="Hallowed Fountain", image="https://img.scryfall.com/cards/large/front/a/f/af7091c9-5f98-4078-a42b-c9e057346d9b.jpg?1562791585"))
    cards.append(Card(name="Island", image="https://img.scryfall.com/cards/large/front/9/6/96ad5cbb-b64e-4e18-9aa0-ac076d4b2448.jpg?1583553498"))
    cards.append(Card(name="Plains", image="https://img.scryfall.com/cards/large/front/2/2/2296cffa-be1f-49af-aaca-3166e7043de0.jpg?1583553460"))
    cards.append(Card(name="Temple of Deceit", image="https://img.scryfall.com/cards/large/front/6/8/686559d7-8ac1-496b-a5a6-1467bf8fc7c5.jpg?1562819288"))
    cards.append(Card(name="Temple of Silence", image="https://img.scryfall.com/cards/large/front/0/f/0f14b6b3-5f40-4328-a3be-28fe32dd7cb1.jpg?1562814674"))
    cards.append(Card(name="Watery Grave", image="https://img.scryfall.com/cards/large/front/4/7/47fde349-010e-4a2e-838e-e924dbeec355.jpg?1561825120"))

    # Combo Elves (Legacy)
    cards.append(Card(name="Birchlore Rangers", image="https://img.scryfall.com/cards/large/front/8/c/8ce3a3a1-3569-4909-a604-f78d4888781e.jpg?1562928197"))
    cards.append(Card(name="Heritage Druid", image="https://img.scryfall.com/cards/large/front/a/7/a726acbd-724e-46c5-a4cf-4aee7c2abb16.jpg?1562880575"))
    cards.append(Card(name="Elvish Mystic", image="https://img.scryfall.com/cards/large/front/d/6/d618c3ea-f823-4fe0-8e11-65d5965528d3.jpg?1561759745"))
    cards.append(Card(name="Elvish Reclaimer", image="https://img.scryfall.com/cards/large/front/3/9/39c431d7-d94b-46c4-bb89-f3db56214ab4.jpg?1563899381"))
    cards.append(Card(name="Elvish Visionary", image="https://img.scryfall.com/cards/normal/front/f/a/faccfa5f-4d89-4a86-92d7-36cb5a16c5c9.jpg?1562711018"))
    cards.append(Card(name="Fyndhorn Elves", image="https://img.scryfall.com/cards/large/front/4/5/45718e96-c7e4-45ef-9196-d3a1eea878fb.jpg?1562909070"))
    cards.append(Card(name="Llanowar Elves", image="https://img.scryfall.com/cards/large/front/7/3/73542493-cd0b-4bb7-a5b8-8f889c76e4d6.jpg?1562302708"))
    cards.append(Card(name="Multani's Acolyte", image="https://img.scryfall.com/cards/large/front/4/e/4e5fdecb-bca0-48ea-b5bb-d0886c7d3316.jpg?1562862815"))
    cards.append(Card(name="Nettle Sentinel", image="https://img.scryfall.com/cards/large/front/f/9/f9f21681-fd36-4106-8395-3153599a08a6.jpg?1562947879"))
    cards.append(Card(name="Quirion Ranger", image="https://img.scryfall.com/cards/large/front/5/6/56efe72c-6d7f-44f6-ac74-01af9305c4b6.jpg?1562277667"))
    cards.append(Card(name="Wirewood Symbiote", image="https://img.scryfall.com/cards/large/front/4/9/49488b76-abaf-4dba-b01f-7b418e4ff295.jpg?1562528525"))
    cards.append(Card(name="Craterhoof Behemoth", image="https://img.scryfall.com/cards/large/front/a/2/a249be17-73ed-4108-89c0-f7e87939beb8.jpg?1561879555"))
    cards.append(Card(name="Natural Order", image="https://img.scryfall.com/cards/large/front/0/8/0845f0b0-9413-4ddd-861d-9607636bebc6.jpg?1562276959"))
    cards.append(Card(name="Glimpse of Nature", image="https://img.scryfall.com/cards/large/front/1/d/1ddcd76b-a7a1-4ae6-bf4a-f929c6574bdc.jpg?1562757977"))
    cards.append(Card(name="Green Sun's Zenith", image="https://img.scryfall.com/cards/large/front/0/2/02335747-54e3-4827-ae19-4e362863da9b.jpg?1562609284"))
    cards.append(Card(name="Gaea's Cradle", image="https://img.scryfall.com/cards/large/front/2/5/25b0b816-0583-44aa-9dc5-f3ff48993a51.jpg?1562902898"))
    cards.append(Card(name="Misty Rainforest", image="https://img.scryfall.com/cards/large/front/2/4/24a5cc2c-0fbf-4a5f-b175-6e0ffd0d0787.jpg?1562610639"))
    cards.append(Card(name="Verdant Catacombs", image="https://img.scryfall.com/cards/large/front/7/a/7abd2723-2851-4f1a-b2d0-dfcb526472c3.jpg?1562613630"))
    cards.append(Card(name="Windswept Heath", image="https://img.scryfall.com/cards/large/front/7/a/7a7c5941-9c8a-4a40-9efb-a84f05c58e53.jpg?1562923899"))
    cards.append(Card(name="Bayou", image="https://img.scryfall.com/cards/normal/front/1/7/17db2b6a-eaa8-4a08-9e86-370bbd058574.jpg?1559591871"))
    cards.append(Card(name="Cavern of Souls", image="https://img.scryfall.com/cards/large/front/1/3/1381c8f1-a292-4bdf-b20c-a5c2a169ee84.jpg?1561857492"))
    cards.append(Card(name="Dryad Arbor", image="https://img.scryfall.com/cards/large/front/8/c/8cee476d-42e1-4997-87af-73e18f542167.jpg?1562923491"))
    cards.append(Card(name="Forest", image="https://img.scryfall.com/cards/large/front/1/2/12a035fe-8847-4678-84f7-01bac77ae011.jpg?1583553465"))

    decks.append(Deck(deck_name='UW Control', createdAt=datetime(2020, 3, 18), user_id=1))
    decks.append(Deck(deck_name='Combo Elves', createdAt=datetime(2020, 3, 18), user_id=1))
    decks.append(Deck(deck_name='UW Control', createdAt=datetime(2020, 3, 18), user_id=2))
    decks.append(Deck(deck_name='UW Control', createdAt=datetime(2020, 3, 18), user_id=3))

    # UW Control (RTR Standard)
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=1, count=4))  # Azorius Charm
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=2, count=3))  # Dissolve
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=3, count=3))  # Doom Blade
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=4, count=4))  # Hero's Downfall
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=5, count=3))  # Sphinx's Revelation
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=6, count=4))  # Sphinx's Revelation
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=7, count=3))  # Detention Sphere
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=8, count=2))  # Elspeth, Sun's Champion
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=9, count=4))  # Jace, Architect of Thought
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=10, count=1))  # Aetherling
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=11, count=2))  # Blood Baron of Vizkopa
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=12, count=4))  # Godless Shrine
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=13, count=4))  # Hallowed Fountain
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=14, count=4))  # Island
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=15, count=2))  # Plains
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=16, count=4))  # Temple of Deceit
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=17, count=4))  # Temple of Silence
    deck_of_cards.append(Deck_Cards(deck_id=1, card_id=18, count=4))  # Watery Grave

    # Combo Elves (Legacy)
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=19, count=2))  # Birchlore Rangers
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=20, count=4))  # Heritage Druid
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=21, count=1))  # Elvish Mystic
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=22, count=4))  # Elvish Reclaimer
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=23, count=4))  # Elvish Visionary
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=24, count=1))  # Fyndhorn Elves
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=25, count=1))  # Llanowar Elves
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=26, count=1))  # Multani's Acolyte
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=27, count=4))  # Nettle Sentinel
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=28, count=4))  # Quirion Ranger
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=29, count=4))  # Wirewood Symbiote
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=30, count=2))  # Craterhoof Behemoth
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=31, count=3))  # Natural Order
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=32, count=4))  # Glimpse of Nature
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=33, count=4))  # Green Sun's Zenith
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=34, count=4))  # Gaea's Cradle
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=35, count=3))  # Misty Rainforest
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=36, count=3))  # Verdant Catacombs
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=37, count=2))  # Windswept Heath
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=38, count=2))  # Bayou
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=39, count=1))  # Cavern of Souls
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=40, count=2))  # Dryad Arbor
    deck_of_cards.append(Deck_Cards(deck_id=2, card_id=41, count=3))  # Forest

    for playset in deck_of_cards:
        db.session.add(playset)

    for deck in decks:
        db.session.add(deck)

    for card in cards:
        db.session.add(card)
    db.session.commit()
    print('DB deleted & reseeded!')
Пример #30
0
def create_db():
    db.delete(session.Session)
    db.delete(registration.Registration)
    db.delete(notification.Notification)
    db.delete(contact.Contact)
    db.delete(event.Event)
    db.delete(organization.Organization)
    db.delete(user.User)

    db.create_all()

    test_contact = contact.Contact(dob=datetime.utcnow(),
                                   phone=123456,
                                   address="123 South st, City",
                                   state="California",
                                   zipcode=90732,
                                   country="USA")
    test_contact1 = contact.Contact(dob=datetime.utcnow(),
                                    phone=7146523,
                                    address="123 Harbor st, City",
                                    state="California",
                                    zipcode=90882,
                                    country="USA")
    db.session.add(test_contact)
    db.session.add(test_contact1)

    test_user = user.User(password="******",
                          email="*****@*****.**",
                          name="Phuong Nguyen")

    test_user1 = user.User(password="******",
                           email="*****@*****.**",
                           name="Khuong Le")

    test_user2 = user.User(password="******",
                           email="*****@*****.**",
                           name="Josh")

    db.session.add(test_user)
    db.session.add(test_user1)

    test_org = organization.Organization(org_name="Computer Science Society",
                                         categories="CS",
                                         contact=test_contact)

    test_org1 = organization.Organization(
        org_name="Software Engineer Association",
        categories="CS",
        contact=test_contact1)
    db.session.add(test_org)
    db.session.add(test_org1)

    test_role = role.Role(user=test_user,
                          organization=test_org,
                          role=role.Roles.CHAIRMAN)

    test_role1 = role.Role(user=test_user1,
                           organization=test_org1,
                           role=role.Roles.CHAIRMAN)

    test_role2 = role.Role(user=test_user2,
                           organization=test_org,
                           role=role.Roles.ADMIN)

    db.session.add(test_role)
    db.session.add(test_role1)
    db.session.add(test_role2)

    temp_id = db.session.query(user.User).first()
    test_session = session.Session(user_id=temp_id.user_id,
                                   expires=datetime.now())

    db.session.add(test_session)

    test_event = event.Event(creator=test_user,
                             organization=test_org,
                             event_name='ADMIN testing',
                             start_date=datetime.now(tz=None),
                             end_date=datetime.now(tz=None),
                             theme='Training',
                             perks='Perks',
                             categories="info",
                             info='categories',
                             phase=event.EventPhase.INITIALIZED,
                             contact=test_contact)

    test_event1 = event.Event(creator=test_user1,
                              organization=test_org1,
                              event_name='CHAIRMAN testing',
                              start_date=datetime.now(tz=None),
                              end_date=datetime.now(tz=None),
                              theme='Training',
                              perks='Perks',
                              categories="info",
                              info='categories',
                              phase=event.EventPhase.APPROVED,
                              contact=test_contact1)

    test_event2 = event.Event(creator=test_user1,
                              organization=test_org1,
                              event_name='CHAIRMAN testing gg',
                              start_date=datetime.now(tz=None),
                              end_date=datetime.now(tz=None),
                              theme='Training',
                              perks='Perks',
                              categories="info",
                              info='categories',
                              phase=event.EventPhase.ARCHIVED,
                              contact=test_contact1)
    db.session.add(test_event)
    db.session.add(test_event1)
    db.session.add(test_event2)

    db.session.commit()
Пример #31
0
def create_db():
    if not os.path.isdir(db_path):
        os.makedirs(db_path)
    db.create_all()
Пример #32
0
def create_testdb():
	db.create_all()
	return 'created tables'
Пример #33
0
import os
from flask import Flask
from config import db, app
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from flask_sqlalchemy import SQLAlchemy
from models.reports import Reports
from models.mail_model import Mail
from models.schedulelog import ScheuleLog
from models.schedulertiming import TimingSchedule
from models.reportsCategory import ReportsCategory
from models.notifications import Notifications

migrate = Migrate(app, db)
app.app_context().push()
db.init_app(app)
db.create_all(app=app)
db.session.commit()

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

if __name__ == '__main__':
    manager.run()
Пример #34
0
def create_db():
    """need to run this just ONCE to create the database
    """
    db.create_all()
Пример #35
0
def main():
    # get args
    parser = argparse.ArgumentParser(description='Build the WiFace database')
    parser.add_argument(
        '--nb_person',
        help='How many people do you want to create in the simulation?',
        default=50,
        type=int)
    parser.add_argument(
        '--duration',
        help='How long should the simulation last ? (in minutes)',
        default=600,
        type=int)
    parser.add_argument('--simulation',
                        help='Boolean if you want to include a simulation',
                        action='store_true')

    args = parser.parse_args()

    collection_id = app.config['COLLECTION_NAME']
    delete_collection(collection_id, client)
    create_collection(collection_id, client)

    # Data to initialize database with
    xmldoc = minidom.parse('vendors.xml')
    VendorsList = xmldoc.getElementsByTagName('VendorMapping')

    MACS = [{
        "address": "11:11:11:11:11:11",
        "isRandom": False,
        "fk_vendor": "DC:F0:90",
        "PP2I": False
    }, {
        "address": "22:22:22:22:22:22",
        "isRandom": True,
        "fk_vendor": "E0:02:A5",
        "PP2I": True
    }, {
        "address": "33:33:33:33:33:33",
        "isRandom": False,
        "fk_vendor": "FC:F8:AE",
        "PP2I": True
    }, {
        "address": "44:44:44:44:44:44",
        "isRandom": False,
        "fk_vendor": "FC:F8:AE",
        "PP2I": True
    }]

    PLACES = [{
        "id": 1,
        "name": "BatCave",
        "longitude": 6.869948,
        "latitude": 46.457080
    }, {
        "id": 2,
        "name": "Toussaint",
        "longitude": 22,
        "latitude": 9
    }, {
        "id": 3,
        "name": "Aperture Science",
        "longitude": 42,
        "latitude": 42
    }]

    USERS = [{
        "email": "Obyka",
        "password": User.hash("***REMOVED***"),
        "admin": True,
        "fk_place": 1
    }, {
        "email": "Raspberry",
        "password": User.hash("***REMOVED***"),
        "admin": False,
        "fk_place": 2
    }]

    IDENTITIES = [{
        "id": 1,
        "firstname": "Bruce",
        "lastname": "Wayne",
        "mail": "batman",
        "uuid": "f8d9c454-443e-45d0-937f-17b676dd6fde",
        "PP2I": False
    }, {
        "id": 2,
        "firstname": "Clark",
        "lastname": "Kent",
        "mail": "superman",
        "uuid": "3cf2fca0-f743-415b-ac3d-728121d64bae",
        "PP2I": True
    }, {
        "id": 3,
        "firstname": "Tony",
        "lastname": "Stark",
        "mail": "ironman",
        "uuid": "629fa6e3-4b6b-49d4-abef-29829c1f860e",
        "PP2I": False
    }, {
        "id": 4,
        "firstname": "Diana",
        "lastname": "Prince",
        "mail": "wonderwoman",
        "uuid": "729fa6e3-4b6b-49d4-abef-29829c1f860e",
        "PP2I": False
    }]

    probe_time = timedelta(minutes=(2))
    batman_time = datetime.now() - timedelta(minutes=(5))
    superman_time = batman_time - timedelta(minutes=(20))
    ironman_time = batman_time - timedelta(minutes=(25))
    wonderwoman = ironman_time

    PICTURES = [
        {
            "id": 1,
            "picPath": "batman.jpg",
            "timestamp": batman_time,
            "fk_place": 1
        },
        {
            "id": 2,
            "picPath": "superman.jpg",
            "timestamp": superman_time,
            "fk_place": 1
        },
        {
            "id": 3,
            "picPath": "ironman.jpg",
            "timestamp": ironman_time,
            "fk_place": 1
        },
        {
            "id": 4,
            "picPath": "wonderwoman.jpg",
            "timestamp": wonderwoman,
            "fk_place": 2
        },
        {
            "id": 5,
            "picPath": "batman_no_mac.jpg",
            "timestamp": batman_time - timedelta(hours=1),
            "fk_place": 1
        },
    ]

    PROBES = [{
        "ssid": "probe_ssid_1",
        "timestamp": batman_time + probe_time,
        "fk_mac": "11:11:11:11:11:11",
        "fk_place": 1
    }, {
        "ssid": "probe_ssid_2",
        "timestamp": batman_time - probe_time,
        "fk_mac": "11:11:11:11:11:11",
        "fk_place": 2
    }, {
        "ssid": "probe_ssid_3",
        "timestamp": superman_time + probe_time,
        "fk_mac": "22:22:22:22:22:22",
        "fk_place": 1
    }, {
        "ssid": "probe_ssid_3",
        "timestamp": superman_time - probe_time,
        "fk_mac": "22:22:22:22:22:22",
        "fk_place": 1
    }, {
        "ssid": "probe_ssid_1",
        "timestamp": ironman_time + probe_time,
        "fk_mac": "33:33:33:33:33:33",
        "fk_place": 1
    }, {
        "ssid": "probe_ssid_2",
        "timestamp": ironman_time - probe_time,
        "fk_mac": "33:33:33:33:33:33",
        "fk_place": 1
    }, {
        "ssid": "probe_ssid_3",
        "timestamp": wonderwoman + probe_time,
        "fk_mac": "44:44:44:44:44:44",
        "fk_place": 1
    }, {
        "ssid": "probe_ssid_3",
        "timestamp": wonderwoman - probe_time,
        "fk_mac": "44:44:44:44:44:44",
        "fk_place": 1
    }]
    REPRENSENTS = [{
        "probability": 100,
        "fk_identity": 1,
        "fk_picture": 1
    }, {
        "probability": 100,
        "fk_identity": 1,
        "fk_picture": 5
    }, {
        "probability": 100,
        "fk_identity": 2,
        "fk_picture": 2
    }, {
        "probability": 100,
        "fk_identity": 3,
        "fk_picture": 3
    }, {
        "probability": 100,
        "fk_identity": 4,
        "fk_picture": 4
    }]

    # Delete database file if it exists currently
    if os.path.exists('probes.db'):
        os.remove('probes.db')

    # Create the database
    db.create_all()

    for vendor in VendorsList:
        v = Vendors(name=vendor.attributes['vendor_name'].value,
                    oui=vendor.attributes['mac_prefix'].value.upper())
        # print(vendor.attributes['mac_prefix'].value.upper())
        db.session.add(v)
    db.session.flush()

    for place in PLACES:
        p = Places(id=place['id'],
                   name=place['name'],
                   latitude=place['latitude'],
                   longitude=place['longitude'])
        db.session.add(p)
    db.session.flush()

    for user in USERS:
        u = User(email=user['email'],
                 password=user['password'],
                 admin=user['admin'],
                 fk_place=user['fk_place'])
        db.session.add(u)
    db.session.flush()

    if args.simulation:
        simulation.launch_simulation(args.nb_person, args.duration)
    else:
        for mac in MACS:
            m = MacAddress(address=mac['address'],
                           isRandom=mac['isRandom'],
                           fk_vendor=mac['fk_vendor'],
                           PP2I=mac['PP2I'])
            db.session.add(m)
        db.session.flush()

        for probe in PROBES:
            p = Probes(ssid=probe['ssid'],
                       timestamp=probe['timestamp'],
                       fk_mac=probe['fk_mac'],
                       fk_place=probe['fk_place'])
            db.session.add(p)
        db.session.flush()

        for identity in IDENTITIES:
            i = Identities(id=identity['id'],
                           firstname=identity['firstname'],
                           lastname=identity['lastname'],
                           mail=identity['mail'],
                           uuid=identity['uuid'],
                           PP2I=identity['PP2I'])
            db.session.add(i)
        db.session.flush()

        for picture in PICTURES:
            p = Pictures(id=picture['id'],
                         picPath=picture['picPath'],
                         timestamp=picture['timestamp'],
                         fk_place=picture['fk_place'])
            db.session.add(p)
        db.session.flush()

        for represents in REPRENSENTS:
            r = Represents(probability=represents['probability'],
                           fk_identity=represents['fk_identity'],
                           fk_picture=represents['fk_picture'])
            db.session.add(r)
        db.session.flush()
        db.session.commit()
Пример #36
0
import os
from config import db
from models import Person

# Data to initialize database with
PEOPLE = [
    {"fname": "Jayant", "lname": "Sachdev"},
    {"fname": "Goyal", "lname": "Goyal"},
    {"fname": "Bunny", "lname": "Easter"},
]

# Delete database file if it exists currently
if os.path.exists("people.db"):
    os.remove("people.db")

print(db)
# Create the database
db.create_all()

# iterate over the PEOPLE structure and populate the database
for person in PEOPLE:
    p = Person(lname=person.get("lname"), fname=person.get("fname"))
    db.session.add(p)

db.session.commit()
Пример #37
0
def create_tables():
    db_path = app.config['SQLALCHEMY_DATABASE_URI']
    if os.path.exists(db_path):
        os.unlink(app.config['SQLALCHEMY_DATABASE_URI'])
    db.create_all()
    populate_example_data()