forked from pyload/pyload
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_JSONBackend.py
More file actions
52 lines (37 loc) · 1.42 KB
/
test_JSONBackend.py
File metadata and controls
52 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
from nose.tools import raises, assert_equal
from requests.auth import HTTPBasicAuth
import requests
import json
from pyload.remote.apitypes import Forbidden
from pyload.remote.JSONClient import JSONClient
from tests.helper.config import credentials, webAddress
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()