示例#1
0
    def tearDown(self):
        """TODO: Docstring for tearDown.
        :returns: TODO

        """
        db.session.remove()
        db.drop_all()
 def setUp(self):
     app.config['TESTING'] = True
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, TEST_DB)
     app.config['WTF_CSRF_ENABLED'] = False
     self.app = app.test_client()
     db.drop_all()
     db.create_all()
示例#3
0
    def tearDown(self):
    	db.session_remove()
    	db.drop_all()


	########################
	#### helper methods ####
	########################

	def add_tasks(self):
		db.session.add(
			Task(
				"Run around in circles",
				date(2015, 10, 22),
				10,
				date(2015, 10, 5),
				1,
				1
			)
		)

		db.session.commit()

		db.session.add(
			Task(
				"Purchase Real Python",
				date(2016, 2, 23),
				10,
				date(2016, 2, 7),
				1,
				1
			)
		)
		db.session.commit()
示例#4
0
 def tearDown(self):
     """
         Executing after each task.
         Clean environnement.
     """
     db.session.remove()
     db.drop_all()
示例#5
0
 def setUp(self):
     # create all the database tables before each test
     db.drop_all()
     db.create_all()
     db.session.add(User("admin", "password"))
     db.session.add(Feature("layered rocks", "rock123.jpg", "layered_rocks"))
     db.session.add(Feature("blueberries", "blueberries123.jpg", "blueberries"))
     db.session.add(Photo("mars.jpg", "mars1234", datetime.datetime.now()))
     db.session.commit()
示例#6
0
文件: models.py 项目: gooopy/template
def seed():

    db.drop_all()
    db.create_all()

    sample = DDL("sample", ",", "\\n")
    if not DDL.query.filter_by(title="sample").first():
        db.session.add(sample)

    sample = DDL.query.filter_by(title="sample").first()

    attributes = []

    attr = Attribute("order_num", "integer", False, None)
    attributes.append(attr)

    attr = Attribute("id", "string", False, None)
    attributes.append(attr)

    attr = Attribute("post_code", "string", False, None)
    attributes.append(attr)

    attr = Attribute("age", "integer", False, None)
    attributes.append(attr)

    attr = Attribute("ip", "string", False, None)
    attributes.append(attr)

    attr = Attribute("buy_date", "string", False, None)
    attributes.append(attr)

    attr = Attribute("total_price", "integer", False, None)
    attributes.append(attr)

    attr = Attribute("itemcode", "integer", False, None)
    attributes.append(attr)

    attr = Attribute("buy_good_count", "integer", False, None)
    attributes.append(attr)

    attr = Attribute("buy_good_price", "integer", False, None)
    attributes.append(attr)

    attr = Attribute("good_cate", "string", False, None)
    attributes.append(attr)

    for a in attributes:
        a.ddl_id = sample.id
        db.session.add(a)

    #preprocessed = DDL("preprocessed", "")


    db.session.commit()
示例#7
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
def recreate_db():
    """Recreates a database."""
    db.drop_all()
    db.create_all()
    db.session.commit()
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
示例#10
0
def test_database():
    db.create_all()
    yield db  # this is where the testing happens
    db.session.remove()
    db.drop_all()
示例#11
0
 def tearDown(self):
     """Executed after each test."""
     db.session.remove()
     db.drop_all()
示例#12
0
def drop_db():
    """Drops the table, you know that one thing they said never to do..."""
    db.drop_all()
示例#13
0
def test_db():
    db.create_all()
    yield db
    db.session.remove()
    db.drop_all()
示例#14
0
def recreate_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
    remove_all_note_templates()
示例#15
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self._remove_db_file()
示例#16
0
def test_db():
    db.create_all()
    yield db  # testing happens here
    db.session.remove()
    db.drop_all()
示例#17
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     file_dir = os.path.join(os.path.dirname(__file__), 'files')
     if os.path.isdir(file_dir):
         shutil.rmtree(file_dir)
