Exemplo n.º 1
0
	def test_unicode_method_invalid_vote(self):
		"""
		Test __unicode__ str output when Opinion is invalid numerically
		"""
		invalid = Opinion(vote=-9999)

		self.assertEqual(invalid.__unicode__(), 'Invalid' )
Exemplo n.º 2
0
	def test_get_json_friendly_usa_state_counts(self):
		"""
		Test that the result of the json is aggregated by state correctly and 
		by votes so that we get back a list of items who specify state and totals
		"""

		question = create_question("Test Aggregation", create_category("test"))
		states = ['VT','NH','MA','TX','GA','CA','WA','NC']
		for region in states:
			for opinion in Opinion.OPINIONS:
				create_opinion(opinion[0], question, region )

		#We strongly disagree with CA, for testing the majority key
		create_opinion(Opinion.STRONGLY_DISAGREE, question, 'CA' )

		results = question.get_json_friendly_usa_state_counts()
		#Assert key structure and that there are states.length items, with 1 vote each
		self.assertEqual(len(results), len(states))
		for result in results:
			self.assertTrue(result.get('totals'))
			if result.get('state') == 'US-CA':
				self.assertEqual(result.get('majority'), Opinion.vote_string(Opinion.STRONGLY_DISAGREE) )
			else:
				self.assertEqual(result.get('majority'), Question.MAJORITY_INCONCLUSIVE )
			totals = result.get('totals')
			self.assertEqual(len(totals), len(Opinion.OPINIONS))
			for vote in totals:
				if result.get('state') == 'US-CA':
					#majority vote in this test data so we have 4 1's and a 2.
					ones = [i for i in totals if i.get('votes') == 1]
					self.assertEqual(len(ones), 4 )
				else:
					self.assertEqual(vote.get('votes'), 1)
Exemplo n.º 3
0
	def test_unicode_method_valid_votes(self):
		"""
		Test __unicode__ str output when Opinion's are valid
		should return strings within the Opinion.OPINION static
		"""
		strong_disagree = Opinion(vote=Opinion.STRONGLY_DISAGREE)
		disagree = Opinion(vote=Opinion.DISAGREE)
		neutral = Opinion(vote=Opinion.NEUTRAL)
		agree = Opinion(vote=Opinion.AGREE)
		strong_agree = Opinion(vote=Opinion.STRONGLY_AGREE)

		self.assertEqual(strong_disagree.__unicode__(), Opinion.vote_string(Opinion.STRONGLY_DISAGREE) )
		self.assertEqual(disagree.__unicode__(), Opinion.vote_string(Opinion.DISAGREE) )
		self.assertEqual(neutral.__unicode__(), Opinion.vote_string(Opinion.NEUTRAL) )
		self.assertEqual(agree.__unicode__(), Opinion.vote_string(Opinion.AGREE) )
		self.assertEqual(strong_agree.__unicode__(), Opinion.vote_string(Opinion.STRONGLY_AGREE) )