Example #1
0
	def test_listing_to_statistics_survey(self):
		listing = Listing(id=1, for_sale='sell', url='test', 
				creator='*****@*****.**', created=datetime.now(),
				last_modified=datetime.now(), title='test',
				text_content='test', verified=True,
				category='Bricks', price='test',
				address='test street', city='test city',
				flag_count=1, expires=(datetime.now() + timedelta(days=30)),
				expired=0, survey_time_sent=None, uuid='1')
		listing.save()

		# Expect that 1 survey was sent because one listing is
		# ready to have a survey sent.
		expected = 1
		actual = survey_mailer.expire_and_mail_surveys()
		self.assertEqual(expected, actual)

		# Simulate that a survey was submitted
		survey = Survey(id=1, listing_id=1, item='test item', category='Bricks',
				price=3, address='test street', city='test city',
				comments='test comments', time_submitted=datetime.now())
		survey.save()
		listing.survey_time_sent = datetime.now()
		listing.save()

		statistics.generate_statistics()

		stats = Statistics.objects.get(id=1)
		self.assertEqual(1, stats.number_surveys)
		self.assertEqual(1, stats.number_listings)
		self.assertEqual(0, stats.number_buyer_surveys)
		self.assertEqual(1, stats.number_seller_surveys)
		self.assertEqual(0, stats.number_buyer_listings)
		self.assertEqual(1, stats.number_seller_listings)
		self.assertEqual(3, stats.average_transaction_amount)
		self.assertEqual(0, stats.buyer_transaction_amount)
		self.assertEqual(3, stats.seller_transaction_amount)
		self.assertEqual(3, stats.successful_transaction_amount)
		self.assertEqual(0, stats.average_transaction_time)
		self.assertEqual(100, stats.buyer_transaction_success_rate)
		self.assertEqual(100, stats.seller_transaction_success_rate)
		self.assertEqual(100, stats.total_transaction_success_rate)

		stats_categories = StatisticsCategory.objects.filter(statistics_id=1)
		for cat in stats_categories:
			if cat.category == 'Bricks':
				self.assertEqual(1, cat.survey_count)
				self.assertEqual(0, cat.buyer_count)
				self.assertEqual(1, cat.seller_count)
				self.assertEqual(3, cat.amount)
			else:
				self.assertEqual(0, cat.survey_count)
				self.assertEqual(0, cat.buyer_count)
				self.assertEqual(0, cat.seller_count)
				self.assertEqual(0, cat.amount)
Example #2
0
 def handle(self, *args, **options):
     statistics.generate_statistics()
     self.stdout.write('Successfully generated statistics\n')
 def handle(self, *args, **options):
     statistics.generate_statistics()
     self.stdout.write('Successfully generated statistics\n')