Ejemplo n.º 1
0
    def test_create_follow_create_vote(self):
        """
            Test that a Follow is created if a user, that is not the owner,
            casts a vote. User will follow project.
        """
        self.assertEqual(Follow.objects.count(), 0)

        voter = BlueBottleUserFactory.create()

        vote = VoteFactory.create(
            voter=voter,
            project=self.project,
        )

        self.assertEqual(Follow.objects.count(), 1)
        self.assertEqual(Follow.objects.all()[0].followed_object, self.project)
        self.assertEqual(Follow.objects.all()[0].user, voter)

        # Test that no follower is created when the task owner
        # is also the project owner
        project_owner_vote = VoteFactory.create(
            voter=self.project.owner,
            project=self.project
        )

        self.assertEqual(Follow.objects.count(), 1)
Ejemplo n.º 2
0
    def test_create_follow_create_vote(self):
        """
            Test that a Follow is created if a user, that is not the owner,
            casts a vote. User will follow project.
        """
        self.assertEqual(Follow.objects.count(), 0)

        voter = BlueBottleUserFactory.create()

        VoteFactory.create(
            voter=voter,
            project=self.project,
        )

        self.assertEqual(Follow.objects.count(), 1)
        self.assertEqual(Follow.objects.all()[0].followed_object, self.project)
        self.assertEqual(Follow.objects.all()[0].user, voter)

        # Test that no follower is created when the task owner
        # is also the project owner
        VoteFactory.create(
            voter=self.project.owner,
            project=self.project
        )

        self.assertEqual(Follow.objects.count(), 1)
Ejemplo n.º 3
0
    def test_get_votes(self):
        VoteFactory.create_batch(11, project=self.project1)
        VoteFactory.create_batch(12, project=self.project2)

        response = self.client.get(self.vote_url +
                                   '?project={0}'.format(self.project1.slug))

        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEqual(data['count'], 11)
        self.assertEqual(len(data['results']), 10)
Ejemplo n.º 4
0
    def test_get_votes(self):
        VoteFactory.create_batch(11, project=self.project1)
        VoteFactory.create_batch(12, project=self.project2)

        response = self.client.get(self.vote_url +
                                   '?project={0}'.format(self.project1.slug))

        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEqual(data['count'], 11)
        self.assertEqual(len(data['results']), 10)
Ejemplo n.º 5
0
    def setUp(self):
        super(TestProjectPopularity, self).setUp()
        self.init_projects()

        self.project = ProjectFactory.create()

        VoteFactory.create(project=self.project)
        task = TaskFactory.create(project=self.project)
        TaskMemberFactory.create(task=task)

        order = OrderFactory.create(status=StatusDefinition.SUCCESS)

        DonationFactory(order=order, project=self.project)
Ejemplo n.º 6
0
    def setUp(self):
        super(TestProjectPopularity, self).setUp()
        self.init_projects()

        self.project = ProjectFactory.create()

        VoteFactory.create(project=self.project)
        task = TaskFactory.create(project=self.project)
        TaskMemberFactory.create(task=task)

        order = OrderFactory.create(status=StatusDefinition.SUCCESS)

        DonationFactory(order=order, project=self.project)
Ejemplo n.º 7
0
    def test_get_user_votes(self):
        VoteFactory.create_batch(11, project=self.project1)
        VoteFactory.create_batch(3, project=self.project2)
        VoteFactory.create(voter=self.user, project=self.project1)
        VoteFactory.create(voter=self.user, project=self.project2)

        vote_url = self.vote_url + '?voter={0}'.format(self.user.id)
        response = self.client.get(vote_url)

        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEqual(data['count'], 2)
        self.assertEqual(len(data['results']), 2)
