summaryrefslogtreecommitdiffstats
path: root/ice-server/heat_test/test/test_api.py
blob: 259a43b1ea13bec9cfcd2d20e59bf0bb1c402ee1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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'))