def migrate_tasks():
    with sqlite3.connect(DATABASE_PATH) as connection:
        c = connection.cursor()

        # temporarily change the target of the migrations (tasks)
        c.execute("""
              ALTER TABLE tasks RENAME TO old_tasks
              """)

        # recreate a new tasks table with the updated schema
        db.create_all()

        # retrieve data from the old_tasks table
        c.execute("""
              SELECT name, due_date, priority, status
              FROM old_tasks
              ORDER BY task_id ASC
              """)
        """
     save all the rows as a list of tuples and set the posted_date to now and user_id to 1
    """
        data = [(row[0], row[1], row[2], row[3], datetime.now(), 1)
                for row in c.fetchall()]

        c.executemany(
            """
                   INSERT INTO tasks (name, due_date, priority, status, posted_date, user_id) VALUES (?, ?, ?, ?, ?, ?)
                   """, data)

        # delete old_tasks table
        c.execute("DROP TABLE old_tasks")
예제 #2
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
         os.path.join(basedir, TEST_DB)
     self.app = app.test_client()
     db.create_all()
def migrate_users():
    with sqlite3.connect(DATABASE_PATH) as connection:
        c = connection.cursor()

        # temporarily change the target of the migrations (users)
        c.execute("""
              ALTER TABLE users RENAME TO old_users
              """)

        # recreate a new users table with the updated schema
        db.create_all()

        # retrieve data from the old_users table
        c.execute("""
              SELECT name, email, password
              FROM old_users
              ORDER BY id ASC
              """)
        """
     save all the rows as a list of tuples and set the role to 'user'
    """
        data = [(row[0], row[1], row[2], "user") for row in c.fetchall()]

        c.executemany(
            """
                   INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)
                   """, data)

        # delete old_tasks table
        c.execute("DROP TABLE old_users")
예제 #4
0
 def setUp(self):
     app.config["TESTING"] = True
     app.config["WTF_CSRF_ENABLED"] = False
     app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///" + \
         os.path.join(basedir, TEST_DB)
     self.app = app.test_client()
     db.create_all()
예제 #5
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
         os.path.join(basedir, TEST_DB)
     self.app = app.test_client()
     db.create_all()
예제 #6
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
         os.path.join(BASE_DIR, TEST_DB)
     self.app = app.test_client()  # mocks out the entire Flask app
     db.create_all()
예제 #7
0
def createall():
    db.create_all()
    f = open("static/默认数据.txt","r",encoding="utf-8")
    for line in f.readlines():
        if line:
            db.session.execute(line)
    f.close()
    db.session.commit()
예제 #8
0
    def setUp(self):
        app.config['TESTING'] = True
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(basedir, TEST_DIR)
        self.app = app.test_client()
        db.create_all()

        self.michaelUser = ('Michael', '*****@*****.**', 'python', 'python')
예제 #9
0
 def setUp(self):
     # Reset the values in original config app
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+ os.path.join(basedir, DATABASE_NAME)
     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
     # Mock the app Object to provide fake attributes/methods.
     self.app = app.test_client()
     db.create_all()
예제 #10
0
파일: tests.py 프로젝트: powerlanguage/mog
    def setUp(self):
        """Set up."""
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
            os.path.join(basedir, TEST_DB)
        self.app = app.test_client()
        db.create_all()

        self.assertEquals(app.debug, False)
 def setUp(self):
     """
         Executing prior to each tasks.
         Create environnement where tests while be executing.
     """
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
                                             os.path.join(basedir, TEST_DB)
     self.app = app.test_client()
     db.create_all()
예제 #12
0
 def setUp(self):
     db.create_all()
     # Adding Users
     user = User(name='user1', email="*****@*****.**")
     user2 = User(name='user2',  email="*****@*****.**")
     user3 = User(name='user3',  email="*****@*****.**")
     db.session.add_all([user, user2, user3])
     # Adding Families
     family = Family(name='Family-name-1', members=[user, user2])
     family2 = Family(name='Family-name-2', members=[user, user3])
     db.session.add_all([family, family2, user3])
     # Adding Fridges
     fridge = Fridge()
     fridge2 = Fridge()
     db.session.add_all([fridge, fridge2])
     family.fridge = fridge
     family2.fridge = fridge2
     # Adding Grocery Lists
     grocery_list = GroceryList(name="listname1")
     grocery_list2 = GroceryList(name="listname2")
     grocery_list3 = GroceryList(name="listname3")
     db.session.add_all([grocery_list, grocery_list2, grocery_list3])
     family.grocery_lists.append(grocery_list)
     family.grocery_lists.append(grocery_list2)
     family2.grocery_lists.append(grocery_list3)
     db.session.commit()
     # Adding items
     item1 = Item(name="item1", family_pk=family.pk)
     item2 = Item(name="item2", family_pk=family.pk)
     item3 = Item(name="item3", family_pk=family.pk)
     item4 = Item(name="item4", family_pk=family2.pk)
     item5 = Item(name="item5", family_pk=family2.pk)
     db.session.add_all([item1, item2, item3, item4, item5])
     # Adding items to fridge
     fridge.items.append(item1)
     fridge2.items.append(item2)
     # Adding items to grocery lists
     grocery_list.items.append(item3)
     grocery_list3.items.append(item4)
     grocery_list3.items.append(item5)
     db.session.commit()
