Esempio n. 1
0
    def setUp(self):
        super(HomepageEndpointTestCase, self).setUp()
        self.init_projects()

        self.stats = Statistics()

        """
        Create 10 Project instances for one user with half in the campaign phase
        and the other half in the done-complete phase
        This will create:
            - 10 running or realised projects
            - 10 campaigners (eg 10 new people involved)
        """
        self.user1 = BlueBottleUserFactory.create()
        self.campaign_phase = ProjectPhase.objects.get(slug='campaign')
        self.plan_phase = ProjectPhase.objects.get(slug='done-complete')
        projects = []

        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                project = ProjectFactory.create(title=char * 3, slug=char * 3, status=self.campaign_phase)
            else:
                project = ProjectFactory.create(title=char * 3, slug=char * 3, status=self.plan_phase)

            projects.append(project)

        """
        Create 10 TaskMember instances for one project.
        This will create:
            - 1 realised task
            - 1 task owner (eg 1 new person involved)
            - 10 task members (eg 10 new people involved)
        """
        self.task = TaskFactory.create(project=projects[0], status=Task.TaskStatuses.realized)
        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                task = TaskMemberFactory.create(task=self.task)
            else:
                task = TaskMemberFactory.create(task=self.task)

        """
        Create 10 Donations with half to fundraisers
        This will create:
            - 10 donations of 1000 (total amount of 10000)
            - 10 donators (eg 10 new people involved)
            - 5 fundraisers (eg 5 new people involved)
        """
        for char in 'abcdefghij':
            if ord(char) % 2 == 1:
                self.order = OrderFactory.create(status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000, order=self.order, fundraiser=None)
            else:
                self.order = OrderFactory.create(status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000, order=self.order)
Esempio n. 2
0
    def test_since_yesterday(self):
        stats = Statistics(start=timezone.now() - datetime.timedelta(days=1))

        self.assertEqual(stats.people_involved, 2)
        self.assertEqual(stats.donated_total, Money(1000, 'EUR'))
        self.assertEqual(stats.projects_online, 1)
        self.assertEqual(stats.projects_realized, 2)
        self.assertEqual(stats.tasks_realized, 1)
        self.assertEqual(stats.votes_cast, 1)
        self.assertEqual(stats.amount_matched, Money(100, 'EUR'))
Esempio n. 3
0
    def test_all(self):
        stats = Statistics()

        self.assertEqual(stats.people_involved, 2)
        self.assertEqual(stats.donated_total, Money(2000, 'EUR'))
        self.assertEqual(stats.projects_online, 2)
        self.assertEqual(stats.projects_realized, 2)
        self.assertEqual(stats.tasks_realized, 2)
        self.assertEqual(stats.votes_cast, 2)
        self.assertEqual(stats.amount_matched, Money(1300, 'EUR'))
Esempio n. 4
0
    def setUp(self):
        super(InitialStatisticsTest, self).setUp()

        self.stats = Statistics()

        # Required by Project model save method
        self.init_projects()

        self.some_user = BlueBottleUserFactory.create()

        self.some_project = ProjectFactory.create(amount_asked=5000,
                                                  owner=self.some_user)
Esempio n. 5
0
    def setUp(self):
        super(InitialStatisticsTest, self).setUp()

        self.stats = Statistics()

        # Required by Project model save method
        self.init_projects()

        self.some_user = BlueBottleUserFactory.create()

        self.some_project = ProjectFactory.create(amount_asked=5000,
                                                  owner=self.some_user)
Esempio n. 6
0
    def test_last_year(self):
        stats = Statistics(
            start=timezone.now() - datetime.timedelta(days=2 * 365),
            end=timezone.now() - datetime.timedelta(days=364),
        )

        self.assertEqual(stats.people_involved, 1)
        self.assertEqual(stats.donated_total, Money(1000, 'EUR'))
        self.assertEqual(stats.projects_online, 1)
        self.assertEqual(stats.projects_realized, 0)
        self.assertEqual(stats.tasks_realized, 1)
        self.assertEqual(stats.votes_cast, 1)
        self.assertEqual(stats.amount_matched, Money(200, 'EUR'))
