def test_find_account_changes(self):
        RUNTIME_AUDITORS.clear()
        RUNTIME_WATCHERS.clear()
        find_changes(['TEST_ACCOUNT'], watcher_registry.keys())

        expected_watcher_count = 0
        expected_auditor_count = 0
        for key in orig_watcher_registry:
            expected_watcher_count = expected_watcher_count + 1
            wa_list = RUNTIME_WATCHERS[orig_watcher_registry[key].__name__]
            self.assertEqual(first=len(wa_list), second=1,
                             msg="Watcher {} should run once but ran {} time(s)"
                             .format(orig_watcher_registry[key].__name__, len(wa_list)))
            for au in auditor_registry[orig_watcher_registry[key].index]:
                expected_auditor_count = expected_auditor_count + 1
                au_list = RUNTIME_AUDITORS[au.__name__]
                self.assertEqual(first=len(au_list), second=1,
                                 msg="Auditor {} should run once but ran {} time(s)"
                                 .format(au.__name__, len(au_list)))

        self.assertEqual(first=len(RUNTIME_WATCHERS.keys()), second=expected_watcher_count,
                         msg="Should run {} watchers but ran {}"
                         .format(expected_watcher_count, len(RUNTIME_WATCHERS.keys())))

        self.assertEqual(first=len(RUNTIME_AUDITORS.keys()), second=expected_auditor_count,
                         msg="Should run {} auditor(s) but ran {}"
                         .format(expected_auditor_count, len(RUNTIME_AUDITORS.keys())))
Exemple #2
0
    def test_find_account_changes(self):
        RUNTIME_AUDITORS.clear()
        RUNTIME_WATCHERS.clear()
        find_changes(['TEST_ACCOUNT'], watcher_registry.keys())

        expected_watcher_count = 0
        expected_auditor_count = 0
        for key in orig_watcher_registry:
            expected_watcher_count = expected_watcher_count + 1
            wa_list = RUNTIME_WATCHERS[orig_watcher_registry[key].__name__]
            self.assertEqual(
                first=len(wa_list),
                second=1,
                msg="Watcher {} should run once but ran {} time(s)".format(
                    orig_watcher_registry[key].__name__, len(wa_list)))
            for au in auditor_registry[orig_watcher_registry[key].index]:
                expected_auditor_count = expected_auditor_count + 1
                au_list = RUNTIME_AUDITORS[au.__name__]
                self.assertEqual(
                    first=len(au_list),
                    second=1,
                    msg="Auditor {} should run once but ran {} time(s)".format(
                        au.__name__, len(au_list)))

        self.assertEqual(first=len(RUNTIME_WATCHERS.keys()),
                         second=expected_watcher_count,
                         msg="Should run {} watchers but ran {}".format(
                             expected_watcher_count,
                             len(RUNTIME_WATCHERS.keys())))

        self.assertEqual(first=len(RUNTIME_AUDITORS.keys()),
                         second=expected_auditor_count,
                         msg="Should run {} auditor(s) but ran {}".format(
                             expected_auditor_count,
                             len(RUNTIME_AUDITORS.keys())))
Exemple #3
0
    def get(self):
        self.reqparse.add_argument('count', type=int, default=30, location='args')
        self.reqparse.add_argument('page', type=int, default=1, location='args')

        args = self.reqparse.parse_args()
        page = args.pop('page', None)
        count = args.pop('count', None)

        configs = []
        all_keys = watcher_registry.keys()
        all_keys.sort()

        start_index = (page - 1) * count
        keys = all_keys[start_index:start_index + count]

        for key in keys:
            watcher_class = watcher_registry[key]
            config = WatcherConfig.query.filter(WatcherConfig.index == watcher_class.index).first()
            if config is None:
                config = WatcherConfig(id=0,
                                       index=watcher_class.index,
                                       interval=watcher_class.interval,
                                       active=True)

            configs.append(config)

        return_dict = {
            "page": page,
            "total": len(all_keys),
            "count": len(configs),
            "items": [marshal(item.__dict__, WATCHER_CONFIG_FIELDS) for item in configs],
            "auth": self.auth_dict
        }

        return return_dict, 200
Exemple #4
0
def _parse_tech_names(tech_str):
    if tech_str == 'all':
        return watcher_registry.keys()
    else:
        return tech_str.split(',')
Exemple #5
0
def _parse_tech_names(tech_str):
    if tech_str == 'all':
        return watcher_registry.keys()
    else:
        return tech_str.split(',')