예제 #13
0
def init_database():
    # create the database tables
    with app.app_context():
        db.create_all()

        # insert sample data
        source = CedSource(
            id="datacite", display_name="DataCite", icon_url="datacite.png"
        )
        event1 = CedEvent(
            id="peeZ2knsGxRzvuw4NVW6",
            doi="10.1039/c5ce01901j",
            api_raw=dict(
                {
                    "id": "80c78ffb-8d32-4de7-8023-1187dffdaef2",
                    "terms": "https://doi.org/10.13003/CED-terms-of-use",
                    "obj_id": "https://doi.org/10.1039/c5ce01901j",
                    "license": "https://creativecommons.org/publicdomain/zero/1.0/",
                    "subj_id": "https://doi.org/10.5517/cc13t0gd",
                    "source_id": "datacite",
                    "timestamp": "2017-06-28T04:23:34Z",
                    "occurred_at": "2014-12-01T14:09:33Z",
                    "source_token": "28276d12-b320-41ba-9272-bb0adc3466ff",
                    "message_action": "create",
                    "relation_type_id": "is_supplement_to",
                }
            ),
            occurred_at=datetime.strptime("2014-12-01", "%Y-%m-%d"),
            normalized_subj_id="https://doi.org/10.5517/cc13t0gd",
            uniqueness_key="08d64da78ed5223c2329d00350727581",
        )
        event2 = CedEvent(
            id="XnXvJVPNq2FkWD4VD6uv",
            doi="10.1039/c5ce01901j",
            api_raw=dict(
                {
                    "id": "4d6a48be-6d51-4d4b-be91-4d5929fa0ba0",
                    "terms": "https://doi.org/10.13003/CED-terms-of-use",
                    "obj_id": "https://doi.org/10.1039/c5ce01901j",
                    "license": "https://creativecommons.org/publicdomain/zero/1.0/",
                    "subj_id": "https://doi.org/10.5517/cc13t0hf",
                    "source_id": "datacite",
                    "timestamp": "2017-06-28T04:23:34Z",
                    "occurred_at": "2014-12-01T14:09:34Z",
                    "source_token": "28276d12-b320-41ba-9272-bb0adc3466ff",
                    "message_action": "create",
                    "relation_type_id": "is_supplement_to",
                }
            ),
            occurred_at=datetime.strptime("2014-12-01", "%Y-%m-%d"),
            normalized_subj_id="https://doi.org/10.5517/cc13t0hf",
            uniqueness_key="2ed6a1381d65683ec3c1ddf575d7709a",
        )
        db.session.add(source)
        db.session.add(event1)
        db.session.add(event2)

        # Commit the changes
        db.session.commit()

        yield db

        # remove tables
        db.session.remove()
        db.drop_all()
예제 #14
0
from views import db
from models import Task
from datetime import date

# create the database and the db table


db.create_all()  # initialize the database shcema

# insert data

db.session.add(Task("Finish this tutorial", date(2015, 3, 13), 10, 1))
db.session.add(Task("fishish realpython", date(2015, 3, 13), 10, 1))
# populate te table with data via the Task object form models.py to specify the schema

# commit the changes

db.session.commit()
# to apply the previous thanges we commit
예제 #15
0
# -*- coding:utf-8 -*-
from views import db
from views import init_app
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager

app = init_app()

db.create_all(app=app)
manager = Manager(app)
migrate = Migrate(app, db)
manager.add_command('db', MigrateCommand)
manager.run()
예제 #16
0
from views import db
from models import Task
from datetime import date

# Create the database and tables
db.create_all()

# Insert data
db.session.add(Task('Finish this tutorial', date(2015, 03, 06), 10, 1))
db.session.add(Task('Finish this course', date(2015, 04, 06), 10, 1))

# Commit the changes
db.session.commit()

예제 #17
0
 def setUp(self):
     db.create_all()