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 } } } } }
def test_results_supporters(self): yesterday = now() - timedelta(days=1) co_financer = BlueBottleUserFactory(is_co_financer=True) 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=yesterday, user=co_financer, amount=Money(50, 'EUR')) DonationFactory.create(activity=funding, status='succeeded', transition_date=yesterday, user=co_financer, amount=Money(50, 'EUR')) SupporterTotalContent.objects.create_for_placeholder(self.placeholder) response = self.client.get(self.url) self.assertEquals(response.status_code, status.HTTP_200_OK) block = response.data['blocks'][0] self.assertEqual(block['type'], 'supporter_total') self.assertEqual(len(block['co_financers']), 1) self.assertEqual(block['co_financers'][0]['total']['amount'], 100)
def setUp(self): super(TestPledgeMails, self).setUp() self.init_projects() self.user = BlueBottleUserFactory(can_pledge=True) self.project_owner = BlueBottleUserFactory(username='******', email='*****@*****.**', password='******') self.organization = OrganizationFactory.create(name='test_org', slug='test_org') self.project = ProjectFactory(owner=self.project_owner, organization=self.organization, title='Project 1', amount_needed=1111, amount_asked=1111) self.order = OrderFactory.create(user=self.user) self.donation = DonationFactory(amount=60, order=self.order, project=self.project, fundraiser=None) self.order_payment = OrderPaymentFactory.create( order=self.order, payment_method='pledgeStandard') self.order_payment.pledged() self.order_payment.save()
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', }, } }
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 = []
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, } } } } }
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')
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' } } } } }
def test_abnormal_address_data(self, mock_client): # Mock response to creating the payment at docdata instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} patch.object(DocdataPaymentAdapter, 'create_payment', fake_create_payment) user = BlueBottleUserFactory() CountryFactory(name='Netherlands', alpha2_code='NL') # Update user address with abnormal line1 user.address.line1 = '1a' user.address.save() self.order = OrderFactory.create(user=user) self.order_payment = OrderPaymentFactory.create( order=self.order, payment_method='docdataIdeal', integration_data={'default_pm': 'ideal'}) self.service = PaymentService(order_payment=self.order_payment) user_data = self.service.adapter.get_user_data() self.assertEqual(user_data['street'], 'Unknown')
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_member_applied_to_task_mail_not_to_project_owner(self): """ Test emails for realized task with a task member """ self.project.owner = BlueBottleUserFactory() self.project.save() self.task.status = "in progress" self.assertEquals(len(mail.outbox), 0) self.task.save() self.task_member = TaskMemberFactory.create(task=self.task, status='applied') # Task owner receives email about new task member self.assertEquals(len(mail.outbox), 1) body = mail.outbox[0].body self.assertTrue('applied for your task' in body) self.assertFalse('with the following motivation' in body) self.assertTrue(self.task_member.member.full_name in body) self.assertEquals(mail.outbox[0].to[0], self.task.author.email) self.task_member.status = 'accepted' self.task_member.save() # Task member receives email that he is accepted self.assertEquals(len(mail.outbox), 2) self.assertNotEquals(mail.outbox[1].subject.find("assigned"), -1) self.assertEquals(mail.outbox[1].to[0], self.task_member.member.email)
def test_incomplete_userdata(self, mock_client): # Mock response to creating the payment at docdata instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} patch.object(DocdataPaymentAdapter, 'create_payment', fake_create_payment) user = BlueBottleUserFactory() self.order = OrderFactory.create(user=user) self.order_payment = OrderPaymentFactory.create( order=self.order, payment_method='docdataIdeal', integration_data={'default_pm': 'ideal'}) self.service = PaymentService(order_payment=self.order_payment) user_data = self.service.adapter.get_user_data() self.assertEqual(user_data['id'], user.id) self.assertEqual(user_data['first_name'], user.first_name) self.assertEqual(user_data['last_name'], user.last_name) self.assertEqual(user_data['email'], user.email) self.assertEqual(user_data['street'], 'Unknown') self.assertEqual(user_data['house_number'], 'Unknown') self.assertEqual(user_data['postal_code'], 'Unknown') self.assertEqual(user_data['city'], 'Unknown') self.assertEqual(user_data['country'], 'NL') self.assertEqual(user_data['company'], '') self.assertEqual(user_data['kvk_number'], '') self.assertEqual(user_data['vat_number'], '') self.assertEqual(user_data['house_number_addition'], '') self.assertEqual(user_data['state'], '')
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 } } } } }
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', }, }, } } }
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, } } } } }
def setUp(self): super(SegmentListAPITestCase, self).setUp() self.client = JSONAPITestClient() self.url = reverse('segment-list') self.user = BlueBottleUserFactory() self.segment_type = SegmentTypeFactory.create() self.segments = SegmentFactory.create_batch(20, type=self.segment_type)
def setUp(self): super(ApplicantTransitionAPITestCase, self).setUp() self.settings = InitiativePlatformSettingsFactory.create( activity_types=['assignment']) self.client = JSONAPITestClient() self.transition_url = reverse('applicant-transition-list') self.user = BlueBottleUserFactory() self.someone_else = BlueBottleUserFactory() self.manager = BlueBottleUserFactory(first_name="Boss") self.owner = BlueBottleUserFactory(first_name="Owner") self.initiative = InitiativeFactory.create( activity_manager=self.manager) self.initiative.states.submit() self.initiative.states.approve(save=True) self.assignment = AssignmentFactory.create(owner=self.owner, initiative=self.initiative) self.assignment.states.submit(save=True) document = PrivateDocumentFactory.create() self.applicant = ApplicantFactory.create(activity=self.assignment, document=document, user=self.user) self.participant_url = reverse('applicant-detail', args=(self.applicant.id, )) self.transition_data = { 'data': { 'type': 'contributions/applicant-transitions', 'attributes': { 'transition': 'accept', }, 'relationships': { 'resource': { 'data': { 'type': 'contributions/applicants', 'id': self.applicant.pk } } } } } mail.outbox = []
def setUp(self): super(EventListAPITestCase, self).setUp() self.settings = InitiativePlatformSettingsFactory.create( activity_types=['event']) self.client = JSONAPITestClient() self.url = reverse('event-list') self.user = BlueBottleUserFactory() self.initiative = InitiativeFactory(owner=self.user) self.initiative.states.submit(save=True)
def setUp(self): super(SkillAPITestCase, self).setUp() self.client = JSONAPITestClient() Skill.objects.all().delete() self.user = BlueBottleUserFactory() skills = SkillFactory.create_batch(5, disabled=False) self.skill = skills[0] self.list_url = reverse('assignment-skill-list') self.detail_url = reverse('assignment-skill', args=(self.skill.id, ))
def setUp(self): super(SegmentTypeListAPITestCase, self).setUp() self.client = JSONAPITestClient() self.url = reverse('segment-type-list') self.user = BlueBottleUserFactory() for i in range(5): segment_type = SegmentTypeFactory.create() SegmentFactory.create_batch(3, type=segment_type)
def setUp(self): super(ThemeAPITestCase, self).setUp() self.client = JSONAPITestClient() ProjectTheme.objects.all().delete() self.list_url = reverse('initiative-theme-list') self.user = BlueBottleUserFactory() themes = ProjectThemeFactory.create_batch(5, disabled=False) self.theme = themes[0] self.detail_url = reverse('initiative-theme', args=(self.theme.id, ))
def test_results_supporters(self): yesterday = now() - timedelta(days=1) co_financer = BlueBottleUserFactory(is_co_financer=True) user = BlueBottleUserFactory(is_co_financer=False) project = ProjectFactory(created=yesterday, owner=user) order1 = OrderFactory(user=co_financer, confirmed=yesterday, status='success') order2 = OrderFactory(user=co_financer, confirmed=yesterday, status='success') order3 = OrderFactory(user=user, confirmed=yesterday, status='success') DonationFactory(order=order1, amount=Money(50, 'EUR'), project=project) DonationFactory(order=order2, amount=Money(50, 'EUR'), project=project) DonationFactory(order=order3, amount=Money(50, 'EUR'), project=project) SupporterTotalContent.objects.create_for_placeholder(self.placeholder) response = self.client.get(self.url) self.assertEquals(response.status_code, status.HTTP_200_OK) block = response.data['blocks'][0] self.assertEqual(block['type'], 'supporter_total') self.assertEqual(len(block['co_financers']), 1) self.assertEqual(block['co_financers'][0]['total']['amount'], 100)
def setUp(self): super(ApplicantAPITestCase, self).setUp() self.settings = InitiativePlatformSettingsFactory.create( activity_types=['assignment']) self.client = JSONAPITestClient() self.url = reverse('applicant-list') self.owner = BlueBottleUserFactory() self.user = BlueBottleUserFactory() self.initiative = InitiativeFactory.create(owner=self.owner, activity_manager=self.owner) self.initiative.states.submit() self.initiative.states.approve(save=True) self.assignment = AssignmentFactory.create(initiative=self.initiative, duration=4, owner=self.owner, title="Make coffee") self.assignment.states.submit(save=True) self.apply_data = { 'data': { 'type': 'contributions/applicants', 'attributes': { 'motivation': 'Pick me! Pick me!', }, 'relationships': { 'activity': { 'data': { 'type': 'activities/assignments', 'id': self.assignment.id }, }, } } } self.private_document_url = reverse('private-document-list') self.php_document_path = './bluebottle/files/tests/files/index.php' self.png_document_path = './bluebottle/files/tests/files/test-image.png' mail.outbox = []
def setUp(self): self.activity = EventFactory.create() self.follower = BlueBottleUserFactory.create() EventFollowFactory.create( user=self.follower, instance=self.activity ) EventFollowFactory.create( user=BlueBottleUserFactory(campaign_notifications=False), instance=self.activity ) EventFollowFactory.create(user=self.activity.owner, instance=self.activity)
def test_payment_country_with_profile_without_country(self, mock_client): # If no country specified in profile the default from settings should be used instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} user = BlueBottleUserFactory() order_payment = OrderPaymentFactory( user=user, payment_method='docdataCreditcard', integration_data={'default_pm': 'mastercard'}) order_payment.order.user = user self.adapter = DocdataPaymentAdapter(order_payment=order_payment) payment = self.adapter.payment self.assertEqual(payment.country, 'BG')
def test_ideal_payment_country_with_profile(self, mock_client): # Even a yankees should get NL for country when selecting iDEAL. instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} user = BlueBottleUserFactory() user.address.country = CountryFactory(name='Merica', alpha2_code='US') order_payment = OrderPaymentFactory( user=user, payment_method='docdataIdeal', integration_data={'default_pm': 'ideal'}) order_payment.order.user = user self.adapter = DocdataPaymentAdapter(order_payment=order_payment) payment = self.adapter.payment self.assertEqual(payment.country, 'NL')
def setUp(self): super(AssignmentDetailApplicantsAPITestCase, self).setUp() self.settings = InitiativePlatformSettingsFactory.create( activity_types=['assignment']) self.user = BlueBottleUserFactory() self.owner = BlueBottleUserFactory() self.initiative = InitiativeFactory(owner=self.user) self.assignment = AssignmentFactory.create(initiative=self.initiative, status='open', owner=self.owner) self.client = JSONAPITestClient() self.url = reverse('assignment-detail', args=(self.assignment.id, )) ApplicantFactory.create_batch(5, activity=self.assignment, status='accepted') ApplicantFactory.create_batch(3, activity=self.assignment, status='new') ApplicantFactory.create_batch(2, activity=self.assignment, status='rejected')
def test_payment_country_with_profile(self, mock_client): # When a country is set in profile, that should be used. instance = mock_client.return_value instance.create.return_value = {'order_key': 123, 'order_id': 123} user = BlueBottleUserFactory() user.address.country = CountryFactory(name='Netherlands', alpha2_code='NL') order_payment = OrderPaymentFactory( user=user, payment_method='docdataCreditcard', integration_data={'default_pm': 'mastercard'}) order_payment.order.user = user self.adapter = DocdataPaymentAdapter(order_payment=order_payment) payment = self.adapter.payment self.assertEqual(payment.country, 'NL')
def setUp(self): team_type = SegmentTypeFactory.create(name='Team') self.team = SegmentFactory.create(name='Online Marketing', type=team_type) self.other_team = SegmentFactory.create(name='Direct Marketing', type=team_type) unit_type = SegmentTypeFactory.create(name='Unit') self.unit = SegmentFactory.create(name='Marketing', type=unit_type) SegmentFactory.create(name='Communications', type=unit_type) self.user = BlueBottleUserFactory() self.user.segments.add(self.team) self.user.segments.add(self.unit) super(ActivitySegmentsTestCase, self).setUp()
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" })