Esempio n. 7
0
class InitialStatisticsTest(BluebottleTestCase):
    def setUp(self):
        super(InitialStatisticsTest, self).setUp()

        self.stats = Statistics()

        # Required by Project model save method
        self.init_projects()

        self.some_user = BlueBottleUserFactory.create()

        self.some_project = ProjectFactory.create(amount_asked=5000,
                                                  owner=self.some_user)

    def tearDown(self):
        self.stats.clear_cached()

    def test_initial_stats(self):
        self.assertEqual(self.stats.projects_online, 0)
        self.assertEqual(self.stats.projects_realized, 0)
        self.assertEqual(self.stats.tasks_realized, 0)
        self.assertEqual(self.stats.people_involved, 0)
        self.assertEqual(self.stats.donated, '000')
Esempio n. 8
0
    def setUp(self):
        super(StatisticsTest, self).setUp()

        self.stats = Statistics()

        # Required by Project model save method
        self.init_projects()

        self.some_user = BlueBottleUserFactory.create()
        self.another_user = BlueBottleUserFactory.create()

        self.campaign_status = ProjectPhase.objects.get(slug='campaign')

        self.some_project = ProjectFactory.create(amount_asked=5000,
                                                  owner=self.some_user)
        self.task = None
        self.donation = None
        self.order = None
Esempio n. 9
0
    def setUp(self):
        super(StatisticsTest, self).setUp()

        self.stats = Statistics()

        # Required by Project model save method
        self.init_projects()

        self.some_user = BlueBottleUserFactory.create()
        self.another_user = BlueBottleUserFactory.create()

        self.campaign_status = ProjectPhase.objects.get(slug='campaign')

        self.some_project = ProjectFactory.create(amount_asked=5000,
                                                  owner=self.some_user)
        self.task = None
        self.donation = None
        self.order = None
Esempio n. 10
0
class HomepageEndpointTestCase(BluebottleTestCase):
    """
    Integration tests for the Statistics API.
    """

    def setUp(self):
        super(HomepageEndpointTestCase, self).setUp()
        self.init_projects()

        self.stats = Statistics()

        """
        Create 10 Project instances for one user with half in the campaign phase
        and the other half in the done-complete phase
        This will create:
            - 10 running or realised projects
            - 10 campaigners (eg 10 new people involved)
        """
        self.user1 = BlueBottleUserFactory.create()
        self.campaign_phase = ProjectPhase.objects.get(slug='campaign', viewable=True)
        self.plan_phase = ProjectPhase.objects.get(slug='done-complete')
        self.en = Language.objects.get(code='en')
        projects = []

        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                project = ProjectFactory.create(title=char * 3, slug=char * 3,
                                                status=self.campaign_phase,
                                                language=self.en,
                                                is_campaign=True)
            else:
                project = ProjectFactory.create(title=char * 3, slug=char * 3,
                                                status=self.plan_phase,
                                                language=self.en)

            projects.append(project)

        """
        Create 10 TaskMember instances for one project.
        This will create:
            - 1 realised task
            - 1 task owner (eg 1 new person involved)
            - 10 task members (eg 10 new people involved)
        """
        self.task = TaskFactory.create(project=projects[0],
                                       status=Task.TaskStatuses.realized)
        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                task = TaskMemberFactory.create(task=self.task)
            else:
                task = TaskMemberFactory.create(task=self.task)

        """
        Create 10 Donations with half to fundraisers
        This will create:
            - 10 donations of 1000 (total amount of 10000)
            - 10 donators (eg 10 new people involved)
            - 5 fundraisers (eg 5 new people involved)
        """
        for char in 'abcdefghij':
            if ord(char) % 2 == 1:
                self.order = OrderFactory.create(
                    status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000,
                                                       order=self.order,
                                                       fundraiser=None)
            else:
                self.order = OrderFactory.create(
                    status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000,
                                                       order=self.order)

        StatisticFactory.create(type='donated_total', title='Donated', language='en')
        StatisticFactory.create(type='projects_online', title='Projects online', language='en')
        StatisticFactory.create(type='projects_realized', title='Projects realised', language='en')
        StatisticFactory.create(type='tasks_realized', title='Tasks realised', language='en')
        StatisticFactory.create(type='people_involved', title='Peeps', language='en')
        StatisticFactory.create(type='manual', title='Rating', value='9.3', language='en')

    def tearDown(self):
        self.stats.clear_cached()

    def test_homepage_stats(self):
        response = self.client.get(reverse('stats', kwargs={'language': 'en'}))

        self.assertEqual(len(response.data['projects']), 4)

        impact = response.data['statistics']
        self.assertEqual(impact[0]['title'], 'Donated')
        self.assertEqual(impact[0]['value'], u'10000')
        self.assertEqual(impact[1]['title'], 'Projects online')
        self.assertEqual(impact[1]['value'], u'5')
        self.assertEqual(impact[2]['title'], 'Projects realised')
        self.assertEqual(impact[2]['value'], u'5')
        self.assertEqual(impact[3]['title'], 'Tasks realised')
        self.assertEqual(impact[3]['value'], u'1')
        self.assertEqual(impact[4]['title'], 'Peeps')
        self.assertEqual(impact[4]['value'], u'36')

        self.assertEqual(impact[5]['title'], 'Rating')
        self.assertEqual(impact[5]['value'], '9.3')
