def test_rules_attributes(self): i = 1 for r in Rules.all(): if ("name" not in r) or ("action" not in r): self.fail("Missing attributes in rule #" + str(i)) if r.action not in Rules.ACTIONS.values(): self.fail("Unknown action in rule: " + r.name) if len(r) > 2: self.fail("Unsupported attributes in rule: " + r.name) i += 1
def _apply_rules(self, process): parent = process.parent rule = Rules.find(parent.name) if not rule or not rule["action"]: return process if rule["action"] == Rules.ACTIONS["CALL-PARENT"]: return self._apply_rules(parent) # Only PRINT action left # PRINT rule is defined for parent process return parent
def render_system(self): uptime = datetime.now() - datetime.fromtimestamp(System.boot_time()) uptime = str(uptime).split('.')[0] users = set([user.name for user in psutil.get_users()]) package_managers = System.package_manager().names() view = SystemView() view.assign('python', System.python_version()) view.assign('distribution', System.distribution()) view.assign('package_managers', package_managers) view.assign('init', System.init_system()) view.assign('uptime', uptime) view.assign('user', System.user()) view.assign('users', users) view.assign('version', __version__) view.assign('rules_count', len(Rules.all())) view.assign('applications_count', len(Applications.all())) view.render()
def render_rules(self): view = RulesView() view.assign('rules', Rules.all()) view.render()
def test_rules_types(self): for rule in Rules.all(): self.assertIsInstance(rule, Rule)
def test_app_with_no_rule(self): self.assertIsNone(Rules.find("NON_EXISTING_APPLICATION"))
def test_rules_duplicity(self): rules = Rules.all() for r in rules: if rules.count(r) > 1: self.fail("Duplicate rules for: " + r.name)
def test_rules_duplicity(self): rules = Rules.all() for r in rules: if self._count(r["name"], rules) > 1: self.fail("Duplicate rules for: " + r["name"])