Пример #1
0
class TestJSONBackend:
    login = ("User", "pwhere")

    def setUp(self):
        self.client = JSONClient()

    def test_login(self):
        self.client.login(*self.login)
        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(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):
        self.client.getServerVersion()

    @raises(AttributeError)
    def test_unknown_method(self):
        self.client.login(*self.login)
        self.client.sdfdsg()
Пример #2
0
 def setUp(self):
     self.client = JSONClient()
Пример #3
0
 def setUp(self):
     self.client = JSONClient(webAddress)
Пример #4
0
 def setUp(self):
     self.client = JSONClient(webAddress)
Пример #5
0
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()
Пример #6
0
 def enableJSON(self):
     self.api = ApiProxy(JSONClient(webAddress))
Пример #7
0
            # Struct - Api class
            elif hasattr(result, "__name__") and result.__name__ in classes:
                for attr, atype in zip(result.__slots__, classes[result.__name__]):
                    self.assert_type(getattr(result, attr), atype)
            else: # simple object
                assert isinstance(result, type)
        except AssertionError:
            print "Assertion for %s as %s failed" % (result, type)
            raise


    def call(self, func, *args, **kwargs):
        result = getattr(self.api, func)(*args, **kwargs)
        self.assert_type(result, methods[func])

        return result


    def __getattr__(self, item):
        def call(*args, **kwargs):
            return self.call(item, *args, **kwargs)

        return call

if __name__ == "__main__":

    from pyload.remote.JSONClient import JSONClient

    api = ApiProxy(JSONClient(), "User", "test")
    api.getServerVersion()