diff options
Diffstat (limited to 'tests/api/test_JSONBackend.py')
-rw-r--r-- | tests/api/test_JSONBackend.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/api/test_JSONBackend.py b/tests/api/test_JSONBackend.py new file mode 100644 index 000000000..d13d6709f --- /dev/null +++ b/tests/api/test_JSONBackend.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- + +from nose.tools import raises, assert_equal + +from requests.auth import HTTPBasicAuth +import requests + +import json + +from pyload.remote.apitypes import Forbidden +from pyload.remote.JSONClient import JSONClient + +from tests.helper.config import credentials, webAddress + +class TestJSONBackend: + + def setUp(self): + self.client = JSONClient(webAddress) + + def test_login(self): + self.client.login(*credentials) + self.client.getServerVersion() + self.client.logout() + + def test_wronglogin(self): + ret = self.client.login("WrongUser", "wrongpw") + assert ret is False + + def test_httpauth(self): + # cheap http auth + ret = requests.get(webAddress + "/getServerVersion", auth=HTTPBasicAuth(*credentials)) + assert_equal(ret.status_code, 200) + assert ret.text + + def test_jsonbody(self): + payload = {'section': 'webinterface', 'option': 'port'} + headers = {'content-type': 'application/json'} + + ret = requests.get(webAddress + "/getConfigValue", headers=headers, + auth=HTTPBasicAuth(*credentials), data=json.dumps(payload)) + + assert_equal(ret.status_code, 200) + assert ret.text + + @raises(Forbidden) + def test_access(self): + self.client.getServerVersion() + + @raises(AttributeError) + def test_unknown_method(self): + self.client.login(*credentials) + self.client.sdfdsg()
\ No newline at end of file |