Esempio n. 1
0
def rig_test_client(data):
    with testing.postgresql.Postgresql() as postgresql:
        dburl = postgresql.url()
        engine = create_engine(dburl)
        setup_data(engine, data)
        app.config['SQLALCHEMY_DATABASE_URI'] = dburl
        yield app.test_client()
def test_handler_add_station_responses_404():
    test_data = {'station_id': 182, 'weekday': 7}
    headers = {'Content-Type': 'application/json'}
    with app.test_client() as client:
        response = client.post('/v1/users/-jbjbjnbk/stations/',
                               headers=headers,
                               data=json.dumps(test_data))
    assert response.status == '404 NOT FOUND'
Esempio n. 3
0
def authorized_client(
    users_service: UsersService, ) -> Generator[Client, None, None]:
    token = users_service.get_user_token()

    app.test_client_class = AuthorizedClient
    with app.test_client(token=token) as client:
        app.before_first_request_funcs = []
        yield client
def test_handler_users_stations_returns_correct_structure():
    with app.test_client() as client:
        response = client.get('/v1/stations/users/?from=35&to=66')
        json_data = response.get_json()
        user = json_data[0]
        assert 'email' in user
        assert 'id' in user
        assert 'name' in user
Esempio n. 5
0
 def test_post(self):
     with app.test_client() as c:
         rv = c.post('/api/auth',
                     json={
                         'username': '******',
                         'password': '******'
                     })
         json_data = rv.get_json()
         assert (json_data)
Esempio n. 6
0
 def setUp(self):
     self.app = app.test_client()
     token = jwt.encode(
         {
             'id_geral': 1,
             'exp':
             datetime.datetime.utcnow() + datetime.timedelta(minutes=40)
         }, app.config['SECRET_KEY'])
     self.headers = {'token': token}
Esempio n. 7
0
def test_handler_station_returns_correct_structure():
    with app.test_client() as client:
        response = client.get('/v1/stations/')
        json_data = response.get_json()
        station = json_data[0]
        assert 'active' in station
        assert 'id' in station
        assert 'line_id' in station
        assert 'name' in station
        assert 'order_on_line' in station
Esempio n. 8
0
def client():
    app.config["TESTING"] = True

    # mocker.patch.object(liquidity.LpClient, "get_quote", return_value=MOCK_QUOTE)
    # mocker.patch.object(
    #     liquidity.LpClient, "trade_and_execute", return_value=MOCK_TRADE
    # )
    # mocker.patch.object(liquidity.LpClient, "lp_details", return_value=MOCK_LP_DETAILS)
    with app.test_client() as client:
        yield client
Esempio n. 9
0
def test_handler_delete_station_responses_200():
    headers = {'Content-Type': 'application/json'}
    with app.test_client() as client:
        response = client.delete('/v1/users/4/stations/190/', headers=headers)
    assert response.status == '200 OK'

    records = db.session.query(UserStation).filter(
        UserStation.user_id == 4, UserStation.station_id == 190).all()

    assert len(records) == 0
Esempio n. 10
0
    def setUp(self):
        self.app = app.test_client()
        self.app_context = app.app_context()
        self.app_context.__enter__()
        db.drop_all()
        db.create_all()

        self.user1 = User('user1', '123456')
        self.user2 = User('user2', '123456')
        db.session.add(self.user1)
        db.session.add(self.user2)
        db.session.commit()
Esempio n. 11
0
def rig_test_client():
    with testing.postgresql.Postgresql() as postgresql:
        with app.app_context():
            dburl = postgresql.url()
            engine = create_engine(dburl)
            Base.metadata.create_all(engine)
            db_session.bind = engine
            user_datastore = SQLAlchemySessionUserDatastore(
                db_session, User, Role)
            app.config['SQLALCHEMY_DATABASE_URI'] = dburl
            app.config['WTF_CSRF_ENABLED'] = False
            init_app_with_options(user_datastore)
            yield app.test_client(), engine
Esempio n. 12
0
def test_handler_add_station_responses_200():
    test_data = {'station_id': 190, 'weekday': 7}
    headers = {'Content-Type': 'application/json'}
    with app.test_client() as client:
        response = client.post('/v1/users/4/stations/',
                               headers=headers,
                               data=json.dumps(test_data))
    assert response.status == '200 OK'

    records = db.session.query(UserStation).filter(
        UserStation.user_id == 4, UserStation.station_id == 190).all()

    assert len(records) == 1
Esempio n. 13
0
def client():
    import tempfile
    import shutil
    models_dir, results_dir = None, None
    try:
        models_dir = tempfile.mkdtemp(prefix='models_tmp')
        results_dir = tempfile.mkdtemp(prefix='results_tmp')
        app.config['MODELS_PATH'] = models_dir
        app.config['RESULTS_PATH'] = results_dir

        yield app.test_client()
    finally:
        # cleanup temp dirs, log errors instead of crashing
        shutil.rmtree(results_dir, onerror=cleanup_error)
        shutil.rmtree(models_dir, onerror=cleanup_error)
