Ejemplo n.º 1
0
def client():
    """
    返回 flask client
    """
    from src.config.config import chaos_db, redis_url, log_db

    if ("sqlite" not in chaos_db or "127.0.0.1" not in redis_url
            or "sqlite" not in log_db):
        raise Exception("单元测试请配置环境变量")

    from src.main import app

    app.config.update({
        "SQLALCHEMY_POOL_SIZE": None,
        "SQLALCHEMY_POOL_TIMEOUT": None
    })
    from src import db

    app.config["TESTING"] = True
    app.config["SERVER_NAME"] = "127.0.0.1:5000"
    ctx = app.app_context()
    ctx.push()
    db.create_all()

    yield app.test_client()

    db.session.remove()
    db.drop_all()
    ctx.pop()
Ejemplo n.º 2
0
    def setUp(self):
        app.config["TESTING"] = True
        app.config["WTF_CSRF_ENABLED"] = False
        app.config["DEBUG"] = False
        self.app = app.test_client()

        self.assertEqual(app.debug, False)
Ejemplo n.º 3
0
 def setUp(self):
     self.db_fd, self.db_path = tempfile.mkstemp()
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + self.db_path
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
     self.app = app.test_client()
     with app.app_context():
         models.initdb_impl()
Ejemplo n.º 4
0
def client():
    app.config['TESTING'] = True

    if use_mock_client:
        with app.test_client() as client:
            return client
    else:
       return requests
Ejemplo n.º 5
0
 def setUp(self) -> None:
     app.config['SECRET_KEY'] = 'test_key'
     self.client = app.test_client()
Ejemplo n.º 6
0
 def setUp(self):
     self.app = app.test_client()
Ejemplo n.º 7
0
 def setUp(self):
     app.testing=True
     self.app=app.test_client()
Ejemplo n.º 8
0
    def test_my_app(self):
        with app.test_client() as client:
            response = client.get("/")

            assert response.status_code == 200
            assert response.data == b"Hello, Anthos!"
Ejemplo n.º 9
0
 def setUp(self):
     self.client = app.test_client()
     self.cwd = os.getcwd()
Ejemplo n.º 10
0
from src.main import app

client = app.test_client()


def test_api():
    assert client.get("/query/configs?product=xw").status_code == 200
    assert client.get("/query/events_count?product=xw").status_code == 200
    assert client.get("/query/events?&product=xw").status_code == 200
    assert client.get(
        "/query/features?page=1&page_size=10&event_type=").status_code == 200
    assert client.get("/query/map").status_code == 200
    assert client.get("/query/latest_map").status_code == 200
    assert client.get(
        "/query/cycle?date=&product&event_type").status_code == 200
Ejemplo n.º 11
0
def fixture_client():
    app.config["TESTING"] = True
    client = app.test_client()

    yield client
Ejemplo n.º 12
0
    def setUp(self):
        # Create a test client
        self.app = app.test_client()

        # Propagate app exceptions to the test client
        self.app.testing = True
def client():
    app.config['TESTING'] = True
    with app.test_client() as client:
        yield client
Ejemplo n.º 14
0
 def setUp(self):
     app.config['TESTING'] = True
     app.config['DEBUG'] = False
     self.app = app.test_client()
     self.response = lambda *args, **kwargs: Response(*args, **kwargs)
Ejemplo n.º 15
0
 def test_basic(self):
     tester = app.test_client(self)
     response = tester.get('/hello', content_type='application/json')
     print(response)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, b'{"message":"Hello, World!"}')