コード例 #1
0
    def test_empty_get_settings(self):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.get_settings = MagicMock(return_value=None)

        client = Client(clients_manager)
        client.__no_auth__ = True
        self.api.add_route('/api/clients/{client}', client)

        body = self.simulate_request('/api/clients/{0}'.format(1), decode="utf-8")
        self.assertEqual(self.srmock.status, falcon.HTTP_OK)
        self.assertTrue('application/json' in self.srmock.headers_dict['Content-Type'])

        result = json.loads(body)

        self.assertIsInstance(result, dict)
        self.assertEqual(result, {})
コード例 #2
0
ファイル: server.py プロジェクト: nightmare04/monitorrent
def create_app(secret_key, token, tracker_manager, clients_manager, notifier_manager, settings_manager,
               engine_runner, log_manager):
    AuthMiddleware.init(secret_key, token, lambda: settings_manager.get_is_authentication_enabled())
    app = create_api()
    add_static_route(app, 'webapp')
    app.add_route('/api/login', Login(settings_manager))
    app.add_route('/api/logout', Logout())
    app.add_route('/api/topics', TopicCollection(tracker_manager))
    app.add_route('/api/topics/{id}', Topic(tracker_manager))
    app.add_route('/api/topics/{id}/reset_status', TopicResetStatus(tracker_manager))
    app.add_route('/api/topics/parse', TopicParse(tracker_manager))
    app.add_route('/api/trackers', TrackerCollection(tracker_manager))
    app.add_route('/api/trackers/{tracker}', Tracker(tracker_manager))
    app.add_route('/api/trackers/{tracker}/check', TrackerCheck(tracker_manager))
    app.add_route('/api/clients', ClientCollection(clients_manager))
    app.add_route('/api/clients/{client}', Client(clients_manager))
    app.add_route('/api/clients/{client}/check', ClientCheck(clients_manager))
    app.add_route('/api/clients/{client}/default', ClientDefault(clients_manager))
    app.add_route('/api/notifiers', NotifierCollection(notifier_manager))
    app.add_route('/api/notifiers/{notifier}', Notifier(notifier_manager))
    app.add_route('/api/notifiers/{notifier}/check', NotifierCheck(notifier_manager))
    app.add_route('/api/notifiers/{notifier}/enabled', NotifierEnabled(notifier_manager))
    app.add_route('/api/settings/authentication', SettingsAuthentication(settings_manager))
    app.add_route('/api/settings/password', SettingsPassword(settings_manager))
    app.add_route('/api/settings/developer', SettingsDeveloper(settings_manager))
    app.add_route('/api/settings/logs', SettingsLogs(settings_manager))
    app.add_route('/api/settings/execute', SettingsExecute(engine_runner))
    app.add_route('/api/execute/logs', ExecuteLogs(log_manager))
    app.add_route('/api/execute/logs/{execute_id}/details', ExecuteLogsDetails(log_manager))
    app.add_route('/api/execute/logs/current', ExecuteLogCurrent(log_manager))
    app.add_route('/api/execute/call', ExecuteCall(engine_runner))
    return app
コード例 #3
0
    def test_not_found_update_settings(self):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.set_settings = MagicMock(side_effect=KeyError)

        client = Client(clients_manager)
        self.api.add_route('/api/clients/{client}', client)

        self.simulate_request('/api/clients/{0}'.format(1), method="PUT",
                              body=json.dumps({'login': '******', 'password': '******'}))
        self.assertEqual(self.srmock.status, falcon.HTTP_NOT_FOUND)
コード例 #4
0
    def test_successful_update_settings(self):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.set_settings = MagicMock(return_value=True)

        client = Client(clients_manager)
        self.api.add_route('/api/clients/{client}', client)

        self.simulate_request('/api/clients/{0}'.format(1), method="PUT",
                              body=json.dumps({'login': '******', 'password': '******'}))
        self.assertEqual(self.srmock.status, falcon.HTTP_NO_CONTENT)
コード例 #5
0
    def test_eroor_update_settings(self):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.set_settings = MagicMock(side_effect=Exception)

        client = Client(clients_manager)
        self.api.add_route('/api/clients/{client}', client)

        self.simulate_request('/api/clients/{0}'.format(1), method="PUT",
                              body=json.dumps({'login': '******', 'password': '******'}))
        self.assertEqual(self.srmock.status, falcon.HTTP_INTERNAL_SERVER_ERROR)
コード例 #6
0
    def test_not_found_settings(self):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.get_settings = MagicMock(side_effect=KeyError)

        client = Client(clients_manager)
        self.api.add_route('/api/clients/{client}', client)

        self.simulate_request('/api/clients/{0}'.format(1))

        self.assertEqual(self.srmock.status, falcon.HTTP_NOT_FOUND)
        self.assertTrue('application/json' in self.srmock.headers_dict['Content-Type'])
コード例 #7
0
    def test_get_settings_error(self):
        clients_manager = ClientsManager({'test': ClientCollectionTest.TestClient()})
        clients_manager.get_settings = MagicMock(side_effect=Exception)

        client = Client(clients_manager)
        self.api.add_route('/api/clients/{client}', client)

        self.simulate_request('/api/clients/{0}'.format(1))

        self.assertEqual(self.srmock.status, falcon.HTTP_INTERNAL_SERVER_ERROR)
        self.assertTrue('application/json' in self.srmock.headers_dict['Content-Type'])