示例#18
0
def recreate_db():
    # データベースを操るcursorはflaskインスタンスから,db = SQLAlchemy(app)と生成する事が一般的
    db.drop_all()  # 既存のdatabase削除
    db.create_all()  # 作成したクラス(テーブル)を実際にSQLite上に作成
    db.session.commit()
示例#19
0
文件: ghana.py 项目: doobeh/gsam
def wipe_them():
    db.drop_all()
    return "Oooo! They've Gone"
示例#20
0
def create_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
    return jsonify(success=True)
示例#21
0
class TestCase(unittest.TestCase):
    # executed prior to each test
    with app.app_context():
        db.drop_all()
        db.create_all()

    def setUp(self):
        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['DEBUG'] = False
        # app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
        #     os.path.join(app.config['BASEDIR'], TEST_DB)
        self.app = app.test_client()
        self.app.post('/api/v1/applicants',
                      data=json.dumps(
                          dict(first_name='bar',
                               last_name="Kirtfield",
                               school='VCU',
                               position='dev intern',
                               degree='eyesight')),
                      content_type='application/json',
                      follow_redirects=True)
        self.app.post('/api/v1/applicants',
                      data=json.dumps(
                          dict(first_name='Ryan',
                               last_name="Kirtfield",
                               school='Penn State',
                               position='dev intern',
                               degree='mathematics')),
                      content_type='application/json',
                      follow_redirects=True)
        self.app.post('/api/v1/applicants',
                      data=json.dumps(
                          dict(first_name='Little',
                               last_name="John",
                               school='VT',
                               position='dev intern',
                               degree='Health')),
                      content_type='application/json',
                      follow_redirects=True)
        self.app.post('/api/v1/applicants',
                      data=json.dumps(
                          dict(first_name='Lion',
                               last_name="Welsh",
                               school='Harvard',
                               position='dev intern',
                               degree='good')),
                      content_type='application/json',
                      follow_redirects=True)

    ####################
    ##POSTING ENTRIES###
    ####################

    def test_post_app1(self):
        tester = app.test_client(self)
        res = self.app.post('/api/v1/applicants',
                            data=json.dumps(
                                dict(first_name='bar',
                                     last_name="Kirtfield",
                                     school='VCU',
                                     position='dev intern',
                                     degree='eyesight')),
                            content_type='application/json',
                            follow_redirects=True)
        self.assertEqual(res.status_code, 201)

    def test_post_missing_fields(self):
        tester = app.test_client(self)
        res = self.app.post('/api/v1/applicants',
                            data=json.dumps(
                                dict(school='VCU',
                                     position='dev intern',
                                     degree='eyesight')),
                            content_type='application/json',
                            follow_redirects=True)
        self.assertEqual(res.status_code, 400)

    def test_post_invalid_position(self):
        tester = app.test_client(self)
        res = self.app.post('/api/v1/applicants',
                            data=json.dumps(
                                dict(school='VCU',
                                     position='cat caller',
                                     degree='eyesight')),
                            content_type='application/json',
                            follow_redirects=True)
        self.assertEqual(res.status_code, 400)

    ####################
    ##Testing Routes####
    ####################

    def test_index(self):
        tester = app.test_client(self)
        res = tester.get('/api/v1/applicants', content_type='application/json')
        self.assertEqual(res.status_code, 200)

    def test_index_without_json(self):
        tester = app.test_client(self)
        res = tester.get('/api/v1/applicants', content_type='application/json')
        self.assertEqual(res.status_code, 200)

    def test_fetch_application(self):
        tester = app.test_client(self)
        res = tester.get('/api/v1/applicants/2',
                         content_type='application/json')
        self.assertEqual(res.status_code, 200)

    ####################
    ##FETCHING DATA#####
    ####################
    def test_fetch_application_nonexist(self):
        tester = app.test_client(self)
        res = tester.get('/api/v1/applicants/200',
                         content_type='application/json')
        self.assertEqual(res.status_code, 404)

    def test_delete_nonexisting_index(self):
        tester = app.test_client(self)
        res = tester.delete('/api/v1/applicants/200 ',
                            content_type='application/json')
        self.assertEqual(res.status_code, 404)

    def test_delete_exists_index(self):
        tester = app.test_client(self)
        res = tester.delete('/api/v1/applicants/1',
                            content_type='application/json')
        self.assertEqual(res.status_code, 200)

    def test_fetch_application_nonexist_after_delete(self):
        tester = app.test_client(self)
        res = tester.get('/api/v1/applicants/1',
                         content_type='application/json')
        self.assertEqual(res.status_code, 404)

    ####################
    ##Updating ENTRIES##
    ####################

    def test_update_some_prop(self):
        tester = app.test_client(self)
        res = self.app.put('/api/v1/applicants/2',
                           data=json.dumps(dict(first_name='bar')),
                           content_type='application/json',
                           follow_redirects=True)
        self.assertEqual(res.status_code, 200)

    def test_update_all_prop(self):
        tester = app.test_client(self)
        res = self.app.put('/api/v1/applicants/2',
                           data=json.dumps(
                               dict(first_name='bar',
                                    last_name="Kirtfield",
                                    school='VCU',
                                    position='dev engineer',
                                    degree='eyesight')),
                           content_type='application/json',
                           follow_redirects=True)
        self.assertEqual(res.status_code, 200)

    ###########################
    ##TEST POST IN PUT METHOD##
    ###########################
    def test_wrong_method(self):
        tester = app.test_client(self)
        res = self.app.post('/api/v1/applicants/7',
                            data=json.dumps(
                                dict(first_name='bar',
                                     last_name="Kirtfield",
                                     school='VCU',
                                     position='dev engineer',
                                     degree='eyesight')),
                            content_type='application/json',
                            follow_redirects=True)
        self.assertEqual(res.status_code, 405)

    ###########################
    ##TEST POST IN GET METHOD##
    ###########################

    def test_wrong_method_post_in_get(self):
        tester = app.test_client(self)
        res = self.app.post('/api/v1/applicants/7',
                            data=json.dumps(
                                dict(first_name='bar',
                                     last_name="Kirtfield",
                                     school='VCU',
                                     position='dev engineer',
                                     degree='eyesight')),
                            content_type='application/json',
                            follow_redirects=True)
        self.assertEqual(res.status_code, 405)

    ###########################
    ##TEST PUT IN GET METHOD###
    ###########################

    def test_wrong_method_put_in_get(self):
        tester = app.test_client(self)
        res = self.app.put('/api/v1/applicants',
                           data=json.dumps(
                               dict(first_name='bar',
                                    last_name="Kirtfield",
                                    school='VCU',
                                    position='dev engineer',
                                    degree='eyesight')),
                           content_type='application/json',
                           follow_redirects=True)
        self.assertEqual(res.status_code, 405)

    ###########################
    ##TEST PUT WITH EMPTY######
    ###########################

    def test_wrong_method_put_empty(self):
        tester = app.test_client(self)
        res = self.app.put('/api/v1/applicants',
                           data=json.dumps(dict()),
                           content_type='application/json',
                           follow_redirects=True)
        self.assertEqual(res.status_code, 405)

    ###########################
    ##TEST SEARCH METHODS######
    ###########################
    def test_search_school(self):
        tester = app.test_client(self)
        res = self.app.get('/api/v1/applicants/school/vcu',
                           content_type='application/json',
                           follow_redirects=True)
        self.assertEqual(res.status_code, 200)

    def test_search_school_no_results(self):
        tester = app.test_client(self)
        res = self.app.get('/api/v1/applicants/school/lslslsls',
                           data=json.dumps(dict()),
                           content_type='application/json',
                           follow_redirects=True)
        self.assertEqual(res.status_code, 200)

    def test_seach_name(self):
        tester = app.test_client(self)
        res = self.app.get('/api/v1/applicants/lastname/kirtfield',
                           data=json.dumps(dict()),
                           follow_redirects=True)
        self.assertEqual(res.status_code, 200)

    def test_search_name_no_results(self):
        tester = app.test_client(self)
        res = self.app.get('/api/v1/applicants/lastname/jwoefjei',
                           data=json.dumps(dict()),
                           follow_redirects=True)
        self.assertEqual(res.status_code, 200)
