def assert_in_v2_response(termtype, expected_texts, v2_post, expect_stream): pbx.connected_termtype = pbx.Termtype(termtype) # use a known starting value pbx.pbx_command_timeout = 2 pbx.session = pexpect.spawn(expect_stream, timeout=2) app.testing = True with app.test_client() as c: resp = c.post('/{}/v2/'.format(pbx_name), data={"request": v2_post}) for txt in expected_texts: assert txt in resp.data.decode('utf-8') pbx.session.close()
def assert_in_v3_response(termtype, expected_texts, v3_post, expect_stream): pbx.connected_termtype = pbx.Termtype(termtype) # use a known starting value pbx.pbx_command_timeout = 2 pbx.session = pexpect.spawn(expect_stream, timeout=2) app.testing = True with app.test_client() as c: resp = c.post('/{}/v3/'.format(pbx_name), json=v3_post) data = json.loads(resp.data) assert isinstance(data, dict) is True for txt in expected_texts: assert txt in resp.data.decode('utf-8') pbx.session.close()
def test_bad_v2_request(): app.testing = True with app.test_client() as c: rv = c.post('/{}/v2/'.format(pbx_name), data='') assert rv.status_code == 400
def test_health_check(): with app.test_client() as c: rv = c.get('/{}/healthz'.format(pbx_name)) assert rv.status_code == 200 assert b'ossi_objects' in rv.data