Exemple #1
0
    def test_results_stats_no_dates(self):
        self.page.start_date = None
        self.page.end_date = None
        self.page.save()

        long_ago = now() - timedelta(days=365 * 2)
        yesterday = now() - timedelta(days=1)
        user = BlueBottleUserFactory(is_co_financer=False)
        project = ProjectFactory(created=yesterday, owner=user)
        project = ProjectFactory(owner=user)
        order1 = OrderFactory(user=user, confirmed=yesterday, status='success')
        order1.created = yesterday
        order1.save()
        order2 = OrderFactory(user=user, confirmed=long_ago, status='success')
        order1.created = long_ago
        order1.save()

        DonationFactory(order=order1, amount=Money(50, 'EUR'), project=project)
        DonationFactory(order=order2, amount=Money(50, 'EUR'), project=project)

        block = StatsContent.objects.create_for_placeholder(self.placeholder, title='Look at us!')
        self.stat1 = StatFactory(type='manual', title='Poffertjes', value=3500, block=block)
        self.stat2 = StatFactory(type='donated_total', title='Donations', value=None, block=block)

        response = self.client.get(self.url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)

        stats = response.data['blocks'][0]
        self.assertEqual(stats['type'], 'statistics')
        self.assertEqual(stats['title'], 'Look at us!')
        self.assertEqual(stats['stats'][0]['title'], self.stat1.title)
        self.assertEqual(stats['stats'][0]['value'], str(self.stat1.value))
        self.assertEqual(stats['stats'][1]['title'], self.stat2.title)
        self.assertEqual(stats['stats'][1]['value'], {"amount": Decimal('100'), "currency": "EUR"})
    def test_results_stats_no_dates(self):
        self.page.start_date = None
        self.page.end_date = None
        self.page.save()

        long_ago = now() - timedelta(days=365 * 2)
        yesterday = now() - timedelta(days=1)
        user = BlueBottleUserFactory(is_co_financer=False)
        funding = FundingFactory(status='open', owner=user)

        DonationFactory.create(activity=funding,
                               status='succeeded',
                               transition_date=yesterday,
                               user=user,
                               amount=Money(50, 'EUR'))
        DonationFactory.create(activity=funding,
                               status='succeeded',
                               transition_date=long_ago,
                               user=user,
                               amount=Money(50, 'EUR'))

        block = StatsContent.objects.create_for_placeholder(
            self.placeholder, title='Look at us!')
        self.stat1 = StatFactory(type='manual',
                                 title='Poffertjes',
                                 value=3500,
                                 block=block)
        self.stat2 = StatFactory(type='donated_total',
                                 title='Donations',
                                 value=None,
                                 block=block)

        response = self.client.get(self.url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)

        stats = response.data['blocks'][0]
        self.assertEqual(stats['type'], 'statistics')
        self.assertEqual(stats['title'], 'Look at us!')
        self.assertEqual(stats['stats'][0]['title'], self.stat1.title)
        self.assertEqual(stats['stats'][0]['value'], str(self.stat1.value))
        self.assertEqual(stats['stats'][1]['title'], self.stat2.title)
        self.assertEqual(stats['stats'][1]['value'], {
            "amount": Decimal('100'),
            "currency": "EUR"
        })
    def test_results_list(self):
        quote_block = QuotesContent.objects.create_for_placeholder(
            self.placeholder)
        self.quote = QuoteFactory(block=quote_block)

        stat_block = StatsContent.objects.create_for_placeholder(
            self.placeholder)
        self.stat = StatFactory(block=stat_block)

        response = self.client.get(self.url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        self.assertEquals(len(response.data['blocks']), 2)
        self.assertEquals(response.data['blocks'][0]['type'], 'quotes')
        self.assertEquals(response.data['blocks'][1]['type'], 'statistics')