Esempio n. 11
0
class HomepageEndpointTestCase(BluebottleTestCase):
    """
    Integration tests for the Statistics API.
    """
    def setUp(self):
        super(HomepageEndpointTestCase, self).setUp()
        self.init_projects()

        self.stats = Statistics()

        """
        Create 10 Project instances for one user with half in the campaign phase
        and the other half in the done-complete phase
        This will create:
            - 10 running or realised projects
            - 10 campaigners (eg 10 new people involved)
        """
        self.user1 = BlueBottleUserFactory.create()
        self.campaign_phase = ProjectPhase.objects.get(slug='campaign')
        self.plan_phase = ProjectPhase.objects.get(slug='done-complete')
        projects = []

        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                project = ProjectFactory.create(title=char * 3, slug=char * 3, status=self.campaign_phase)
            else:
                project = ProjectFactory.create(title=char * 3, slug=char * 3, status=self.plan_phase)

            projects.append(project)

        """
        Create 10 TaskMember instances for one project.
        This will create:
            - 1 realised task
            - 1 task owner (eg 1 new person involved)
            - 10 task members (eg 10 new people involved)
        """
        self.task = TaskFactory.create(project=projects[0], status=Task.TaskStatuses.realized)
        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                task = TaskMemberFactory.create(task=self.task)
            else:
                task = TaskMemberFactory.create(task=self.task)

        """
        Create 10 Donations with half to fundraisers
        This will create:
            - 10 donations of 1000 (total amount of 10000)
            - 10 donators (eg 10 new people involved)
            - 5 fundraisers (eg 5 new people involved)
        """
        for char in 'abcdefghij':
            if ord(char) % 2 == 1:
                self.order = OrderFactory.create(status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000, order=self.order, fundraiser=None)
            else:
                self.order = OrderFactory.create(status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000, order=self.order)

    def tearDown(self):
        self.stats.clear_cached()

    def test_homepage_stats(self):
        response = self.client.get(reverse('stats'))

        self.assertEqual(response.data['donated'], Decimal('10000.00'))
        self.assertEqual(response.data['projects_online'], 5)
        self.assertEqual(response.data['projects_realized'], 5)
        self.assertEqual(response.data['tasks_realized'], 1)
        self.assertEqual(response.data['people_involved'], 36)
Esempio n. 12
0
    def setUp(self):
        super(HomepageEndpointTestCase, self).setUp()
        self.init_projects()

        self.stats = Statistics()
        """
        Create 10 Project instances for one user with half in the campaign phase
        and the other half in the done-complete phase
        This will create:
            - 10 running or realised projects
            - 10 campaigners (eg 10 new people involved)
        """
        self.user1 = BlueBottleUserFactory.create()
        self.campaign_phase = ProjectPhase.objects.get(slug='campaign',
                                                       viewable=True)
        self.plan_phase = ProjectPhase.objects.get(slug='done-complete')
        self.en = Language.objects.get(code='en')
        projects = []

        for char in 'abcdefghij':
            # Put half of the projects in the campaign phase.
            if ord(char) % 2 == 1:
                project = ProjectFactory.create(title=char * 3,
                                                slug=char * 3,
                                                status=self.campaign_phase,
                                                language=self.en,
                                                is_campaign=True)
            else:
                project = ProjectFactory.create(title=char * 3,
                                                slug=char * 3,
                                                status=self.plan_phase,
                                                language=self.en)

            projects.append(project)
        """
        Create 10 TaskMember instances for one project.
        This will create:
            - 1 realised task
            - 1 task owner (eg 1 new person involved)
            - 10 task members (eg 10 new people involved)
        """
        self.task = TaskFactory.create(project=projects[0],
                                       status=Task.TaskStatuses.realized)
        for char in 'abcdefghij':
            TaskMemberFactory.create(task=self.task, status='realized')
        """
        Create 10 Donations with half to fundraisers
        This will create:
            - 10 donations of 1000 (total amount of 10000)
            - 10 donators (eg 10 new people involved)
            - 5 fundraisers (eg 5 new people involved)
        """
        for char in 'abcdefghij':
            if ord(char) % 2 == 1:
                self.order = OrderFactory.create(
                    status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000,
                                                       order=self.order,
                                                       fundraiser=None)
            else:
                self.order = OrderFactory.create(
                    status=StatusDefinition.SUCCESS)
                self.donation = DonationFactory.create(amount=1000,
                                                       order=self.order)

        StatisticFactory.create(type='donated_total',
                                title='Donated',
                                language='en')
        StatisticFactory.create(type='projects_online',
                                title='Projects online',
                                language='en')
        StatisticFactory.create(type='projects_realized',
                                title='Projects realised',
                                language='en')
        StatisticFactory.create(type='tasks_realized',
                                title='Tasks realised',
                                language='en')
        StatisticFactory.create(type='people_involved',
                                title='Peeps',
                                language='en')
        StatisticFactory.create(type='manual',
                                title='Rating',
                                value='9.3',
                                language='en')
