Skip to content

Commit

Permalink
Adds test for creating a database after the API.
Browse files Browse the repository at this point in the history
The added test is only for Flask-SQLAlchemy.
  • Loading branch information
jfinkels committed Apr 28, 2016
1 parent abd4f50 commit 1bcc0b6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,28 @@ class Person(self.db.Model):
id = self.db.Column(self.db.Integer, primary_key=True)

self.Person = Person
self.db.create_all()

def test_init_app(self):
self.db.create_all()
manager = APIManager(flask_sqlalchemy_db=self.db)
manager.create_api(self.Person)
manager.init_app(self.flaskapp)
response = self.app.get('/api/person')
assert response.status_code == 200

def test_create_api_before_db_create_all(self):
"""Tests that we can create APIs before
:meth:`flask.ext.sqlalchemy.SQLAlchemy.create_all` is called.
"""
manager = APIManager(self.flaskapp, flask_sqlalchemy_db=self.db)
manager.create_api(self.Person)
self.db.create_all()
person = self.Person(id=1)
self.db.session.add(person)
self.db.session.commit()
response = self.app.get('/api/person/1')
assert response.status_code == 200
document = loads(response.data)
person = document['data']
assert '1' == person['id']

0 comments on commit 1bcc0b6

Please sign in to comment.