Esempio n. 14
0
    def setUp(self):
        db_user = app.config['DB_USERNAME']
        db_pass = app.config['DB_PASSWORD']
        db_host = app.config['DB_HOST']
        db_name = 'test_blog'
        self.db_uri = "mysql+pymysql://%s:%s@%s/" % (db_user, db_pass, db_host)

        app.config['TESTING'] = True
        app.config['WTF_CSRF_ENABLED'] = False
        app.config['BLOG_DATABASE_NAME'] = db_name
        app.config['SQLALCHEMY_DATABASE_URI'] = self.db_uri + db_name

        engine = sqlalchemy.create_engine(self.db_uri)
        conn = engine.connect()
        conn.execute("commit")
        conn.execute("CREATE DATABASE %s" % db_name)
        db.create_all()
        conn.close()

        self.app = app.test_client()
Esempio n. 15
0
 def test_ok(self):
     with app.test_client() as client:
         resp = client.get("/")
         self.assertEqual(resp.status_code, 200)
Esempio n. 16
0
def test_handler_station_responses_200():
    with app.test_client() as client:
        response = client.get('/v1/stations/')
        assert response.status == '200 OK'
        json_data = response.get_json()
        assert len(json_data) > 0
Esempio n. 17
0
def before_all(context):
    context.app = app.test_client()
Esempio n. 18
0
 def test_stuff(self):
     self.login('root', 'public')
     rv = self.app.get('/')
     rv.data
     with app.test_client():
         print User.query.all() # !!!!! ***** See ***** !!!!! 
Esempio n. 19
0
def app(db):
    """Set up the Flask test client"""

    return flask_app.test_client()
Esempio n. 20
0
 def setUp(self):
     self.app = app.test_client()
     db.create_all()
Esempio n. 21
0
def test_testing_endpoint():
    response = app.test_client().get("/testing")
    assert response.status_code == 200
Esempio n. 22
0
def test_it_can_serve_HTTP():
    browser = app.test_client()
    response = browser.get('/')
    assert response.status_code == 200
Esempio n. 23
0
def test_db_list():
    response = app.test_client().get("/db_list")
    assert response.status_code == 200
def test_handler_users_stations_responses_404():
    with app.test_client() as client:
        response = client.get('/v1/stations/users/?from=-58&to=abcd')
        assert response.status == '404 NOT FOUND'
Esempio n. 25
0
def test_db_choose():
    response = app.test_client().get("/db_choose/cmpd")
    assert response.status_code == 200
    response_data = json.loads(response.get_data().decode('utf-8'))
    assert response_data['result'] == app.config['DB_NAME']
def test_handler_users_stations_responses_200():
    with app.test_client() as client:
        response = client.get('/v1/stations/users/?from=35&to=66')
        assert response.status == '200 OK'
        json_data = response.get_json()
        assert len(json_data) > 0
Esempio n. 27
0
 def setUp(self):
     app.config.from_object('webapp.config.Testing')
     db.init_app(app)
     self.app = app.test_client()
 def create_app(self):
     self.app = app.test_client()
     return app
Esempio n. 29
0
 def test_inner(self):
     raise Exception("test error")
     with app.test_client() as client:
         resp = client.get("/")
         self.assertIn(b"masha", resp.data)
Esempio n. 30
0
 def setUp(self):
     self.debug = False
     self.client = app.test_client()
Esempio n. 31
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
sys.path.append("..")
from flask import *
from webapp import app, db
from webapp.apps.spamsub.models import *

app.testing = True
client = app.test_client()
ctx = app.test_request_context()
ctx.push()
print "app and db have been imported.\nYou have a test client: client,\nand a test request context: ctx"
Esempio n. 32
0
 def test_response_data(self):
     tester = app.test_client(self)
     response = tester.get('/foundme')
     self.assertEqual(response.data, b'You found me!')
Esempio n. 33
0
 def setUp(self):
     self.client = app.test_client()
Esempio n. 34
0
 def test_response(self):
     tester = app.test_client(self)
     response = tester.get('/foundme')
     self.assertEqual(response.status_code, 200)
Esempio n. 35
0
def api():
    app.debug = True
    app.testing = True
    yield app.test_client()
Esempio n. 36
0
 def test_web_view(self):
     with app.test_client() as c:
         resp = c.get('/tasks')
         data = flask.json.loads(resp.data)
         assertEquals(data['contains'], "Ahmed")
Esempio n. 37
0
def api():
    app.debug = True
    app.testing = True
    yield app.test_client()
Esempio n. 38
0
 def setUp(self):
     self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
     app.config['TESTING'] = True
     self.app = app.test_client()