def setUp(self): super(WallpostReactionApiIntegrationTest, self).setUp() self.manager = BlueBottleUserFactory.create() self.manager_token = "JWT {0}".format( self.manager.get_jwt_token()) self.event = EventFactory.create(owner=self.manager) self.some_wallpost = TextWallpostFactory.create(content_object=self.event) self.another_wallpost = TextWallpostFactory.create() self.some_user = BlueBottleUserFactory.create( password='******', first_name='someName', last_name='someLast') self.some_token = "JWT {0}".format(self.some_user.get_jwt_token()) self.another_user = BlueBottleUserFactory.create( password='******', first_name='anotherName', last_name='anotherLast') self.another_token = "JWT {0}".format( self.another_user.get_jwt_token()) self.wallpost_reaction_url = reverse('wallpost_reaction_list') self.wallpost_url = reverse('wallpost_list') self.text_wallpost_url = reverse('text_wallpost_list') response = self.client.post( self.wallpost_reaction_url, { 'text': 'Dit is een test', 'wallpost': self.some_wallpost.id }, token=self.some_token ) self.reaction_detail_url = reverse('wallpost_reaction_detail', kwargs={'pk': response.data['id']})
def test_wallposts_with_and_without_donation(self): """ Test that a Wallpost doesn't serializes donation if there isn't one """ TextWallpostFactory.create(content_object=self.funding) self.donation = DonationFactory( amount=Money(35, 'EUR'), user=None, activity=self.funding ) self.donation.states.succeed(save=True) response = self.client.get(self.updates_url, token=self.owner_token) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), 2) self.assertEqual( response.data['results'][0]['donation'], { 'name': None, 'fundraiser': None, 'amount': {'currency': 'EUR', 'amount': 35.00}, 'user': None, 'anonymous': False, 'reward': None, 'type': 'contributions/donations', 'id': self.donation.id } ) self.assertEqual(response.data['results'][1]['donation'], None)
def test_not_follow_own_task(self): """ Test that users do not follow their own task page """ self.assertEqual(Follow.objects.count(), 0) TextWallpostFactory.create(content_object=self.task, author=self.some_user, text="test1") self.assertEqual(Follow.objects.count(), 0)
def test_wallpost_mail_fundraiser(self): """ Test that the relevant people get an email when the email_followers option is selected for a fundraiser """ # On a Fundraiser page, people who posted to the wall and who donated get an email --> Followers self.assertEqual(Follow.objects.count(), 0) # A user creates a fundraiser fundraiser_person = BlueBottleUserFactory.create() fundraiser = FundraiserFactory(project=self.project, owner=fundraiser_person) # Two people donate to the fundraiser donator1 = BlueBottleUserFactory.create() order = OrderFactory.create(user=donator1, status=StatusDefinition.CREATED) DonationFactory(order=order, amount=35, project=self.project, fundraiser=fundraiser) order.locked() order.success() order.save() donator2 = BlueBottleUserFactory.create() order2 = OrderFactory.create(user=donator2, status=StatusDefinition.CREATED) DonationFactory(order=order2, amount=35, project=self.project, fundraiser=fundraiser) order2.locked() order2.success() order2.save() # The fundraiser owner creates a wallpost to followers TextWallpostFactory.create(content_object=fundraiser, author=fundraiser_person, text="test_fundraiser", email_followers=True) mail_count = 0 self.assertEqual(Follow.objects.count(), 3) # When the fundraiser sends an email to the followers he doesn't get one himself receivers = [donator1.email, donator2.email] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) receivers.remove(email.to[0]) self.assertEqual(mail_count, 2) self.assertEqual(receivers, [])
def test_new_wallpost_by_a_on_project_by_a(self): """ Project by A + Wallpost by A => No mails. """ # Object by A # | # +-- Wallpost by A (+) TextWallpostFactory.create(content_object=self.project_1, author=self.user_a) # Mailbox should not contain anything. self.assertEqual(len(mail.outbox), 0)
def test_no_mail_no_campaign_notifications(self): """ Test that users who have campaign_notifications turned off don't get email """ task_owner1 = BlueBottleUserFactory.create(campaign_notifications=False) TaskFactory.create( author=task_owner1, project=self.project ) # Add extra project and owner that should not get any email project_owner = BlueBottleUserFactory.create(campaign_notifications=False) ProjectFactory(owner=project_owner, status=self.phase1) # Create a follower by donating donator1 = BlueBottleUserFactory.create(campaign_notifications=False) order = OrderFactory.create(user=donator1, status=StatusDefinition.CREATED) DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) order.locked() order.success() order.save() # Create a follower by being a fundraiser for the project fundraiser_person = BlueBottleUserFactory.create(campaign_notifications=False) FundraiserFactory(project=self.project, owner=fundraiser_person) self.assertEqual(Follow.objects.count(), 3) # Create follower by voting voter_person = BlueBottleUserFactory.create( campaign_notifications=False) VoteFactory(voter=voter_person, project=self.project) # Project owner creates a wallpost and emails followers TextWallpostFactory.create( content_object=self.project, author=self.project.owner, text="test2", email_followers=True) mail_count = 0 # People who should get an email: self.some_user, task_owner1, # fundraiser_person, commenter, voter and donator1 for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertEqual(mail_count, 0)
def setUp(self): super(WallpostReactionApiIntegrationTest, self).setUp() self.some_wallpost = TextWallpostFactory.create() self.another_wallpost = TextWallpostFactory.create() self.some_user = BlueBottleUserFactory.create(password='******', first_name='someName', last_name='someLast') self.some_token = "JWT {0}".format(self.some_user.get_jwt_token()) self.another_user = BlueBottleUserFactory.create(password='******', first_name='anotherName', last_name='anotherLast') self.another_token = "JWT {0}".format(self.another_user.get_jwt_token()) self.wallpost_reaction_url = reverse('wallpost_reaction_list') self.wallpost_url = reverse('wallpost_list') self.text_wallpost_url = reverse('text_wallpost_list')
def test_no_duplicate_follow(self): """ Test that no duplicate followers are created """ self.assertEqual(Follow.objects.count(), 0) commenter = BlueBottleUserFactory.create() # Create a text Wallpost for our dummy project some_wallpost = TextWallpostFactory.create(content_object=self.project, author=self.another_user, text="test1", email_followers=False) self.assertEqual(Follow.objects.count(), 1) #Side-effectg of creating the wallpost another_wallpost = TextWallpostFactory.create(content_object=self.project, author=commenter, text="test2", email_followers=False) self.assertEqual(Follow.objects.count(), 2) # Make sure to inspect the second Follow object, this is the Follow object for the Reaction self.assertEqual(Follow.objects.all()[1].followed_object, self.project) self.assertEqual(Follow.objects.all()[1].user, commenter)
def test_new_reaction_by_b_on_wallpost_b_on_project_by_a(self): """ Project by A + Wallpost by B + Reaction by B => Mail to (project owner) A. """ # Object by A # | # +-- Wallpost by B # | # +-- Reaction by A # | # +-- Reaction by B (+) w = TextWallpostFactory.create(content_object=self.project_1, author=self.user_b) Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_a) # Empty outbox. mail.outbox = [] Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_b) # Mailbox should contain an email to project owner. self.assertEqual(len(mail.outbox), 1) m = mail.outbox[0] self.assertEqual(m.to, [self.user_a.email]) self.assertEqual(m.activated_language, self.user_a.primary_language)
def test_not_follow_own_task(self): """ Test that users do not follow their own task page """ self.assertEqual(Follow.objects.count(), 0) some_wallpost = TextWallpostFactory.create(content_object=self.task, author=self.some_user, text="test1") self.assertEqual(Follow.objects.count(), 0)
def test_wallpost_no_mail(self): """ Test that followers don't get an email if email_followers is false. Email_followers boolean is false by default on wallpost model""" self.assertEqual(len(mail.outbox), 0) self.assertEqual(Follow.objects.count(), 0) commenter = BlueBottleUserFactory.create() commenter2 = BlueBottleUserFactory.create() # Create follower by creating a donation order = OrderFactory.create(user=self.another_user, status=StatusDefinition.CREATED) # Make sure to set Fundraiser to None. Otherwise, a fundraiser is created donation = DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) # Create follower by creating a task owner task_owner1 = BlueBottleUserFactory.create() task = TaskFactory.create( author=task_owner1, project=self.project ) # Verify we have two followers self.assertEqual(Follow.objects.count(), 2) # Create a text Wallpost for our dummy project some_wallpost = TextWallpostFactory.create(content_object=self.project, author=self.project.owner, text="test1", email_followers=False) self.assertEqual(Follow.objects.count(), 2) # Some other emails are sent, so we do not compare the mail count. Instead we look at the subject for email in mail.outbox: self.assertTrue("New wallpost on" not in email.subject)
def test_new_reaction_by_c_on_wallpost_b_on_project_by_a(self): """ Project by A + Wallpost by B + Reaction by C => Mail to (project owner) A + Mail to (reaction author) B """ # Object by A # | # +-- Wallpost by B # | # +-- Reaction by A # | # +-- Reaction by B # | # +-- Reaction by C (+) w = TextWallpostFactory.create(content_object=self.project_1, author=self.user_b) Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_a) Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_b) # Empty outbox. mail.outbox = [] Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_c) # Mailbox should contain an email to project owner. self.assertEqual(len(mail.outbox), 2) m1 = mail.outbox[0] m2 = mail.outbox[1] self.assertListEqual([m2.to[0], m1.to[0]], [self.user_a.email, self.user_b.email])
def test_no_mail_no_campaign_notifications(self): """ Test that users who have campaign_notifications turned off don't get email """ task_owner1 = BlueBottleUserFactory.create(campaign_notifications=False) task = TaskFactory.create( author=task_owner1, project=self.project ) # Add extra project and owner that should not get any email project_owner = BlueBottleUserFactory.create(campaign_notifications=False) project2 = ProjectFactory(owner=project_owner, status=self.phase1) # Create a follower by donating donator1 = BlueBottleUserFactory.create(campaign_notifications=False) order = OrderFactory.create(user=donator1, status=StatusDefinition.CREATED) donation = DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) # Create a follower by being a fundraiser for the project fundraiser_person = BlueBottleUserFactory.create(campaign_notifications=False) fundraiser = FundraiserFactory(project=self.project, owner=fundraiser_person) self.assertEqual(Follow.objects.count(), 3) # Project owner creates a wallpost and emails followers some_wallpost_2 = TextWallpostFactory.create(content_object=self.project, author=self.project.owner, text="test2", email_followers=True) mail_count = 0 # People who should get an email: self.some_user, task_owner1, fundraiser_person, commenter, and donator1 receivers = [] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertEqual(mail_count, 0)
def test_new_reaction_by_b_on_wallpost_a_on_project_by_a(self): """ Project by A + Wallpost by A + Reaction by B => Mail to (reaction author) A. """ # Object by A # | # +-- Wallpost by A # | | # | +-- Reaction by A # | | # | +-- Reaction by B (+) w = TextWallpostFactory.create(content_object=self.project_1, author=self.user_a) Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_a) # Empty outbox. mail.outbox = [] Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_b) # Mailbox should contain an email to author of reaction a. self.assertEqual(len(mail.outbox), 1) m = mail.outbox[0] self.assertEqual(m.to, [self.user_a.email])
def test_wallpost_mail_project(self): """ Test that the relevant people get an email when the email_followers option is selected for a project """ # On a project page, task owners, fundraisers, and people who donated, get a mail. # Create a follower by being a task owner task_owner1 = BlueBottleUserFactory.create() task = TaskFactory.create( author=task_owner1, project=self.project ) # Add extra project and owner that should not get any email project_owner = BlueBottleUserFactory.create() project2 = ProjectFactory(owner=project_owner, status=self.phase1) # iLeaving a wallpost should not create a follower commenter = BlueBottleUserFactory.create() some_wallpost = TextWallpostFactory.create(content_object=self.project, author=commenter, text="test1", email_followers=False) # Create a follower by donating donator1 = BlueBottleUserFactory.create() order = OrderFactory.create(user=donator1, status=StatusDefinition.CREATED) donation = DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) # Create a follower by being a fundraiser for the project fundraiser_person = BlueBottleUserFactory.create() fundraiser = FundraiserFactory(project=self.project, owner=fundraiser_person) self.assertEqual(Follow.objects.count(), 3) # Project owner creates a wallpost and emails followers some_wallpost_2 = TextWallpostFactory.create(content_object=self.project, author=self.project.owner, text="test2", email_followers=True) mail_count = 0 # People who should get an email: self.some_user, task_owner1, fundraiser_person, commenter, and donator1 receivers = [task_owner1.email, fundraiser_person.email, donator1.email] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) receivers.remove(email.to[0]) self.assertEqual(mail_count, 3) self.assertEqual(receivers, [])
def test_new_wallpost_by_b_on_task_by_a(self): """ Task by A + Wallpost by B => Mail to (task owner) A """ # Object by A # | # +-- Wallpost by B (+) TextWallpostFactory.create(content_object=self.task_1, author=self.user_b) # Mailbox should contain an email to project owner. self.assertEqual(len(mail.outbox), 1) m = mail.outbox[0] self.assertEqual(m.to, [self.user_a.email]) self.assertEqual(m.activated_language, self.user_a.primary_language)
def test_new_wallpost_b_on_project_with_roles_by_a_c_d(self): """ Project by A, with task manager C and promoter D + Wallpost by B => Mail to A, C and D. """ # Object by A with task manager C + promoter D # | # +-- Wallpost by B self.project_1.task_manager = self.user_c self.project_1.promoter = self.user_d self.project_1.save() mail.outbox = [] TextWallpostFactory.create(content_object=self.project_1, author=self.user_b) # Mailbox should contain an email to author of reaction b. self.assertEqual(len(mail.outbox), 3)
def test_create_follow_wallpost_project(self): """ Test that a Follow object is created between the user and the project when a wallpost is created """ self.assertEqual(Follow.objects.count(), 0) # Create a text Wallpost for our dummy project some_wallpost = TextWallpostFactory.create(content_object=self.project, author=self.another_user) self.assertEqual(Follow.objects.count(), 1) self.assertEqual(Follow.objects.all()[0].followed_object, self.project) self.assertEqual(Follow.objects.all()[0].user, self.another_user)
def test_create_follow_wallpost_task(self): """ Test that a Follow object is created when a user leaves a wallpost on a task """ self.assertEqual(Follow.objects.count(), 0) # Create a text Wallpost for our dummy project some_wallpost = TextWallpostFactory.create(content_object=self.task, author=self.another_user) self.assertEqual(Follow.objects.count(), 1) self.assertEqual(Follow.objects.all()[0].followed_object, self.task) self.assertEqual(Follow.objects.all()[0].user, self.another_user)
def test_wallpost_mail_task(self): """ Test that the relevant people get an email when the email_followers option is selected for a task """ # On a task page, the task members, task owners, get an email --> Followers project_owner = BlueBottleUserFactory.create() project2 = ProjectFactory(owner=project_owner, status=self.phase1) task_owner1 = BlueBottleUserFactory.create() task = TaskFactory.create( author=task_owner1, project=project2 ) task_member_1 = TaskMemberFactory(task=task) task_member_2 = TaskMemberFactory(task=task) mail.outbox = [] self.assertEqual(Follow.objects.count(), 5) for follower in Follow.objects.all(): if follower.user != task_owner1: self.assertTrue(follower.followed_object in (task, task.project)) TextWallpostFactory.create(content_object=task, author=task_owner1, text="test2", email_followers=True) mail_count = 0 receivers = [task_member_1.member.email, task_member_2.member.email] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) receivers.remove(email.to[0]) self.assertEqual(mail_count, 2) self.assertEqual(receivers, [])
def test_wallpost_no_mail(self): """ Test that followers don't get an email if email_followers is false. Email_followers boolean is false by default on wallpost model""" self.assertEqual(len(mail.outbox), 0) self.assertEqual(Follow.objects.count(), 0) BlueBottleUserFactory.create() BlueBottleUserFactory.create() # Create follower by creating a donation order = OrderFactory.create(user=self.another_user, status=StatusDefinition.CREATED) # Make sure to set Fundraiser to None. Otherwise, a fundraiser is created DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) order.locked() order.success() order.save() # Create follower by creating a task owner task_owner1 = BlueBottleUserFactory.create() TaskFactory.create( author=task_owner1, project=self.project ) # Verify we have two followers self.assertEqual(Follow.objects.count(), 2) # Create a text Wallpost for our dummy project TextWallpostFactory.create(content_object=self.project, author=self.project.owner, text="test1", email_followers=False) self.assertEqual(Follow.objects.count(), 2) # Some other emails are sent, so we do not compare the mail count. Instead we look at the subject for email in mail.outbox: self.assertTrue("New wallpost on" not in email.subject)
def setUp(self): super(TestWallpostAPIPermissions, self).setUp() self.user = BlueBottleUserFactory.create() self.user_token = "JWT {0}".format(self.user.get_jwt_token()) self.some_initiative = InitiativeFactory.create(owner=self.user) self.some_wallpost = TextWallpostFactory.create( content_object=self.some_initiative, author=self.user) self.wallpost_url = reverse('wallpost_list')
def test_tags_generation(self, queue_mock): project = ProjectFactory.create() DonationFactory.create(project=project) wallpost = TextWallpostFactory.create() expected_tags = {'type': 'wallpost', 'tenant': u'test'} expected_fields = {'id': wallpost.id, 'user_id': wallpost.author.id} args, kwargs = queue_mock.call_args self.assertEqual(kwargs['tags'], expected_tags) self.assertEqual(kwargs['fields'], expected_fields) self.assertEqual(kwargs['timestamp'], wallpost.created)
def test_new_wallpost_by_a_on_project_by_a(self): """ Project by A + Wallpost by A => No mails. """ # Object by A # | # +-- Wallpost by A (+) post = TextWallpostFactory.create(content_object=self.project_1, author=self.user_a) # Mailbox should not contain anything. self.assertEqual(len(mail.outbox), 0)
def test_wallpost_mail_fundraiser(self): """ Test that the relevant people get an email when the email_followers option is selected for a fundraiser """ # On a Fundraiser page, people who posted to the wall and who donated get an email --> Followers self.assertEqual(Follow.objects.count(), 0) fundraiser_person = BlueBottleUserFactory.create() fundraiser = FundraiserFactory(project=self.project, owner=fundraiser_person) donator1 = BlueBottleUserFactory.create() order = OrderFactory.create(user=donator1, status=StatusDefinition.CREATED) donation = DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) donator2 = BlueBottleUserFactory.create() order2 = OrderFactory.create(user=donator2, status=StatusDefinition.CREATED) donation = DonationFactory(order=order2, amount=35, project=self.project, fundraiser=None) commenter = BlueBottleUserFactory.create() commenter_post = TextWallpostFactory.create(content_object=fundraiser, author=commenter, text="test_commenter", email_followers=False) some_wallpost = TextWallpostFactory.create(content_object=fundraiser, author=fundraiser_person, text="test_fundraiser", email_followers=True) mail_count = 0 self.assertEqual(Follow.objects.count(), 4) for follower in Follow.objects.all(): follower.followed_object = self.project # When the fundraiser sends an email to the followers he doesn't get one himself receivers = [donator1.email, donator2.email, commenter.email] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) receivers.remove(email.to[0]) self.assertEqual(mail_count, 3) self.assertEqual(receivers, [])
def setUp(self): super(WallpostReactionApiIntegrationTest, self).setUp() self.init_projects() self.some_wallpost = TextWallpostFactory.create() self.another_wallpost = TextWallpostFactory.create() self.some_user = BlueBottleUserFactory.create(password='******', first_name='someName', last_name='someLast') self.some_token = "JWT {0}".format(self.some_user.get_jwt_token()) self.another_user = BlueBottleUserFactory.create( password='******', first_name='anotherName', last_name='anotherLast') self.another_token = "JWT {0}".format( self.another_user.get_jwt_token()) self.wallpost_reaction_url = reverse('wallpost_reaction_list') self.wallpost_url = reverse('wallpost_list') self.text_wallpost_url = reverse('text_wallpost_list')
def test_new_wallpost_by_b_on_task_by_a(self): """ Task by A + Wallpost by B => Mail to (task owner) A """ # Object by A # | # +-- Wallpost by B (+) post = TextWallpostFactory.create(content_object=self.task_1, author=self.user_b) # Mailbox should contain an email to project owner. self.assertEqual(len(mail.outbox), 1) m = mail.outbox[0] self.assertEqual(m.to, [self.user_a.email])
def test_reaction(self, queue_mock): wallpost = TextWallpostFactory.create() reaction = ReactionFactory.create(wallpost=wallpost, author=wallpost.author) expected_tags = { 'type': 'wallpost', 'sub_type': 'reaction', 'tenant': u'test' } expected_fields = {'id': reaction.id, 'user_id': reaction.author.id} args, kwargs = queue_mock.call_args self.assertEqual(kwargs['tags'], expected_tags) self.assertEqual(kwargs['fields'], expected_fields)
def test_tags_generation(self, queue_mock): project = ProjectFactory.create() donation = DonationFactory.create(project=project) wallpost = TextWallpostFactory.create() expected_tags = { 'type': 'wallpost', 'tenant': u'test' } expected_fields = { 'id': wallpost.id, 'user_id': wallpost.author.id } args, kwargs = queue_mock.call_args self.assertEqual(kwargs['tags'], expected_tags) self.assertEqual(kwargs['fields'], expected_fields)
def test_new_wallpost_by_b_on_project_by_a(self): """ Project by A + Wallpost by B => Mail to (project owner) A """ # Object by A # | # +-- Wallpost by B (+) post = TextWallpostFactory.create( content_object=self.project_1, author=self.user_b) # Mailbox should contain an email to project owner. self.assertEqual(len(mail.outbox), 1) m = mail.outbox[0] self.assertEqual(m.to, [self.user_a.email]) self.assertEqual(m.activated_language, self.user_a.primary_language)
def test_new_reaction_by_a_on_wallpost_a_on_project_by_a(self): """ Project by A + Wallpost by A + Reaction by A => No mails. """ # Object by A # | # +-- Wallpost by A # | | # | +-- Reaction by A (+) w = TextWallpostFactory.create(content_object=self.project_1, author=self.user_a) # Empty outbox. mail.outbox = [] Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_a) # Mailbox should not contain anything. self.assertEqual(len(mail.outbox), 0)
def test_delete_wallpost_by_b_on_project_by_a(self): """ Project by A + Wallpost by B => Mail to (project owner) A """ # Object by A # | # +-- Wallpost by B (+) post = TextWallpostFactory.create(content_object=self.project_1, author=self.user_b) # Mailbox should contain an email to project owner. self.assertEqual(len(mail.outbox), 1) post.deleted = now() post.save() # No new mails should be send self.assertEqual(len(mail.outbox), 1)
def test_reaction(self, queue_mock): wallpost = TextWallpostFactory.create() reaction = ReactionFactory.create(wallpost=wallpost, author=wallpost.author) expected_tags = { 'type': 'wallpost', 'sub_type': 'reaction', 'tenant': u'test' } expected_fields = { 'id': reaction.id, 'user_id': reaction.author.id } args, kwargs = queue_mock.call_args self.assertEqual(kwargs['tags'], expected_tags) self.assertEqual(kwargs['fields'], expected_fields)
def test_wallpost_mail_task(self): """ Test that the relevant people get an email when the email_followers option is selected for a task """ # On a task page, the task members, task owners, get an email --> Followers project_owner = BlueBottleUserFactory.create() project2 = ProjectFactory(owner=project_owner, status=self.phase1) task_owner1 = BlueBottleUserFactory.create() task = TaskFactory.create( author=task_owner1, project=project2 ) task_member_1 = TaskMemberFactory(task=task) task_member_2 = TaskMemberFactory(task=task) mail.outbox = [] self.assertEqual(Follow.objects.count(), 3) for follower in Follow.objects.all(): if follower.user != task_owner1: self.assertEqual(follower.followed_object, task) some_wallpost = TextWallpostFactory.create(content_object=task, author=task_owner1, text="test2", email_followers=True) mail_count = 0 receivers = [task_member_1.member.email, task_member_2.member.email] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) receivers.remove(email.to[0]) self.assertEqual(mail_count, 2) self.assertEqual(receivers, [])
def test_new_reaction_by_c_on_wallpost_b_on_project_by_a(self): """ Project by A + Wallpost by B + Reaction by C => Mail to (project owner) A + Mail to (reaction author) B """ # Object by A # | # +-- Wallpost by B # | # +-- Reaction by A # | # +-- Reaction by B # | # +-- Reaction by C (+) w = TextWallpostFactory.create(content_object=self.project_1, author=self.user_b) Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_a) Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_b) # Empty outbox. mail.outbox = [] Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_c) # Mailbox should contain an email to project owner. self.assertEqual(len(mail.outbox), 2) m1 = mail.outbox[0] m2 = mail.outbox[1] self.assertListEqual([m2.to[0], m1.to[0]], [self.user_a.email, self.user_b.email]) self.assertListEqual( [m2.activated_language, m1.activated_language], [self.user_a.primary_language, self.user_b.primary_language])
def test_delete_reaction_by_c_on_wallpost_b_on_project_by_a(self): """ Project by A + Wallpost by B + Reaction by C => Mail to (project owner) A + Mail to (reaction author) B """ # Object by A # | # +-- Wallpost by B # | # +-- Reaction by A # | # +-- Reaction by B # | # +-- Reaction by C (+) w = TextWallpostFactory.create(content_object=self.project_1, author=self.user_b) Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_a) reaction = Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_b) # Empty outbox. mail.outbox = [] Reaction.objects.create(text='Hello world', wallpost=w, author=self.user_c) # Mailbox should contain an email to project owner. self.assertEqual(len(mail.outbox), 2) reaction.deleted = now() reaction.save() # No new mails should be sent self.assertEqual(len(mail.outbox), 2)
def setUp(self): super(TestTextWallpostAdmin, self).setUp() self.site = AdminSite() self.wallpost = TextWallpostFactory.create() self.admin = TextWallpostAdmin(self.wallpost, self.site)
def test_wallpost_delete_mail_project(self): """ Test that the relevant people don't get an email when the email_followers option is selected for a project during wallpost create but is then deleted.""" # On a project page, task owners, fundraisers, and people who donated, get a mail. # Create a follower by being a task owner task_owner1 = BlueBottleUserFactory.create() task = TaskFactory.create( author=task_owner1, project=self.project ) # Add extra project and owner that should not get any email project_owner = BlueBottleUserFactory.create() project2 = ProjectFactory(owner=project_owner, status=self.phase1) # iLeaving a wallpost should not create a follower commenter = BlueBottleUserFactory.create() some_wallpost = TextWallpostFactory.create(content_object=self.project, author=commenter, text="test1", email_followers=False) # Create a follower by donating donator1 = BlueBottleUserFactory.create() order = OrderFactory.create(user=donator1, status=StatusDefinition.CREATED) donation = DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) # Create a follower by being a fundraiser for the project fundraiser_person = BlueBottleUserFactory.create() fundraiser = FundraiserFactory(project=self.project, owner=fundraiser_person) self.assertEqual(Follow.objects.count(), 3) voter = BlueBottleUserFactory.create() vote = VoteFactory(voter=voter, project=self.project) self.assertEqual(Follow.objects.count(), 4) # Project owner creates a wallpost and emails followers some_wallpost_2 = TextWallpostFactory.create( content_object=self.project, author=self.project.owner, text="test2", email_followers=True) mail_count = 0 # People who should get an email: self.some_user, voter, task_owner1, # fundraiser_person, commenter, and donator1 receivers = [voter.email, task_owner1.email, fundraiser_person.email, donator1.email] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) receivers.remove(email.to[0]) self.assertEqual(mail_count, 4) self.assertEqual(receivers, []) # Setup for mail counting after wallpost delete mail_count = 0 receivers = [voter.email, task_owner1.email, fundraiser_person.email, donator1.email] # This time we can safely reset the email box to 0 mail.outbox = [] # Ember triggers a save to the record before the actual delete # therefore we can't use the Django delete function. This won't # trigger the email_follower signal to be fired again. To replicate # the server behavior we can simply re-save the wallpost record. This # will cause the signal to fire but with the "created" flag to False. some_wallpost_2.save() # Check that no emails about a new wallpost go out for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) self.assertEqual(mail_count, 0)
def test_wallpost_mail_project(self): """ Test that the relevant people get an email when the email_followers option is selected for a project """ # On a project page, task owners, fundraisers, and people who donated, get a mail. # Create a follower by being a task owner task_owner1 = BlueBottleUserFactory.create() TaskFactory.create( author=task_owner1, project=self.project ) # Add extra project and owner that should not get any email project_owner = BlueBottleUserFactory.create() ProjectFactory(owner=project_owner, status=self.phase1) # iLeaving a wallpost should not create a follower commenter = BlueBottleUserFactory.create() TextWallpostFactory.create(content_object=self.project, author=commenter, text="test1", email_followers=False) # Create a follower by donating donator1 = BlueBottleUserFactory.create() order = OrderFactory.create(user=donator1, status=StatusDefinition.CREATED) DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) order.locked() order.success() order.save() # Create a follower by being a fundraiser for the project fundraiser_person = BlueBottleUserFactory.create() FundraiserFactory(project=self.project, owner=fundraiser_person) self.assertEqual(Follow.objects.count(), 3) voter = BlueBottleUserFactory.create() VoteFactory(voter=voter, project=self.project) self.assertEqual(Follow.objects.count(), 4) # Project owner creates a wallpost and emails followers TextWallpostFactory.create( content_object=self.project, author=self.project.owner, text="test2", email_followers=True) mail_count = 0 # People who should get an email: self.some_user, voter, task_owner1, # fundraiser_person, commenter, and donator1 receivers = [voter.email, task_owner1.email, fundraiser_person.email, donator1.email] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) receivers.remove(email.to[0]) self.assertEqual(mail_count, 4) self.assertEqual(receivers, [])
def test_wallpost_delete_mail_project(self): """ Test that the relevant people don't get an email when the email_followers option is selected for a project during wallpost create but is then deleted. """ # On a project page, task owners, fundraisers, and people who donated, get a mail. # Create a follower by being a task owner task_owner1 = BlueBottleUserFactory.create() TaskFactory.create( author=task_owner1, project=self.project ) # Add extra project and owner that should not get any email project_owner = BlueBottleUserFactory.create() ProjectFactory(owner=project_owner, status=self.phase1) # iLeaving a wallpost should not create a follower commenter = BlueBottleUserFactory.create() TextWallpostFactory.create(content_object=self.project, author=commenter, text="test1", email_followers=False) # Create a follower by donating donator1 = BlueBottleUserFactory.create() order = OrderFactory.create(user=donator1, status=StatusDefinition.CREATED) DonationFactory(order=order, amount=35, project=self.project, fundraiser=None) order.locked() order.success() order.save() # Create a follower by being a fundraiser for the project fundraiser_person = BlueBottleUserFactory.create() FundraiserFactory(project=self.project, owner=fundraiser_person) self.assertEqual(Follow.objects.count(), 3) voter = BlueBottleUserFactory.create() VoteFactory(voter=voter, project=self.project) self.assertEqual(Follow.objects.count(), 4) # Project owner creates a wallpost and emails followers some_wallpost_2 = TextWallpostFactory.create( content_object=self.project, author=self.project.owner, text="test2", email_followers=True) mail_count = 0 # People who should get an email: self.some_user, voter, task_owner1, # fundraiser_person, commenter, and donator1 receivers = [voter.email, task_owner1.email, fundraiser_person.email, donator1.email] for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) receivers.remove(email.to[0]) self.assertEqual(mail_count, 4) self.assertEqual(receivers, []) # Setup for mail counting after wallpost delete mail_count = 0 receivers = [voter.email, task_owner1.email, fundraiser_person.email, donator1.email] # This time we can safely reset the email box to 0 mail.outbox = [] # Ember triggers a save to the record before the actual delete # therefore we can't use the Django delete function. This won't # trigger the email_follower signal to be fired again. To replicate # the server behavior we can simply re-save the wallpost record. This # will cause the signal to fire but with the "created" flag to False. some_wallpost_2.save() # Check that no emails about a new wallpost go out for email in mail.outbox: if "New wallpost on" in email.subject: mail_count += 1 self.assertTrue(email.to[0] in receivers) self.assertEqual(mail_count, 0)
def setUp(self): super(TestEngagementMetricsXls, self).setUp() self.init_projects() self.year = datetime.now().year # Project Phases done_complete = ProjectPhase.objects.get(slug="done-complete") done_incomplete = ProjectPhase.objects.get(slug="done-incomplete") # Users user1 = BlueBottleUserFactory.create() # Projects project1 = ProjectFactory.create(owner=user1, status=done_complete) ProjectFactory.create(owner=user1, status=done_incomplete) # Wallposts TextWallpostFactory.create(content_object=project1, author=user1, editor=user1, text="test1", email_followers=False) # Votes VoteFactory(project=project1, voter=user1) # Fundraisers fundraiser = FundraiserFactory(project=project1, owner=user1) # Donations order1 = OrderFactory.create(user=user1) DonationFactory(order=order1, fundraiser=fundraiser, project=project1) order1.locked() order1.save() order1.success() order1.save() order2 = OrderFactory.create(user=None) donation2 = DonationFactory(order=order2, fundraiser=fundraiser, project=project1) donation2.anonymous = True order2.locked() order2.save() order2.success() order2.save() # Tasks task = TaskFactory.create(author=user1, project=project1, people_needed=2, status='realized') task_member = TaskMemberFactory.create( time_spent=10, member=user1, task=task, status=TaskMember.TaskMemberStatuses.applied) task_member.status = TaskMember.TaskMemberStatuses.realized task_member.save() # Simulate user Login jwt_token = user1.get_jwt_token() task_member_url = reverse('task-member-detail', kwargs={'pk': task_member.id}) self.client.get(task_member_url, token="JWT {0}".format(jwt_token)) # xls export self.xls_file_name = 'test.xlsx' self.xls_file_path = os.path.join(settings.PROJECT_ROOT, self.xls_file_name) self.command = EngagementCommand()