summaryrefslogtreecommitdiffstats
path: root/tests/api
diff options
context:
space:
mode:
authorGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-05-24 00:14:23 +0200
committerGravatar RaNaN <Mast3rRaNaN@hotmail.de> 2013-05-24 00:14:23 +0200
commitf1a20ba26fda68993325b16196f563e6aeebe60c (patch)
tree5e920ca5eacef7913b60e0d1cc289d87e9949a3b /tests/api
parentfixed bug in asynchandler (diff)
downloadpyload-f1a20ba26fda68993325b16196f563e6aeebe60c.tar.xz
improvements to json api
Diffstat (limited to 'tests/api')
-rw-r--r--tests/api/test_JSONBackend.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/tests/api/test_JSONBackend.py b/tests/api/test_JSONBackend.py
index b6509a52a..e99b97827 100644
--- a/tests/api/test_JSONBackend.py
+++ b/tests/api/test_JSONBackend.py
@@ -1,23 +1,47 @@
# -*- coding: utf-8 -*-
-from nose.tools import raises
+from nose.tools import raises, assert_equal
+
+from requests.auth import HTTPBasicAuth
+import requests
+
+import json
from module.remote.apitypes import Forbidden
from module.remote.JSONClient import JSONClient
+
class TestJSONBackend:
+ login = ("User", "pwhere")
def setUp(self):
self.client = JSONClient()
def test_login(self):
- self.client.login("User", "test")
+ self.client.login(*self.login)
self.client.getServerVersion()
self.client.logout()
def test_wronglogin(self):
ret = self.client.login("WrongUser", "wrongpw")
- assert ret == False
+ assert ret is False
+
+
+ def test_httpauth(self):
+ # cheap http auth
+ ret = requests.get(self.client.URL + "/getServerVersion", auth=HTTPBasicAuth(*self.login))
+ 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(self.client.URL + "/getConfigValue", headers=headers,
+ auth=HTTPBasicAuth(*self.login), data=json.dumps(payload))
+
+ assert_equal(ret.status_code, 200)
+ assert ret.text
@raises(Forbidden)
def test_access(self):
@@ -25,7 +49,5 @@ class TestJSONBackend:
@raises(AttributeError)
def test_unknown_method(self):
- self.client.login("User", "test")
- self.client.sdfdsg()
-
- # TODO: test raising of exceptions, also in WSBackend \ No newline at end of file
+ self.client.login(*self.login)
+ self.client.sdfdsg() \ No newline at end of file