Example #1
0
 def tearDown(self):
     """
     Executed after each test
     Has to be in this awkward camelCase to overload method in TestCase
     """
     # drop all tables so they're recreated in the setUp method
     drop_db()
Example #2
0
    def test_500_get_projects_server_error(self):
        ''' Test get projects '''
        drop_db()  # delete table ahead of request
        res = self.client().get('/projects')
        data = json.loads(res.data)

        self.assertEqual(res.status_code, 500)
        self.assertEqual(data['success'], False)
        self.assertEqual(data['messages'], 'failed to query projects')
Example #3
0
    def test_500_add_project_server_error(self):
        ''' Test adding a new project '''
        drop_db()  # delete table ahead of request
        res = self.client().post('/projects', json=self.project_example)
        data = json.loads(res.data)

        self.assertEqual(res.status_code, 500)
        self.assertEqual(data['success'], False)
        self.assertEqual(data['messages'], 'failed to add new project')
Example #4
0
def test_create_user():
    engine = setup_db("test")
    session = create_session(engine)

    user = User()
    user.name = "Alex"
    session.add(user)
    session.commit()
    users = session.query(User).all()
    assert len(users) == 1

    drop_db(engine)
Example #5
0
    def setUp(self):
        """Define test variables and initialize app."""
        self.maxDiff = None
        self.app = create_app()
        self.client = self.app.test_client
        self.database_name = "bookshelf_test"
        self.database_path = "postgresql://{}:{}@{}/{}".format(
            'student', 'student', 'localhost:5432', self.database_name)
        drop_db(self.app, self.database_path)
        setup_db(self.app, self.database_path)

        # binds the app to the current context
        with self.app.app_context():
            self.db = SQLAlchemy()
            self.db.init_app(self.app)
            # create all tables
            self.db.create_all()
Example #6
0
def delete_all():
    drop_db()
Example #7
0
import models

from flask import Flask, jsonify
app = Flask(__name__)


@app.route('/')
@app.route('/home', methods=['GET'])
def home():
    data = {
        'message': 'Hello, World!',
        'developer': models.User.getUserWithUsername('develop').to_json()
    }

    return jsonify(**data)


# run the app.
if __name__ == "__main__":
    # reset the entire database before launching the web application
    models.drop_db()
    models.init_db()

    # Setting debug to True enables debug output. This line should be
    # removed before deploying a production app.
    app.debug = True
    app.run(port=3000)
Example #8
0
 def tearDown(self):
     ''' Executed after each test '''
     drop_db()