示例#22
0
def recreate_db():
    '''Recreates a db.'''
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#23
0
def drop_db():
    """Drop database tables."""
    db.drop_all()
示例#24
0
def test_database():
    # db = project.db
    db.create_all()
    yield db  # testing here
    db.session.remove()
    db.drop_all()
示例#25
0
def drop_db():
    """Drops the db tables."""
    db.drop_all()
示例#26
0
def recreate_db():
    """ recreate the database """
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#27
0
def recreate_db():
    db.session.remove()
    db.drop_all()
    db.create_all()
def drop_db():
    """Drops the db tables"""
    db.drop_all()
示例#29
0
def test_database():
    db.ceates_all()
    yield db  #testing happens here
    db.session.remove()
    db.drop_all()
示例#30
0
def drop_db():
    db.drop_all()
    db.session.commit()
示例#31
0
from project import db
from project.models import Paper

# drop all of the existing database tables
db.drop_all()

# create the database and the database table
db.create_all()

# insert recipe data
#paper1 = Paper('db_create', 'init db')
#db.session.add(paper1)

# commit the changes
db.session.commit()
 def tearDown(self):
     """
         Executing after to each tasks.
         Clean environnement.
     """
     db.drop_all()
示例#33
0
def create_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#34
0
 def tearDown(self):
     db.session.remove()
     # removes all tables after each test
     db.drop_all()
