Пример #1
0
	def test_group(self):
		"""
		.
		"""
		site = Site.objects.get_current()
		count = CTGroup.objects.count()
		self.failUnlessEqual(count, 3)
		group1 = CTGroup.objects.get(name='Test group one')
		# group.set_permission('blog', read=PERM_CHOICE_EDITOR)
		user = self._make_user('bernie')
		member = self._make_membership(user, group1)
		post = CTPost(
			ct_group=group1,
			title = 'Post one', 
			slug = slugify('post one'),
			author = user,
			body = "some text's here...",
			publish = datetime.datetime.now()
	    )
		post.save()
		c = Comment(
			content_object=post,
			site= site,
			user = user,
			comment = 'Comment 1...',
			submit_date= datetime.datetime.now()
		)
		c.save()
		_delay(1)
		c = Comment(
			content_object=post,
			site= site,
			user = user,
			comment = 'Comment 2...',
			submit_date= datetime.datetime.now()
		)
		c.save()
		group2 = CTGroup.objects.get(name='Test group two')
		group2.set_permission('blog', read=PERM_CHOICE_EDITOR)
		user = self._make_user('chic')
		member = self._make_membership(user, group2)
		post = CTPost(
			ct_group=group2,
			title = 'Post one', 
			slug = slugify('post one'),
			author = user,
			body = "some text's here...",
			publish = datetime.datetime.now()
	    )
		post.save()
		post.save() # checks not emailed twice
		post = CTPost(
			ct_group=group2,
			title = 'Post two', 
			slug = slugify('post two'),
			author = user,
			body = "some text here for this's draft post...",
			publish = datetime.datetime.now(),
			status = 1
	    )
		post.save()
		self.assertEquals(len(mail.outbox), 4)
		post.status = 2
		post.save()
		self.assertEquals(len(mail.outbox), 5)
		# for m in mail.outbox:
		# 	print
		# 	print m.bcc
		# 	print m.subject
		# 	print m.body
			
		# print mail.outbox[0].bcc
		# print mail.outbox[0].body
		# print mail.outbox[1].bcc
		count = CTEvent.objects.count()
		self.failUnlessEqual(count, 5)
Пример #2
0
	def test_digest(self):
		"""
		.
		"""
		site = Site.objects.get_current()
		group = CTGroup.objects.get(name='Test group two')
		group3 = CTGroup.objects.get(name='Test group three')
		group.set_permission('blog', read=PERM_CHOICE_GROUP_MEMBER)
		user = self._make_user('chic')
		member = self._make_membership(user, group)
		post = CTPost(
			ct_group=group,
			title = 'digest post one', 
			slug = slugify('post one'),
			author = user,
			body = "Some text's here for post 1...",
			publish = datetime.datetime.now()
	    )
		post.save()
		c = Comment(
			content_object=post,
			site= site,
			user = user,
			comment = 'Comment...',
			submit_date= datetime.datetime.now()
		)
		c.save()
		post = CTPost(
			ct_group=group,
			title = 'digest post two', 
			slug = slugify('post two'),
			author = user,
			body = "Some text's here for post 2...",
			publish = datetime.datetime.now()
	    )
		post.save()
		post = CTPost(
			ct_group=group3,
			title = 'digest post one', 
			slug = slugify('post one'),
			author = user,
			body = "Some text's here for post 1...",
			publish = datetime.datetime.now()
	    )
		post.save()
		post = CTPost(
			ct_group=group3,
			title = 'digest post two', 
			slug = slugify('post two'),
			author = user,
			body = "Some text's here for post 2...",
			publish = datetime.datetime.now(),
			notified = True
	    )
		post.save()
		c = Comment(
			content_object=post,
			site= site,
			user = user,
			comment = 'Comment 1...',
			submit_date= datetime.datetime.now()
		)
		c.save()
		_delay(1)
		c = Comment(
			content_object=post,
			site= site,
			user = user,
			comment = 'Comment 2...',
			submit_date= datetime.datetime.now()
		)
		c.save()
		self.assertEquals(len(mail.outbox), 6)
		self.assertEquals(mail.outbox[0].subject, '[example.com] Test group two update')
		self.assertEquals(len(mail.outbox[0].bcc), 2)

		mail.outbox = []
		self.failUnlessEqual(Comment.objects.count(), 3)
		self.failUnlessEqual(CTEvent.objects.count(), 6)
		process_digests()
		self.assertEquals(len(mail.outbox), 2)
		# print
		# print mail.outbox[0].bcc
		# print mail.outbox[0].subject
		# print mail.outbox[0].body
		# print
		# print mail.outbox[1].bcc
		# print mail.outbox[1].subject
		# print mail.outbox[1].body
		
		# events should be cleared
		self.failUnlessEqual(CTEvent.objects.count(), 0)