def test_group_stances(self): """Verifies stances are grouped by stance and side.""" stance1 = Stance() stance1.issue = "Apples" stance1.side = outcomes.PRO stance2 = Stance() stance2.issue = "Oranges" stance2.side = outcomes.PRO stance3 = Stance() stance3.issue = "Banana" stance3.side = outcomes.CON stance4 = Stance() stance4.issue = "Apples" stance4.side = outcomes.CON stance5 = Stance() stance5.issue = "Banana" stance5.side = outcomes.CON stance6 = Stance() stance6.issue = "Oranges" stance6.side = outcomes.CON input_list = [stance1, stance2, stance3, stance4, stance5, stance6] correct_list = [stance4, stance1, stance3, stance5, stance6, stance2] stance_analyze.group_stances(input_list) self.assertEquals(input_list, correct_list)
def _apply_decision_strategies(member, bill, decision): """Applies strategies to compute a result for the decision. Tries all active strategies in the database and stops at the first one that succeeds. Arguments: member: the Member voting on the bill bill: the Bill to be voted upon. decision: the object that represents the decision Return: True if a decision was made, false otherwise. Upon success, the decision object has been updated appropriately. """ logger.LOGGER.info("Applying decision strategies...") strategy_entries = _retrieve_strategy_list() for strategy_entry in strategy_entries: logger.LOGGER.info("Trying decision strategy: %s" % strategy_entry.name) if not strategy_hash.STRATEGY_HASH.has_key(strategy_entry.name): logger.LOGGER.error("No such strategy exists.") continue strategy_class = strategy_hash.STRATEGY_HASH[strategy_entry.name] strategy = strategy_class(decision, member, bill) result = strategy.run() if result: strategy.explain() stance_analyze.group_stances(decision.reason) stance_analyze.group_stances(decision.downside) return True logger.LOGGER.info("Failed to produce a decision.") return False