Ejemplo n.º 8
0
    def test_get_user_votes(self):
        VoteFactory.create_batch(11, project=self.project1)
        VoteFactory.create_batch(3, project=self.project2)
        VoteFactory.create(voter=self.user, project=self.project1)
        VoteFactory.create(voter=self.user, project=self.project2)

        vote_url = self.vote_url + '?voter={0}'.format(self.user.id)
        response = self.client.get(vote_url)

        self.assertEqual(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEqual(data['count'], 2)
        self.assertEqual(len(data['results']), 2)
Ejemplo n.º 9
0
    def test_vote_already_votes_twice(self):
        category = CategoryFactory.create()

        self.project1.categories = [category]
        self.project1.save()

        self.project2.categories = [category]
        self.project2.save()

        self.project3.categories = [category]
        self.project3.save()

        VoteFactory.create(voter=self.user, project=self.project1)
        VoteFactory.create(voter=self.user, project=self.project2)

        response = self.client.post(self.vote_url,
                                    {'project': self.project3.slug},
                                    token=self.user_token)
        self.assertEqual(response.status_code, 400)
        self.assertEqual(
            unicode(response.data['non_field_errors'][0]), u'You already voted.'
        )
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
    def test_tags_generation(self, queue_mock):
        vote = VoteFactory.create(project=self.project)
        project = vote.project
        expected_tags = {
            'type': 'vote',
            'tenant': u'test',
            'location': self.location.name,
            'location_group': self.location.group.name,
            'country': project.country.name,
            'theme': project.theme.name,
            'theme_slug': project.theme.slug

        }
        expected_fields = {
            'id': vote.id,
            'user_id': vote.voter.id,
            'project_id': vote.project.id
        }

        args, kwargs = queue_mock.call_args
        self.assertEqual(kwargs['tags'], expected_tags)
        self.assertEqual(kwargs['fields'], expected_fields)
Ejemplo n.º 12
0
    def test_tags_generation(self, queue_mock):
        vote = VoteFactory.create(project=self.project)
        project = vote.project
        expected_tags = {
            'type': 'vote',
            'tenant': u'test',
            'location': self.location.name,
            'location_group': self.location.group.name,
            'country': project.country.name,
            'theme': project.theme.name,
            'theme_slug': project.theme.slug
        }
        expected_fields = {
            'id': vote.id,
            'user_id': vote.voter.id,
            'project_id': vote.project.id
        }

        args, kwargs = queue_mock.call_args
        self.assertEqual(kwargs['tags'], expected_tags)
        self.assertEqual(kwargs['fields'], expected_fields)
        self.assertEqual(kwargs['timestamp'], vote.created)
Ejemplo n.º 13
0
    def setUp(self):
        super(StatisticsDateTest, self).setUp()

        self.init_projects()

        new_user = BlueBottleUserFactory.create()
        old_user = BlueBottleUserFactory.create()

        status_realized = ProjectPhase.objects.get(slug='done-complete')
        status_campaign = ProjectPhase.objects.get(slug='campaign')

        now = timezone.now()
        last_year = timezone.now() - datetime.timedelta(days=365)

        new_project = ProjectFactory.create(amount_asked=5000,
                                            status=status_realized,
                                            owner=old_user,
                                            campaign_ended=now,
                                            campaign_started=now,
                                            amount_extra=100)
        ProjectFactory.create(amount_asked=5000,
                              status=status_campaign,
                              owner=old_user,
                              campaign_started=now)
        old_project = ProjectFactory.create(amount_asked=5000,
                                            status=status_realized,
                                            owner=old_user,
                                            campaign_ended=last_year,
                                            campaign_started=last_year,
                                            amount_extra=200)
        ProjectFactory.create(amount_asked=5000,
                              status=status_campaign,
                              owner=old_user,
                              campaign_started=last_year,
                              amount_extra=1000)

        VoteFactory.create(voter=old_user, created=now)
        vote = VoteFactory.create(voter=old_user)
        vote.created = last_year
        vote.save()

        old_task = TaskFactory.create(author=old_user,
                                      project=old_project,
                                      status=Task.TaskStatuses.realized,
                                      deadline=last_year)
        TaskMemberFactory.create(task=old_task,
                                 member=old_user,
                                 status='realized')

        new_task = TaskFactory.create(author=old_user,
                                      project=new_project,
                                      status=Task.TaskStatuses.realized,
                                      deadline=now)
        TaskMemberFactory.create(task=new_task,
                                 member=new_user,
                                 status='realized')

        order1 = OrderFactory.create(user=old_user,
                                     status=StatusDefinition.SUCCESS)
        order1.created = now
        order1.save()

        DonationFactory.create(amount=Money(1000, 'EUR'),
                               order=order1,
                               project=old_project,
                               fundraiser=None)

        order2 = OrderFactory.create(user=old_user,
                                     status=StatusDefinition.SUCCESS)
        order2.created = last_year
        order2.save()

        DonationFactory.create(amount=Money(1000, 'EUR'),
                               order=order2,
                               project=old_project,
                               fundraiser=None)
Ejemplo n.º 14
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, [])
Ejemplo n.º 15
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()
Ejemplo n.º 16
0
    def test_votes_stats(self):
        VoteFactory.create(voter=self.some_user)
        VoteFactory.create(voter=self.some_user)
        VoteFactory.create(voter=self.another_user)

        self.assertEqual(self.stats.votes_cast, 3)
Ejemplo n.º 17
0
    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)