Exemplo n.º 1
0
    def test_sort_created(self):
        first = InitiativeFactory.create(status='approved')
        second = InitiativeFactory.create(status='approved')
        third = InitiativeFactory.create(status='approved')

        first.created = datetime.datetime(2018,
                                          5,
                                          8,
                                          tzinfo=get_current_timezone())
        first.save()
        second.created = datetime.datetime(2018,
                                           5,
                                           7,
                                           tzinfo=get_current_timezone())
        second.save()
        third.created = datetime.datetime(2018,
                                          5,
                                          9,
                                          tzinfo=get_current_timezone())
        third.save()

        response = self.client.get(self.url + '?sort=date',
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 3)
        self.assertEqual(data['data'][0]['id'], str(third.pk))
        self.assertEqual(data['data'][1]['id'], str(first.pk))
        self.assertEqual(data['data'][2]['id'], str(second.pk))
Exemplo n.º 2
0
    def test_sort_activity_date(self):
        first = InitiativeFactory.create(status='approved')
        FundingFactory.create(initiative=first,
                              status='open',
                              deadline=now() + datetime.timedelta(days=8))
        FundingFactory.create(initiative=first,
                              status='submitted',
                              deadline=now() + datetime.timedelta(days=7))

        second = InitiativeFactory.create(status='approved')
        EventFactory.create(initiative=second,
                            status='open',
                            start=now() + datetime.timedelta(days=7))
        third = InitiativeFactory.create(status='approved')
        EventFactory.create(initiative=third,
                            status='open',
                            start=now() + datetime.timedelta(days=7))
        AssignmentFactory.create(initiative=third,
                                 status='open',
                                 date=now() + datetime.timedelta(days=9))

        response = self.client.get(self.url + '?sort=activity_date',
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 3)
        self.assertEqual(data['data'][0]['id'], str(third.pk))
        self.assertEqual(data['data'][1]['id'], str(first.pk))
        self.assertEqual(data['data'][2]['id'], str(second.pk))
Exemplo n.º 3
0
    def test_create_duplicate_title(self):
        InitiativeFactory.create(title='Some title', status='approved')
        data = {
            'data': {
                'type': 'initiatives',
                'attributes': {
                    'title': 'Some title'
                },
                'relationships': {
                    'theme': {
                        'data': {
                            'type': 'themes',
                            'id': self.theme.pk
                        },
                    }
                }
            }
        }
        response = self.client.post(self.url,
                                    json.dumps(data),
                                    user=self.owner)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        data = response.json()
        self.assertTrue('/data/attributes/title' in (
            error['source']['pointer']
            for error in data['data']['meta']['errors']))
Exemplo n.º 4
0
    def test_initiative_duplicate(self):
        initiative = InitiativeFactory.create()
        InitiativeFactory.create(slug=initiative.slug)

        data = {
            'data': {
                'type': 'initiative-redirects',
                'attributes': {
                    'route': 'project',
                    'params': {
                        'project_id': initiative.slug
                    }
                },
            }
        }
        response = self.client.post(self.url, json.dumps(data))

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.assertEqual(response.json()['data']['attributes']['target-route'],
                         'initiatives.details')

        self.assertEqual(
            response.json()['data']['attributes']['target-params'],
            [initiative.pk, initiative.slug])
Exemplo n.º 5
0
    def test_filter_country(self):
        country1 = CountryFactory.create()
        country2 = CountryFactory.create()

        initiative1 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country1))
        initiative2 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country2))
        initiative3 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country1))
        initiative4 = InitiativeFactory.create(place=GeolocationFactory.create(
            country=country2))

        first = AssignmentFactory.create(status='full', initiative=initiative1)
        ApplicantFactory.create_batch(3, activity=first, status='accepted')

        second = AssignmentFactory.create(status='open',
                                          initiative=initiative3)

        third = AssignmentFactory.create(status='full', initiative=initiative2)
        ApplicantFactory.create_batch(3, activity=third, status='accepted')

        AssignmentFactory.create(status='open', initiative=initiative4)

        response = self.client.get(
            self.url +
            '?sort=popularity&filter[country]={}'.format(country1.id),
            user=self.owner)

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 2)

        self.assertEqual(data['data'][0]['id'], str(second.pk))
        self.assertEqual(data['data'][1]['id'], str(first.pk))
