コード例 #1
0
    def setUp(self):
        self.app = create_app()
        self.client = self.app.test_client
        setup_db(self.app, 'trivia_test')

        db.drop_all()
        db.create_all()

        self.temp_categories = [
            Category('Science'),
            Category('Art'),
            Category('Geography'),
            Category('History'),
            Category('Entertainment'),
            Category('Sports')
        ]

        self.temp_questions = [
            Question('Whose autobiography is entitled \'I Know Why the Caged Bird Sings\'?', 'Maya Angelou', 2, 4),
            Question('What boxer\'s original name is Cassius Clay?', 'Muhammad Ali', 1, 4),
            Question('The Taj Mahal is located in which Indian city?', 'Agra', 2, 3),
            Question('Which Dutch graphic artist–initials M C was a creator of optical illusions?', 'Escher', 1, 2),
            Question('What is the heaviest organ in the human body?', 'The Liver', 4, 1)
        ]

        db.session.add_all(self.temp_categories)
        db.session.add_all(self.temp_questions)
        db.session.commit()
コード例 #2
0
ファイル: base.py プロジェクト: DustinFischer/udacity-fsnd
    def setUp(self):
        self.app = create_app(TestConfig)
        self.client = self.app.test_client()
        self.app_context = self.app.app_context()
        self.app_context.push()

        db.drop_all()
        setup_db()
コード例 #3
0
def app():
    app = create_app(
        test_config={
            'TESTING': True,
            'SQLALCHEMY_DATABASE_URI':
            'postgresql://jlu@localhost:5432/trivia_test',
            'SQLALCHEMY_TRACK_MODIFICATIONS': False
        })
    # populate test database with test data
    db.engine.execute(_data_sql)
    yield app

    print('app teardown')
    db.drop_all()
    # db.engine.execute('DROP TABLE questions; DROP TABLE categories;')
    db.session.close()
コード例 #4
0
    def test_get_categories_fail_no_categories(self):
        db.drop_all()
        db.create_all()

        res = self.client().get('/categories')

        status = res.status_code
        data = json.loads(res.data)

        # check status and data
        self.assertEqual(status, 404)
        self.assertTrue('success' in data)
        self.assertTrue('error' in data)
        self.assertTrue('description' in data)
        self.assertTrue('message' in data)

        # check success
        self.assertFalse(data['success'])
        self.assertEqual(data['error'], 404)
        self.assertEqual(data['description'], 'no categories found')
        self.assertEqual(data['message'], 'not found')
コード例 #5
0
ファイル: base.py プロジェクト: DustinFischer/udacity-fsnd
 def tearDown(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()
コード例 #6
0
 def tearDown(self):
     with self.app.app_context():
         db.session.remove()
         db.drop_all()
コード例 #7
0
 def tearDown(self):
     """Executed after reach test"""
     db.session.remove()
     db.drop_all()
コード例 #8
0
def create_db():
    db.drop_all()
    db.create_all()
    db.session.commit()
    print('Done\n')
コード例 #9
0
 def tearDown(self):
     db.drop_all()
コード例 #10
0
 def tearDownClass(cls):
     """Executed after all tests"""
     db.drop_all()