diff options
Diffstat (limited to 'tests/api')
| -rw-r--r-- | tests/api/test_JSONBackend.py | 36 | 
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 | 
