aboutsummaryrefslogtreecommitdiffstats
path: root/library/recipes/tvmtool/examples/ut_with_roles/test.py
blob: 4a976bc2288bf7ef902600e6c09edcd4edf2ea79 (plain) (blame)
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
import os
import os.path
import requests

TVMTOOL_PORT_FILE = "tvmtool.port"
TVMTOOL_AUTHTOKEN_FILE = "tvmtool.authtoken"


def _get_tvmtool_params():
    port = int(open(TVMTOOL_PORT_FILE).read())
    authtoken = open(TVMTOOL_AUTHTOKEN_FILE).read()
    return port, authtoken


def test_tvmtool():
    assert os.path.isfile(TVMTOOL_PORT_FILE)
    assert os.path.isfile(TVMTOOL_AUTHTOKEN_FILE)

    port, authtoken = _get_tvmtool_params()

    r = requests.get("http://localhost:%d/tvm/ping" % port)
    assert r.text == 'OK'
    assert r.status_code == 200

    r = requests.get("http://localhost:%d/v2/roles?self=me" % port, headers={'Authorization': authtoken})
    assert r.status_code == 200, r.text