Exemplo n.º 6
0
    def test_no_filter(self):
        InitiativeFactory.create(owner=self.owner, status='approved')
        InitiativeFactory.create(status='approved')

        response = self.client.get(self.url,
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))
        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 2)
Exemplo n.º 7
0
    def test_more_results(self):
        InitiativeFactory.create_batch(19, owner=self.owner, status='approved')
        InitiativeFactory.create(status="approved")

        response = self.client.get(self.url,
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))
        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 20)
        self.assertEqual(len(data['data']), 8)
Exemplo n.º 8
0
    def test_filter_location(self):
        location = LocationFactory.create()
        initiative = InitiativeFactory.create(status='approved',
                                              location=location)
        InitiativeFactory.create(status='approved')

        response = self.client.get(
            self.url + '?filter[location.id]={}'.format(location.pk),
            HTTP_AUTHORIZATION="JWT {0}".format(self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 1)
        self.assertEqual(data['data'][0]['id'], str(initiative.pk))
Exemplo n.º 9
0
    def setUp(self):
        super(EventTransitionTestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.owner = BlueBottleUserFactory()
        self.manager = BlueBottleUserFactory()
        self.other_user = BlueBottleUserFactory()

        self.initiative = InitiativeFactory.create(
            activity_manager=self.manager)
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.event = EventFactory.create(owner=self.owner,
                                         initiative=self.initiative)

        self.event_url = reverse('event-detail', args=(self.event.id, ))
        self.transition_url = reverse('activity-transition-list')

        self.review_data = {
            'data': {
                'type': 'activities/transitions',
                'attributes': {
                    'transition': 'delete',
                },
                'relationships': {
                    'resource': {
                        'data': {
                            'type': 'activities/events',
                            'id': self.event.pk
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
    def setUp(self):
        super(FlutterwavePaymentTestCase, self).setUp()
        self.provider = FlutterwavePaymentProviderFactory.create()

        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory()
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.funding = FundingFactory.create(initiative=self.initiative)
        self.donation = DonationFactory.create(activity=self.funding,
                                               amount=Money(1000, 'NGN'),
                                               user=self.user)

        self.payment_url = reverse('flutterwave-payment-list')

        self.tx_ref = "{}-{}".format(self.provider.prefix, self.donation.id)

        self.data = {
            'data': {
                'type': 'payments/flutterwave-payments',
                'attributes': {
                    'tx-ref': self.tx_ref
                },
                'relationships': {
                    'donation': {
                        'data': {
                            'type': 'contributions/donations',
                            'id': self.donation.pk,
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
    def setUp(self):
        super(FlutterwavePayoutAccountTestCase, self).setUp()

        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory()
        self.initiative = InitiativeFactory.create()
        FlutterwavePaymentProviderFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.funding = FundingFactory.create(initiative=self.initiative)
        self.payout_account = PlainPayoutAccountFactory.create(
            status='verified', owner=self.user)

        self.payout_account_url = reverse('payout-account-list')
        self.bank_account_url = reverse('flutterwave-external-account-list')

        self.data = {
            'data': {
                'type': 'payout-accounts/flutterwave-external-accounts',
                'attributes': {
                    'bank-code': '044',
                    'account-number': '123456789',
                    'account-holder-name': 'Jolof Rice'
                },
                'relationships': {
                    'connect-account': {
                        'data': {
                            'id': self.payout_account.id,
                            'type': 'payout-accounts/plains'
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
    def setUp(self):
        super(TelesomPaymentTestCase, self).setUp()
        TelesomPaymentProvider.objects.all().delete()
        TelesomPaymentProviderFactory.create()

        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory()
        self.initiative = InitiativeFactory.create()

        self.initiative.states.submit(save=True)
        self.initiative.states.approve(save=True)

        self.funding = FundingFactory.create(initiative=self.initiative)
        self.donation = DonationFactory.create(activity=self.funding,
                                               user=self.user)

        self.payment_url = reverse('telesom-payment-list')

        self.data = {
            'data': {
                'type': 'payments/telesom-payments',
                'attributes': {},
                'relationships': {
                    'donation': {
                        'data': {
                            'type': 'contributions/donations',
                            'id': self.donation.pk,
                        }
                    }
                }
            }
        }
Exemplo n.º 13
0
    def setUp(self):
        super(StatisticsDateTest, self).setUp()

        user = BlueBottleUserFactory.create()
        other_user = BlueBottleUserFactory.create()

        for diff in (10, 5, 1):
            initiative = InitiativeFactory.create(owner=user)
            past_date = timezone.now() - datetime.timedelta(days=diff)
            initiative.created = past_date
            initiative.save()
            initiative.states.submit()
            initiative.states.approve(save=True)

            event = EventFactory(
                start=past_date,
                initiative=initiative,
                duration=1,
                transition_date=past_date,
                status='succeeded',
                owner=BlueBottleUserFactory.create(),
            )

            ParticipantFactory.create(activity=event,
                                      status='succeeded',
                                      time_spent=1,
                                      user=other_user)
Exemplo n.º 14
0
    def test_export_impact(self):
        from_date = now() - timedelta(weeks=2)
        to_date = now() + timedelta(weeks=1)
        users = BlueBottleUserFactory.create_batch(5)

        co2 = ImpactType.objects.get(slug='co2')
        co2.active = True
        co2.save()
        water = ImpactType.objects.get(slug='water')
        water.active = True
        water.save()

        initiative = InitiativeFactory.create(owner=users[0])

        assignment = AssignmentFactory.create(owner=users[1],
                                              initiative=initiative)
        assignment.goals.create(type=co2, realized=300)
        assignment.goals.create(type=water, realized=750)

        data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'}
        tenant = connection.tenant
        result = plain_export(Exporter, tenant=tenant, **data)
        book = xlrd.open_workbook(result)

        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 23).value,
            u'Reduce CO\u2082 emissions')
        self.assertEqual(book.sheet_by_name('Tasks').cell(1, 23).value, 300)
        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 24).value, u'Save water')
        self.assertEqual(book.sheet_by_name('Tasks').cell(1, 24).value, 750)
Exemplo n.º 15
0
    def setUp(self):
        super(ParticipantListTestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.participant = BlueBottleUserFactory()

        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.event = EventFactory.create(owner=self.initiative.owner,
                                         initiative=self.initiative)

        self.participant_url = reverse('participant-list')
        self.event_url = reverse('event-detail', args=(self.event.pk, ))

        self.data = {
            'data': {
                'type': 'contributions/participants',
                'attributes': {},
                'relationships': {
                    'activity': {
                        'data': {
                            'id': self.event.pk,
                            'type': 'activities/events',
                        },
                    },
                }
            }
        }
Exemplo n.º 16
0
    def test_sort_matching_theme(self):
        theme = ProjectThemeFactory.create()
        self.owner.favourite_themes.add(theme)
        self.owner.save()

        initiative = InitiativeFactory.create(theme=theme)

        first = EventFactory.create(status='open', capacity=1)
        ParticipantFactory.create(activity=first)
        second = EventFactory.create(status='open',
                                     initiative=initiative,
                                     capacity=1)
        ParticipantFactory.create(activity=second)
        third = EventFactory.create(status='open')
        ParticipantFactory.create(activity=third)
        fourth = EventFactory.create(status='open', initiative=initiative)
        ParticipantFactory.create(activity=fourth)

        response = self.client.get(self.url + '?sort=popularity',
                                   user=self.owner)

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 4)

        self.assertEqual(data['data'][0]['id'], str(fourth.pk))
        self.assertEqual(data['data'][1]['id'], str(third.pk))
        self.assertEqual(data['data'][2]['id'], str(second.pk))
        self.assertEqual(data['data'][3]['id'], str(first.pk))
Exemplo n.º 17
0
    def test_initiative_with_funding(self):
        initiative = InitiativeFactory.create()
        funding = FundingFactory.create(initiative=initiative)

        data = {
            'data': {
                'type': 'initiative-redirects',
                'attributes': {
                    'route': 'project',
                    'params': {
                        'project_id': initiative.slug
                    }
                },
            }
        }
        response = self.client.post(self.url, json.dumps(data))

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.assertEqual(response.json()['data']['attributes']['target-route'],
                         'initiatives.activities.details.funding')

        self.assertEqual(
            response.json()['data']['attributes']['target-params'],
            [funding.pk, funding.slug])
Exemplo n.º 18
0
    def setUp(self):
        super(PledgePayoutAccountDetailTestCase, self).setUp()

        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory()
        self.initiative = InitiativeFactory.create()
        PledgePaymentProviderFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.funding = FundingFactory.create(initiative=self.initiative)
        self.payout_account = PlainPayoutAccountFactory.create(
            status='verified',
            owner=self.user
        )
        self.bank_account = PledgeBankAccountFactory.create(
            connect_account=self.payout_account
        )

        self.bank_account_url = reverse(
            'pledge-external-account-detail', args=(self.bank_account.pk, )
        )

        self.data = {
            'data': {
                'type': 'payout-accounts/pledge-external-accounts',
                'id': self.bank_account.pk,
                'attributes': {
                    'account-number': '11111111',
                },
            }
        }
Exemplo n.º 19
0
    def setUp(self):
        super(ImpactTypeListAPITestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.url = reverse('statistic-list')
        self.user = BlueBottleUserFactory()

        initiative = InitiativeFactory.create()
        event = EventFactory.create(
            initiative=initiative,
            owner=initiative.owner,
            start=timezone.now() - datetime.timedelta(hours=1),
            duration=0.1

        )

        initiative.states.submit(save=True)
        initiative.states.approve(save=True)

        event.refresh_from_db()

        ParticipantFactory.create_batch(5, activity=event)

        self.impact_type = ImpactTypeFactory.create()

        self.impact_goal = ImpactGoalFactory.create(
            type=self.impact_type,
            target=100,
            realized=50
        )

        self.manual = ManualStatisticFactory.create()
        self.impact = ImpactStatisticFactory(impact_type=self.impact_type)
        self.database = DatabaseStatisticFactory(query='people_involved')
Exemplo n.º 20
0
    def setUp(self):
        super(ParticipantTransitionTestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.url = reverse('event-list')
        self.participant_user = BlueBottleUserFactory()

        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)

        self.event = EventFactory.create(owner=self.initiative.owner,
                                         initiative=self.initiative)
        self.participant = ParticipantFactory.create(
            user=self.participant_user, activity=self.event)

        self.transition_url = reverse('participant-transition-list')
        self.event_url = reverse('event-detail', args=(self.event.pk, ))

        self.data = {
            'data': {
                'type': 'contributions/participant-transitions',
                'attributes': {
                    'transition': 'withdraw',
                },
                'relationships': {
                    'resource': {
                        'data': {
                            'type': 'contributions/participants',
                            'id': self.participant.pk
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
    def setUp(self):
        super(PaymentTestCase, self).setUp()
        self.client = JSONAPITestClient()
        self.user = BlueBottleUserFactory(can_pledge=True)
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)

        self.funding = FundingFactory.create(initiative=self.initiative)
        self.donation = DonationFactory.create(activity=self.funding, user=self.user)

        self.donation_url = reverse('funding-donation-list')
        self.payment_url = reverse('pledge-payment-list')

        self.data = {
            'data': {
                'type': 'payments/pledge-payments',
                'relationships': {
                    'donation': {
                        'data': {
                            'type': 'contributions/donations',
                            'id': self.donation.pk,
                        }
                    }
                }
            }
        }
        mail.outbox = []
Exemplo n.º 22
0
    def setUp(self):
        self.initiative = InitiativeFactory.create()
        self.initiative.states.submit()
        self.initiative.states.approve(save=True)
        self.funding = FundingFactory.create(
            initiative=self.initiative,
            duration=30,
            target=Money(1000, 'EUR')
        )
        BudgetLineFactory.create(activity=self.funding)
        payout_account = StripePayoutAccountFactory.create(reviewed=True, status='verified')
        self.bank_account = ExternalAccountFactory.create(connect_account=payout_account, status='verified')
        self.funding.bank_account = self.bank_account
        self.funding.states.submit()
        self.funding.states.approve(save=True)

        for donation in DonationFactory.create_batch(
                3,
                amount=Money(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                2,
                amount=Money(200, 'USD'),
                payout_amount=(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(100, 'USD'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        donation = DonationFactory.create(
            amount=Money(750, 'EUR'),
            activity=self.funding,
            status='succeeded')
        PledgePaymentFactory.create(donation=donation)

        self.donation = donation

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(150, 'EUR'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)

        for donation in DonationFactory.create_batch(
                5,
                amount=Money(100, 'USD'),
                activity=self.funding,
                status='succeeded'):
            StripePaymentFactory.create(donation=donation)
Exemplo n.º 23
0
    def test_search_boost(self):
        first = InitiativeFactory.create(title='Something else',
                                         pitch='Lorem ipsum dolor sit amet',
                                         status='approved')
        second = InitiativeFactory.create(title='Lorem ipsum dolor sit amet',
                                          pitch="Something else",
                                          status='approved')

        response = self.client.get(self.url + '?filter[search]=lorem ipsum',
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 2)
        self.assertEqual(data['data'][0]['id'], str(second.pk))
        self.assertEqual(data['data'][1]['id'], str(first.pk))
Exemplo n.º 24
0
 def setUp(self):
     super(EventTasksTestCase, self).setUp()
     self.settings = InitiativePlatformSettingsFactory.create(
         activity_types=['event']
     )
     self.client = JSONAPITestClient()
     self.initiative = InitiativeFactory.create(status='approved')
     self.initiative.save()
Exemplo n.º 25
0
    def test_sort_title(self):
        second = InitiativeFactory.create(title='B: something else',
                                          status='approved')
        third = InitiativeFactory.create(title='C: More', status='approved')
        first = InitiativeFactory.create(title='A: something',
                                         status='approved')

        response = self.client.get(self.url + '?sort=alphabetical',
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 3)
        self.assertEqual(data['data'][0]['id'], str(first.pk))
        self.assertEqual(data['data'][1]['id'], str(second.pk))
        self.assertEqual(data['data'][2]['id'], str(third.pk))
Exemplo n.º 26
0
    def setUp(self):
        super(InitialStatisticsTest, self).setUp()
        self.stats = Statistics()
        Member.objects.all().delete()

        self.some_user = BlueBottleUserFactory.create()

        self.some_initiative = InitiativeFactory.create(owner=self.some_user)
Exemplo n.º 27
0
    def test_update_rejected(self):
        self.initiative = InitiativeFactory.create()
        self.initiative.states.reject(save=True)
        response = self.client.put(self.url,
                                   json.dumps(self.data),
                                   user=self.initiative.owner)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Exemplo n.º 28
0
    def setUp(self):
        self.permission = RelatedResourceOwnerPermission()
        self.user = BlueBottleUserFactory.create()
        self.initiative = InitiativeFactory.create(owner=self.user)
        self.user.groups.clear()

        self.user.user_permissions.add(
            Permission.objects.get(codename='api_read_own_event'))
Exemplo n.º 29
0
    def setUp(self):
        super(FundingWallpostTest, self).setUp()

        self.owner = BlueBottleUserFactory.create()
        self.owner_token = "JWT {0}".format(self.owner.get_jwt_token())

        self.initiative = InitiativeFactory.create(owner=self.owner)
        self.funding = FundingFactory.create(target=Money(5000, 'EUR'), status='open', initiative=self.initiative)
        self.updates_url = "{}?parent_type=funding&parent_id={}".format(reverse('wallpost_list'), self.funding.id)
Exemplo n.º 30
0
    def test_search_location(self):
        location = LocationFactory.create(name='nameofoffice')
        first = InitiativeFactory.create(status='approved', location=location)

        second = InitiativeFactory.create(status='approved',
                                          title='nameofoffice')

        InitiativeFactory.create(status='approved')

        response = self.client.get(self.url + '?filter[search]=nameofoffice',
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 2)
        self.assertEqual(data['data'][0]['id'], str(second.pk))
        self.assertEqual(data['data'][1]['id'], str(first.pk))