示例#35
0
 def tearDown(self):
     db.drop_all()
示例#36
0
 def tearDown(self):
     # executes after each TestCase
     db.drop_all()
def recreate_db():
    """Delete all the data in the database and recreate all tables."""
    db.reflect()
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#38
0
def dropall():
    "Drops all database tables"
    if prompt_bool("Are you sure ? You will lose all your data !"):
        db.drop_all()
示例#39
0
 def tearDown(self):
     """Tear down test scenario."""
     db.session.remove()
     db.drop_all()
示例#40
0
def create_database():
    db.drop_all()
    db.create_all()
 def teardown():
     _db.session.remove()
     _db.drop_all()
示例#42
0
def recreate_db():
    """重新创建数据表."""
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#43
0
 def setUp(self):
     db.drop_all()
     db.create_all()
示例#44
0
def recreate_db():
    db.reflect()
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#45
0
 def tearDown(self):
     """Tear down tests."""
     db.session.remove()
     db.drop_all()
示例#46
0
 def tearDown(self):
     # executes after each TestCase
     db.drop_all()
示例#47
0
# -*- coding: utf-8 -*-
from project import db
import random
import datetime
from project.models import *

db.drop_all()
#luo db
db.create_all()
db.session.flush()

# 
u = User(u"ringuh", u"zerg", True)
db.session.add(u)

db.session.add(User(u"vieras", u"vieras"))
coms = [
	Sarjakuva( 	
		u"Oglaf", 
		u"oglaf", 
		u"http://oglaf.com", 
		u"Trydy Cooper, Doub Bayne", 
		1,
		u"http://oglaf.com/cumsprite/"
	),
	Sarjakuva(
		u"Fingerpori", 
		u"fingerpori",
		u"http://www.hs.fi/fingerpori", 
		u"Pertti Jarla", 
		2,
def recreate_db():
    """Recreates a database."""
    db.drop_all()
    db.create_all()
    db.session.commit()
示例#49
0
 def tearDown(self):
     db.drop_all()
示例#50
0
def drop_db():
    """Drops the db tables."""
    db.reflect()
    db.drop_all()
示例#51
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
示例#52
0
def drop_db():
    db.drop_all()