Esempio n. 13
0
class StatisticsTest(BluebottleTestCase):
    def setUp(self):
        super(StatisticsTest, self).setUp()

        self.stats = Statistics()

        # Required by Project model save method
        self.init_projects()

        self.some_user = BlueBottleUserFactory.create()
        self.another_user = BlueBottleUserFactory.create()

        self.campaign_status = ProjectPhase.objects.get(slug='campaign')

        self.some_project = ProjectFactory.create(amount_asked=5000,
                                                  owner=self.some_user)
        self.task = None
        self.donation = None
        self.order = None

    def tearDown(self):
        self.stats.clear_cached()

    def test_project_campaign_stats(self):
        self.some_project.status = self.campaign_status
        self.some_project.save()

        self.assertEqual(self.stats.projects_online, 1)
        # People involved:
        # - campaigner
        self.assertEqual(self.stats.people_involved, 1)

    def test_project_complete_stats(self):
        self.some_project.status = ProjectPhase.objects.get(
            slug='done-complete')
        self.some_project.save()

        self.assertEqual(self.stats.projects_online, 0)
        self.assertEqual(self.stats.projects_realized, 1)
        # People involved:
        # - campaigner
        self.assertEqual(self.stats.people_involved, 1)

    def test_task_stats(self):
        self.assertEqual(self.stats.tasks_realized, 0)

        # project is in campaign phase
        self.some_project.status = self.campaign_status
        self.some_project.save()

        # Create a task and add other user as member
        self.task = TaskFactory.create(author=self.some_user,
                                       project=self.some_project,
                                       status=Task.TaskStatuses.realized)
        TaskMemberFactory.create(task=self.task, member=self.another_user)

        self.assertEqual(self.stats.tasks_realized, 1)
        # People involved:
        # - campaigner
        # - task member (another_user)
        self.assertEqual(self.stats.people_involved, 2)

    def test_donation_stats(self):
        self.some_project.status = self.campaign_status
        self.some_project.save()

        self.order = OrderFactory.create(user=self.another_user,
                                         status=StatusDefinition.SUCCESS)
        self.donation = DonationFactory.create(amount=1000, order=self.order,
                                               project=self.some_project,
                                               fundraiser=None)

        self.assertEqual(self.stats.donated, 1000)
        # People involved:
        # - campaigner
        # - donator (another_user)
        self.assertEqual(self.stats.people_involved, 2)

    def test_donation_total_stats(self):
        self.some_project.status = self.campaign_status
        self.some_project.save()

        self.order1 = OrderFactory.create(user=self.another_user,
                                          status=StatusDefinition.SUCCESS)
        self.donation1 = DonationFactory.create(amount=1000, order=self.order1,
                                                project=self.some_project,
                                                fundraiser=None)

        self.order2 = OrderFactory.create(user=None,
                                          status=StatusDefinition.SUCCESS)
        self.donation2 = DonationFactory.create(amount=1000, order=self.order2,
                                                project=self.some_project,
                                                fundraiser=None)

        self.assertEqual(self.stats.donated, 2000)
        # People involved:
        # - campaigner
        # - donator (another_user)
        # - donator (anon)
        self.assertEqual(self.stats.people_involved, 3)