def test(self): vote = Vote.get(94) vote_members = VoteMember.get_by_vote_id(vote.id) total_for, total_against, total_abstain = 0, 0, 0 for vote_member in vote_members: if vote_member.vote_result_code == "voted for": total_for += 1 elif vote_member.vote_result_code == "voted against": total_against += 1 elif vote_member.vote_result_code == "abstain": total_abstain += 1 self.assertEqual(vote.total_for, total_for) self.assertEqual(vote.total_against, total_against) self.assertEqual(vote.total_abstain, total_abstain) self.assertTrue(isinstance(vote_member.member_id, int))
def test(self): vote = Vote.get(94) vote_members = VoteMember.get_by_vote_id(vote.id) total_for, total_against, total_abstain = 0, 0, 0 for vote_member in vote_members: if vote_member.vote_result_code == 'voted for': total_for += 1 elif vote_member.vote_result_code == 'voted against': total_against += 1 elif vote_member.vote_result_code == 'abstain': total_abstain += 1 self.assertEqual(vote.total_for, total_for) self.assertEqual(vote.total_against, total_against) self.assertEqual(vote.total_abstain, total_abstain) self.assertTrue(isinstance(vote_member.member_id, int))
def _handle_noargs(self, **options): if options.get('createvotesrcid'): src_ids = [int(i) for i in options['createvotesrcid'].split(',')] self._log_info('downloading %s votes' % len(src_ids)) dataservice_votes = [] for src_id in src_ids: self._log_info('downloading vote %s' % src_id) dataservice_vote = DataserviceVote.get(src_id) dataservice_votes.append(dataservice_vote) self._log_info('downloaded all votes data, will create them now') oknesset_votes = [] for dataservice_vote in dataservice_votes: if self._has_existing_object(dataservice_vote): raise VoteScraperException( 'vote already exists in DB: %s' % dataservice_vote.id) else: oknesset_vote = self._create_new_object(dataservice_vote) oknesset_votes.append(oknesset_vote) self._log_info('created vote %s (%s)' % (oknesset_vote, oknesset_vote.pk)) self._log_info('done, created %s votes' % len(oknesset_votes)) elif options.get('validatevotepages'): from_page, to_page = [ int(p) for p in options['validatevotepages'].split('-') ] skip_to_vote_id = options.get('validateskipto', None) output_file_name = options.get('validateoutputfile', None) try_to_fix = options.get('validatefix', False) if from_page > to_page: # we support reverse pages as well! pages = reversed(range(to_page, from_page + 1)) else: pages = range(from_page, to_page + 1) if output_file_name: out = open(output_file_name, 'wb') else: out = stdout self._validate_vote_pages(out, pages, skip_to_vote_id, try_to_fix) if output_file_name: out.close() self._log_info('done') else: return super(Command, self)._handle_noargs(**options)