Exemplo n.º 1
0
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
Exemplo n.º 2
0
    def test_execute_with_tracker(self):
        topic1 = Mock()
        topic1.id = 1

        topic2 = Mock()
        topic2.id = 2

        trackers_manager = Mock()
        trackers_manager.get_tracker_topics = Mock(
            return_value=[topic1, topic2])

        engine_runner = Mock()
        engine_runner.trackers_manager = trackers_manager
        engine_runner.execute = MagicMock()
        # noinspection PyTypeChecker
        execute_call = ExecuteCall(engine_runner)

        self.api.add_route(self.test_route, execute_call)

        self.simulate_request(self.test_route,
                              query_string="tracker=tracker.tv",
                              method="POST")

        self.assertEqual(self.srmock.status, falcon.HTTP_OK)

        engine_runner.execute.assert_called_once_with([1, 2])
        trackers_manager.get_tracker_topics.assert_called_once_with(
            'tracker.tv')
Exemplo n.º 3
0
    def test_execute_fail_with_multiple_params(self, query_string):
        engine_runner = Mock()
        engine_runner.execute = MagicMock()
        # noinspection PyTypeChecker
        execute_call = ExecuteCall(engine_runner)

        self.api.add_route(self.test_route, execute_call)

        self.simulate_request(self.test_route, query_string=query_string, method="POST")
        self.assertEqual(self.srmock.status, falcon.HTTP_BAD_REQUEST)
        engine_runner.execute.assert_not_called()
Exemplo n.º 4
0
    def test_execute_with_ids(self):
        engine_runner = Mock()
        engine_runner.execute = MagicMock()
        # noinspection PyTypeChecker
        execute_call = ExecuteCall(engine_runner)

        self.api.add_route(self.test_route, execute_call)

        self.simulate_request(self.test_route, query_string="ids=1,2,3", method="POST")

        self.assertEqual(self.srmock.status, falcon.HTTP_OK)

        engine_runner.execute.assert_called_once_with([1, 2, 3])
Exemplo n.º 5
0
    def test_execute_with_statuses(self):
        trackers_manager = Mock()
        trackers_manager.get_status_topics_ids = Mock(return_value=[1, 2, 3])

        engine_runner = Mock()
        engine_runner.trackers_manager = trackers_manager
        engine_runner.execute = MagicMock()
        # noinspection PyTypeChecker
        execute_call = ExecuteCall(engine_runner)

        self.api.add_route(self.test_route, execute_call)

        self.simulate_request(self.test_route, query_string="statuses=ok,error", method="POST")

        self.assertEqual(self.srmock.status, falcon.HTTP_OK)

        engine_runner.execute.assert_called_once_with([1, 2, 3])
        trackers_manager.get_status_topics_ids.assert_called_once_with([Status.Ok, Status.Error])
Exemplo n.º 6
0
    def test_execute_with_empty_topics_expect_conflict(self):
        trackers_manager = Mock()
        trackers_manager.get_tracker_topics = Mock(return_value=[])

        engine_runner = Mock()
        engine_runner.trackers_manager = trackers_manager
        engine_runner.execute = MagicMock()
        # noinspection PyTypeChecker
        execute_call = ExecuteCall(engine_runner)

        self.api.add_route(self.test_route, execute_call)

        self.simulate_request(self.test_route, query_string="tracker=tracker.tv", method="POST")

        self.assertEqual(self.srmock.status, falcon.HTTP_CONFLICT)

        engine_runner.execute.assert_not_called()
        trackers_manager.get_tracker_topics.assert_called_once_with('tracker.tv')