summaryrefslogtreecommitdiffstats
path: root/ice-server/heat_test/test/test_api.py
diff options
context:
space:
mode:
Diffstat (limited to 'ice-server/heat_test/test/test_api.py')
-rw-r--r--ice-server/heat_test/test/test_api.py62
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'))