From 26227cfe53f8fd4bc1631d8e1b35031f589682dc Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 15 Jan 2012 15:55:19 +0100 Subject: backend + api test case, nicer format for plugin tester --- tests/test_backends.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/test_backends.py (limited to 'tests/test_backends.py') diff --git a/tests/test_backends.py b/tests/test_backends.py new file mode 100644 index 000000000..71ccedd2f --- /dev/null +++ b/tests/test_backends.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- + + +from urllib import urlencode +from urllib2 import urlopen, HTTPError +from json import loads + +from logging import log + +from module.common import APIExerciser + +url = "http://localhost:8001/api/%s" + +class TestBackends(): + + def setUp(self): + u = urlopen(url % "login", data=urlencode({"username": "TestUser", "password": "sometestpw"})) + self.key = loads(u.read()) + assert self.key is not False + + def test_random(self): + api = APIExerciser.APIExerciser(None, True, "TestUser", "sometestpw") + + assert api.api.login("crapp", "wrong pw") is False + + for i in range(0, 1000): + api.testAPI() + + def call(self, name, post=None): + if not post: post = {} + post["session"] = self.key + u = urlopen(url % name, data=urlencode(post)) + return loads(u.read()) + + def test_wronglogin(self): + u = urlopen(url % "login", data=urlencode({"username": "crap", "password": "wrongpw"})) + assert loads(u.read()) is False + + def test_access(self): + try: + urlopen(url % "getServerVersion") + except HTTPError, e: + assert e.code == 403 + else: + assert False + + def test_status(self): + ret = self.call("statusServer") + log(1, str(ret)) + assert "pause" in ret + assert "queue" in ret + + def test_unknown_method(self): + try: + self.call("notExisting") + except HTTPError, e: + assert e.code == 404 + else: + assert False -- cgit v1.2.3