def client(app):
    app_context = app.app_context()
    app_context.push()
    db.create_all()

    mock = patch('dataservice.extensions.flask_indexd.requests')
    mock = mock.start()
    indexd_mock = MockIndexd()
    mock.Session().get.side_effect = indexd_mock.get
    mock.Session().post.side_effect = indexd_mock.post

    mod = 'dataservice.api.study.models.requests'
    mock_bs = patch(mod)
    mock_bs = mock_bs.start()

    mock_resp_get = MagicMock()
    mock_resp_get.status_code = 200
    mock_resp_post = MagicMock()
    mock_resp_post.status_code = 201

    mock_bs.Session().get.side_effect = mock_resp_get
    mock_bs.Session().post.side_effect = mock_resp_post

    yield app.test_client()

    mock_bs.stop()
    mock.stop()
    # Need to make sure we close all connections so pg won't lock tables
    db.session.close()
    db.drop_all()
Ejemplo n.º 2
0
 def drop_all(self):
     db.session.remove()
     db.drop_all()
     self.app_context.pop()