diff options
Diffstat (limited to 'tests/api')
| -rw-r--r-- | tests/api/ApiProxy.py | 4 | ||||
| -rw-r--r-- | tests/api/ApiTester.py | 6 | ||||
| -rw-r--r-- | tests/api/test_JSONBackend.py | 15 | ||||
| -rw-r--r-- | tests/api/test_WebSocketBackend.py | 10 | ||||
| -rw-r--r-- | tests/api/test_api.py | 17 | 
5 files changed, 34 insertions, 18 deletions
diff --git a/tests/api/ApiProxy.py b/tests/api/ApiProxy.py index 4bea0f5a3..0da79a204 100644 --- a/tests/api/ApiProxy.py +++ b/tests/api/ApiProxy.py @@ -3,10 +3,12 @@  from pyload.remote.apitypes_debug import classes, methods +from tests.helper.config import credentials +  class ApiProxy:      """ Proxy that does type checking on the api """ -    def __init__(self, api, user="User", pw="test"): +    def __init__(self, api, user=credentials[0], pw=credentials[1]):          self.api = api          self.user = user          self.pw = pw diff --git a/tests/api/ApiTester.py b/tests/api/ApiTester.py index 39973b52f..e9a185947 100644 --- a/tests/api/ApiTester.py +++ b/tests/api/ApiTester.py @@ -3,6 +3,8 @@  from pyload.remote.JSONClient import JSONClient  from pyload.remote.WSClient import WSClient +from tests.helper.config import webAddress, wsAddress +  from ApiProxy import ApiProxy  class ApiTester: @@ -29,7 +31,7 @@ class ApiTester:          self.api = api      def enableJSON(self): -        self.api = ApiProxy(JSONClient()) +        self.api = ApiProxy(JSONClient(webAddress))      def enableWS(self): -        self.api = ApiProxy(WSClient()) +        self.api = ApiProxy(WSClient(wsAddress)) diff --git a/tests/api/test_JSONBackend.py b/tests/api/test_JSONBackend.py index 4efc65d2a..d13d6709f 100644 --- a/tests/api/test_JSONBackend.py +++ b/tests/api/test_JSONBackend.py @@ -10,15 +10,15 @@ import json  from pyload.remote.apitypes import Forbidden  from pyload.remote.JSONClient import JSONClient +from tests.helper.config import credentials, webAddress  class TestJSONBackend: -    login = ("User", "pwhere")      def setUp(self): -        self.client = JSONClient() +        self.client = JSONClient(webAddress)      def test_login(self): -        self.client.login(*self.login) +        self.client.login(*credentials)          self.client.getServerVersion()          self.client.logout() @@ -26,10 +26,9 @@ class TestJSONBackend:          ret = self.client.login("WrongUser", "wrongpw")          assert ret is False -      def test_httpauth(self):          # cheap http auth -        ret = requests.get(self.client.URL + "/getServerVersion", auth=HTTPBasicAuth(*self.login)) +        ret = requests.get(webAddress + "/getServerVersion", auth=HTTPBasicAuth(*credentials))          assert_equal(ret.status_code, 200)          assert ret.text @@ -37,8 +36,8 @@ class TestJSONBackend:          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)) +        ret = requests.get(webAddress + "/getConfigValue", headers=headers, +                           auth=HTTPBasicAuth(*credentials), data=json.dumps(payload))          assert_equal(ret.status_code, 200)          assert ret.text @@ -49,5 +48,5 @@ class TestJSONBackend:      @raises(AttributeError)      def test_unknown_method(self): -        self.client.login(*self.login) +        self.client.login(*credentials)          self.client.sdfdsg()
\ No newline at end of file diff --git a/tests/api/test_WebSocketBackend.py b/tests/api/test_WebSocketBackend.py index 679654fc9..a9288104f 100644 --- a/tests/api/test_WebSocketBackend.py +++ b/tests/api/test_WebSocketBackend.py @@ -5,23 +5,25 @@ from nose.tools import raises  from pyload.remote.apitypes import Forbidden  from pyload.remote.WSClient import WSClient +from tests.helper.config import credentials, wsAddress +  class TestWebSocketBackend:      def setUp(self): -        self.client = WSClient() +        self.client = WSClient(wsAddress)          self.client.connect()      def tearDown(self):          self.client.close()      def test_login(self): -        self.client.login("User", "test") +        self.client.login(*credentials)          self.client.getServerVersion()          self.client.logout()      def test_wronglogin(self):          ret = self.client.login("WrongUser", "wrongpw") -        assert ret == False +        assert ret is False      @raises(Forbidden)      def test_access(self): @@ -29,5 +31,5 @@ class TestWebSocketBackend:      @raises(AttributeError)      def test_unknown_method(self): -        self.client.login("User", "test") +        self.client.login(*credentials)          self.client.sdfdsg() diff --git a/tests/api/test_api.py b/tests/api/test_api.py index 68448b891..668470fe4 100644 --- a/tests/api/test_api.py +++ b/tests/api/test_api.py @@ -1,17 +1,19 @@ -  from unittest import TestCase  from random import choice -from pyLoadCore import Core +from pyload.Core import Core  from ApiTester import ApiTester +  class TestAPI(TestCase):      """      Test all available testers randomly and on all backends      """ +    _multiprocess_can_split_ = True      core = None +    #TODO: parallel testing      @classmethod      def setUpClass(cls):          from test_noargs import TestNoArgs @@ -33,7 +35,16 @@ class TestAPI(TestCase):          cls.core.shutdown()      def test_random(self, n=10000): -          for i in range(n):              func = choice(self.methods)              func() + +    def test_random2(self, n): +        self.test_random(n) + +    def test_random3(self, n): +        self.test_random(n) + +    def test_random4(self, n): +        self.test_random(n) +  | 
