-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
95 lines (73 loc) · 2.87 KB
/
test.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'''
Project : MDMPy2
File : test
Author : Lego
Date : 14/02/2017
'''
# -*- coding: utf-8 -*-
import os.path
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), 'site-packages')))
import cherrypy
from controllers.home import HomeController
from controllers.settings import SettingsController
from controllers.music import MusicController
from cptest import BaseCherryPyTestCase
import json
from models.dbtool import *
def setUpModule():
initializeDatabase()
cherrypy.site = {
'base_path': os.getcwd()
}
session_dir = cherrypy.site['base_path'] + "/sessions"
if not os.path.exists(session_dir):
os.makedirs(session_dir)
server_config = {
'tools.sessions.on': True,
'tools.sessions.storage_type': "file",
'tools.sessions.storage_path': session_dir,
'tools.sessions.timeout': 180,
}
cherrypy.config.update(server_config)
cherrypy.tree.mount(HomeController(), '/dashboard')
cherrypy.tree.mount(SettingsController(), '/settings')
cherrypy.tree.mount(MusicController(), '/music')
cherrypy.engine.start()
setup_module = setUpModule
def tearDownModule():
cherrypy.engine.exit()
teardown_module = tearDownModule
class TestCherryPyApp(BaseCherryPyTestCase):
def test_index(self):
response = self.request(path='/dashboard/', app_path='/dashboard')
self.assertEqual(response.output_status, '200 OK')
# response body is wrapped into a list internally by CherryPy
# self.assertEqual(response.body, ['hello world'])
def test_settings(self):
response = self.request(path='/settings/', app_path='/settings')
self.assertEqual(response.output_status, '200 OK')
def test_music(self):
response = self.request(path='/music/', app_path='/music')
self.assertEqual(response.output_status, '200 OK')
def test_music_search(self):
response = MusicController.search(query="queen")
self.assertEqual(json.loads(response)['success'], True)
def test_indexer_add(self):
response = SettingsController.addIndexer(type='torznab', url='test', api_key='test', testcase=True)
self.__class__.indexerID = response.id
self.assertIsInstance(response.id, int)
def test_indexer_remove(self):
response = SettingsController.removeIndexer(self.__class__.indexerID, True)
self.assertTrue(response)
# def test_echo(self):
# response = self.request('/echo', msg="hey there")
# self.assertEqual(response.output_status, '200 OK')
# self.assertEqual(response.body, ["hey there"])
#
# response = self.request('/echo', method='POST', msg="back from the future")
# self.assertEqual(response.output_status, '200 OK')
# self.assertEqual(response.body, ["back from the future"])
if __name__ == '__main__':
import unittest
unittest.main()