Beispiel #1
0
 def do_activate(self):
     shell = self.object
     controller.set_shell(shell)
     server = Server()
     server.start()
     shell.server = server
     log.info('RhythmWeb server started')
Beispiel #2
0
 def test_get_index_file(self, response_class):
     server = Server()
     response = Mock()
     response_class.return_value = response
     server.handle_request({}, Mock())
     content = app.get_file('/index.html', 'default')
     self.assertIsNotNone(content)
     response.reply_with_file.assert_called_with('/index.html',content)
 def test_full_server_stack_post_handling(self):
     self.rb.get_entry.return_value = Stub(id=2)
     server = Server()
     try:
         server.start()
         response = urlopen('http://localhost:7003/rest/song/2', data=bytes('rating=5', 'UTF-8'))
         self.assertEquals(response.code, 200)
     finally:
         server.stop()
 def test_full_server_stack(self):
     server = Server()
     try:
         server.start()
         response = urlopen('http://localhost:7003')
         self.assertEquals(response.code, 200)
         html = response.read().decode('UTF-8')
         self.assertTrue('html' in html)
     finally:
         server.stop()
 def test_full_server_stack_error_handling(self):
     self.rb.get_entry.side_effect = RuntimeError('just because')
     server = Server()
     try:
         server.start()
         urlopen('http://localhost:7003/rest/song/1')
         self.assertTrue(False)
     except HTTPError as e:
         self.assertEquals(e.code, 500)
     finally:
         server.stop()
 def test_full_server_stack_not_found_handling(self):
     self.rb.get_entry.return_value = None
     server = Server()
     try:
         server.start()
         urlopen('http://localhost:7003/rest/song/1')
         self.assertTrue(False)
     except HTTPError as e:
         self.assertEquals(e.code, 404)
     finally:
         server.stop()
Beispiel #7
0
 def test_post_list_parameters(self, response_class):
     server = Server()
     response = Mock()
     response_class.return_value = response
     server.handle_request(
         {
             'PATH_INFO': '/path/with/kwargs',
             'REQUEST_METHOD': 'POST',
             'CONTENT_TYPE': 'application/x-www-form-urlencoded',
             'wsgi.input': BytesIO(b'key1=value1,value3,value5')
         }, Mock())
     response.reply_with_json.assert_called_with({
         'key1': 'value1,value3,value5'})
class TestWebStatus(unittest.TestCase):

    def setUp(self):
        self.rb = Mock(rb.RBHandler)
        controller.rb_handler['rb'] = self.rb
        self.entry = Stub()
        self.response = Mock()
        self.app = Server()

    def test_load_index(self):
        result = handle_request(self.app, environ('/'), self.response)
        self.assertIn('<html>', result)

    def test_load_index_by_full_name(self):
        result = handle_request(self.app, environ('/index.html'), self.response)
        self.assertIn('<html>', result)

    def test_load_style(self):
        result = handle_request(self.app, environ('/style.css'), self.response)
        self.assertIsNotNone(result)

    def test_load_image(self):
        result = self.app.handle_request(environ('/img/star.png'), self.response)
        self.assertIsNotNone(result)

    def test_not_found(self):
        result = handle_request(self.app, environ('invalid_file'), self.response)
        self.response.assert_called_with('404 NOT FOUND', 
                [('Content-type', 'text/html; charset=UTF-8')])
Beispiel #9
0
 def test_return_dict_with_path_argument(self, response_class):
     server = Server()
     response = Mock()
     response_class.return_value = response
     server.handle_request({'PATH_INFO': '/something/myarg'}, Mock())
     response.reply_with_json.assert_called_with({'the_argument': 'myarg'})
Beispiel #10
0
 def test_file_not_found(self, response_class):
     server = Server()
     response = Mock()
     response_class.return_value = response
     server.handle_request({'PATH_INFO': '/index.py'}, Mock())
     response.reply_with_not_found.assert_called_with()
 def setUp(self):
     self.rb = Mock(rb.RBHandler)
     controller.rb_handler['rb'] = self.rb
     self.entry = Stub()
     self.response = Mock()
     self.app = Server()