def setUp(self): super(MonthlyDonationApiTest, self).setUp() self.init_projects() self.phase_campaign = ProjectPhase.objects.get(slug='campaign') self.country = CountryFactory() self.some_project = ProjectFactory.create(amount_asked=500, status=self.phase_campaign) self.another_project = ProjectFactory.create( amount_asked=750, status=self.phase_campaign) self.some_user = BlueBottleUserFactory.create() self.some_user_token = "JWT {0}".format(self.some_user.get_jwt_token()) self.another_user = BlueBottleUserFactory.create() self.another_user_token = "JWT {0}".format( self.another_user.get_jwt_token()) self.monthly_donation_url = reverse('monthly-donation-list') self.monthly_donation_project_url = reverse( 'monthly-donation-project-list') self.monthly_profile = { 'iban': 'NL13TEST0123456789', 'bic': 'TESTNL2A', 'name': 'Nijntje het Konijntje', 'city': 'Amsterdam', 'country': self.country.id, 'amount': 50.00 }
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 setUp(self): super(MonthlyDonationAdminTest, self).setUp() self.app.extra_environ['HTTP_HOST'] = str(self.tenant.domain_url) self.superuser = BlueBottleUserFactory.create(is_staff=True, is_superuser=True) self.init_projects() self.phase_campaign = ProjectPhase.objects.get(slug='campaign') self.country = CountryFactory() self.projects = [] for amount in [500, 100, 1500, 300, 200]: self.projects.append( ProjectFactory.create(amount_asked=amount, status=self.phase_campaign)) # Some donations to get the popularity going # Top 3 after this should be projects 4, 3, 0 order = OrderFactory() DonationFactory(order=order, project=self.projects[3], amount=10) DonationFactory(order=order, project=self.projects[3], amount=100) DonationFactory(order=order, project=self.projects[3], amount=20) DonationFactory(order=order, project=self.projects[4], amount=10) DonationFactory(order=order, project=self.projects[4], amount=70) DonationFactory(order=order, project=self.projects[0], amount=10) order.locked() order.save() order.success() order.save() # Since we force the transitions update_amounts isn't triggered by # signal, so we run it manually here. for project in self.projects: project.update_amounts() self.user1 = BlueBottleUserFactory.create() self.user2 = BlueBottleUserFactory.create() # Create a monthly donor with a preferred project self.monthly_donor1 = MonthlyDonorFactory(user=self.user1, amount=25) self.monthly_donor1_project = MonthlyDonorProjectFactory( donor=self.monthly_donor1, project=self.projects[0]) # Create a monthly donor without preferred projects self.monthly_donor2 = MonthlyDonorFactory(user=self.user2, amount=100) Project.update_popularity()
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 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 test_normal_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() holland = CountryFactory(name='Netherlands', alpha2_code='NL') # Update user address user.address.line1 = 'Dam 1a' user.address.line2 = 'Bovenste bel' user.address.city = 'Amsterdam' user.address.postal_code = '1000AA' user.address.country = holland 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['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'], 'Dam') self.assertEqual(user_data['house_number'], '1a') self.assertEqual(user_data['postal_code'], '1000AA') self.assertEqual(user_data['city'], 'Amsterdam') 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'], '')