diff options
author | Mickael JEZEQUEL <mickael.jezequel@orange.com> | 2018-03-07 17:19:48 +0100 |
---|---|---|
committer | Mickael JEZEQUEL <mickael.jezequel@orange.com> | 2018-03-07 17:21:45 +0100 |
commit | b2727af1d234bae3e64cf31a0af3dfee2d1c91f8 (patch) | |
tree | 40556f1679e2b9521c21598a43d0f4a71e6c2915 /ice-server/heat_test/test/test_api.py | |
parent | d5d7097ce064a9711cd7415d100db2560ef7ff08 (diff) |
implement rest API for ICE tests
Change-Id: I1ccb630858907161c4e8b13986fe963bb309b608
Issue-ID: VNFSDK-213
Signed-off-by: Mickael JEZEQUEL <mickael.jezequel@orange.com>
Diffstat (limited to 'ice-server/heat_test/test/test_api.py')
-rw-r--r-- | ice-server/heat_test/test/test_api.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/ice-server/heat_test/test/test_api.py b/ice-server/heat_test/test/test_api.py new file mode 100644 index 0000000..259a43b --- /dev/null +++ b/ice-server/heat_test/test/test_api.py @@ -0,0 +1,62 @@ +import io +import json +import os +import sys + +import pytest + +#sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir)) + +# Make sure that the application source directory (this directory's parent) is +# on sys.path. +here = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, here) +print(sys.path) + +import app as myapp + +ICE_URL = '/ice/' + +flask_app = myapp.create_test_app() + + +@pytest.fixture(scope='module') +def client(): + with flask_app.app.test_client() as c: + yield c + + +def test_404(client): + response = client.get('/dummy') + assert response.status_code == 404 + + +def test_ping(client): + response = client.get(ICE_URL, content_type='application/json') + assert response.status_code == 200 + + +def test_validate_nofile(client): + response = client.post(ICE_URL) + assert response.status_code == 400 + assert json_of_response(response) is not None + + +def test_validate_not_zip(client): + data = {'file': (io.BytesIO(b'my file contents'), 'hello world.txt')} + response = client.post(ICE_URL, data=data) + assert response.status_code == 422 + + +@pytest.mark.skip(reason="no way of currently testing this") +def test_validate_bad_zip(client): + zf = os.path.join(os.path.dirname(__file__), 'fixture/test.zip') + data = {'file': (zf, 'test.zip')} + response = client.post(ICE_URL, data=data) + print("##"+zf) + assert response.status_code == 200 + + +def json_of_response(response): + """Decode json from response""" + return json.loads(response.data.decode('utf8')) |