def test_billing_group_league_filter(self): league1 = LeagueFactory() league2 = LeagueFactory() bg1 = BillingGroupFactory(league=league1) bg2 = BillingGroupFactory(league=league2) form = EventInviteEmailForm(league=league1) # First billing group should be included in form self.assertTrue( any(bg1.pk == c.data['value'] for c in form['billing_group'])) # Second billing group should NOT be included self.assertFalse( any(bg2.pk == c.data['value'] for c in form['billing_group']))
def test_billing_group_amounts_and_label(self): league = LeagueFactory() bg = BillingGroupFactory(league=league) field_name = 'billinggroup{}'.format(bg.pk) form_data = { 'name': 'Test Form', 'start_date': '2012-01-01', 'end_date': '2012-03-31', } # Check that label is set correctly form = RegistrationAdminEventForm(data=form_data, league=league) self.assertEqual(form[field_name].label, "{} Invoice Amount".format(bg.name)) # Negative numbers should not be accepted form_data[field_name] = -99.99 form = RegistrationAdminEventForm(data=form_data, league=league) self.assertFalse( form.is_valid(), "BillingGroup in RegistrationAdminEventForm should not be negative" ) # Large numbers should not be accepted form_data[field_name] = 100000000000.0 form = RegistrationAdminEventForm(data=form_data, league=league) self.assertFalse( form.is_valid(), "BillingGroup in RegistrationAdminEventForm should not be negative" )
def setUp(self): super().setUp() self.league = LeagueFactory() self.league.stripe_private_key = settings.STRIPE_TEST_SECRET self.league.stripe_public_key = settings.STRIPE_TEST_PUBLIC self.league.save() self.group = BillingGroupFactory(league=self.league) self.group.default_group_for_league = True self.group.save() self.event = RegistrationEventFactory( league=self.league, start_date=date(2018, 3, 1), end_date=date(2018, 6, 30), ) self.billing_periods = self.event.create_monthly_billing_periods()
def test_billing_groups_league_filter(self): league1 = LeagueFactory() league2 = LeagueFactory() bg1 = BillingGroupFactory(league=league1) bg2 = BillingGroupFactory(league=league2) # Use an unbound form for this form = RegistrationAdminEventForm(league=league1) # Key for billing group should not be set self.assertRaises(KeyError, lambda: form['billinggroup{}'.format(bg2.pk)]) # The first billing group should be set and the initial value set try: self.assertEqual(form['billinggroup{}'.format(bg1.pk)].value(), bg1.invoice_amount) except KeyError: self.fail("Billing Group should have been set for this league.")
def test_default_billing_group_league_selected(self): # Test that if a league has a default billing group set it is selected here league = LeagueFactory() bg1 = BillingGroupFactory(league=league) bg2 = BillingGroupFactory(league=league) bg3 = BillingGroupFactory(league=league) bg2.default_group_for_league = True bg2.save() default = BillingGroup.objects.filter( league=league, default_group_for_league=True).get() # Default group should be selected on the form. form = EventInviteEmailForm(league=league) self.assertTrue( any(bg2.pk == c.data['value'] and c.data['selected'] for c in form['billing_group'])) # Introduce some chaos. Change the league to no longer have a default. # Temporarily disable signals so we can set the league to not have a default. default.default_group_for_league = False kwargs = { 'signal': pre_save, 'receiver': update_default_billing_group_for_league, 'sender': BillingGroup, } with temp_disconnect_signal(**kwargs): default.save() # There should no longer be a default group set. with self.assertRaises(BillingGroup.DoesNotExist): BillingGroup.objects.filter(league=league, default_group_for_league=True).get() # Try to create the form with no default group set. form = EventInviteEmailForm(league=league) # Nothing should be marked as selected. self.assertFalse( any(bg1.pk == c.data['value'] and c.data['selected'] for c in form['billing_group'])) self.assertFalse( any(bg2.pk == c.data['value'] and c.data['selected'] for c in form['billing_group']))
def test_registration_admin_form_minimum_data(self): league = LeagueFactory() legal_forms_ids = [] for c in range(1, 3): legal_form = LegalDocumentFactory(league=league) legal_forms_ids.append(legal_form.pk) billing_groups = [] for bg in range(1, 5): billing_groups.append(BillingGroupFactory(league=league)) # Maximum arguments, all of them, everything and then more. form_data = { 'name': 'Test Form', 'start_date': '2012-01-01', 'end_date': '2012-03-31', 'description': 'Test Description of this event', 'public_registration_open_date': '2011-12-01', 'public_registration_closes_date': '2011-12-31', 'invite_expiration_date': '2011-12-31', 'minimum_registration_age': 18, 'maximum_registration_age': 25, 'automatic_billing_dates': 'monthly', # Legal forms 'legal_forms': legal_forms_ids, # Billing Status billing amounts } for billing_group in billing_groups: form_data['billinggroup{}'.format( billing_group.pk)] = billing_group.invoice_amount form = RegistrationAdminEventForm(data=form_data, league=league) self.assertTrue( form.is_valid(), "RegistrationAdminEventForm should be valid with all data submitted." )
class TestAutomaticBilling(TransactionTestCase): def setUp(self): super().setUp() self.league = LeagueFactory() self.league.stripe_private_key = settings.STRIPE_TEST_SECRET self.league.stripe_public_key = settings.STRIPE_TEST_PUBLIC self.league.save() self.group = BillingGroupFactory(league=self.league) self.group.default_group_for_league = True self.group.save() self.event = RegistrationEventFactory( league=self.league, start_date=date(2018, 3, 1), end_date=date(2018, 6, 30), ) self.billing_periods = self.event.create_monthly_billing_periods() def tearDown(self): #self.event.delete() #self.group.delete() #self.league.delete() super().tearDown() def get_registration_data(self, user): registration_data_obj = RegistrationDataFactory( invite=None, user=user, event=self.event, organization=self.league.organization, ) registration_data = copy_model_to_dict(registration_data_obj) registration_data_obj.delete() registration_data['birth_month'] = 11 registration_data['birth_day'] = 3 registration_data['birth_year'] = 1987 registration_data['legal_agree'] = 'checked' registration_data['stripe_token'] = 'tok_visa' return registration_data def test_automatic_invoicing(self): freezer = freeze_time("2018-02-20 12:00:01") freezer.start() user = UserFactoryNoPermissions(league=self.league, organization=self.league.organization) self.client.login(username=user.email, password=user_password) response = self.client.post(reverse('register:show_form', kwargs={ 'league_slug': self.league.slug, 'event_slug': self.event.slug }), self.get_registration_data(user), follow=True) # Generate invoice should not create an invoice, as the first period # should have been paid during the registration process. freezer.stop() freezer = freeze_time("2018-03-20 12:00:01") freezer.start() generate_invoices() self.assertEqual(Invoice.objects.count(), 1) self.assertEqual(Invoice.objects.all()[0].status, "paid") self.assertEqual(Invoice.objects.all()[0].subscription.status, "active") # Invoice should be generated freezer.stop() freezer = freeze_time("2018-03-22 12:00:01") freezer.start() generate_invoices() capture_invoices() self.assertEqual(Invoice.objects.all()[1].status, "unpaid") self.assertEqual(Invoice.objects.all()[1].subscription.status, "active") # Card should be automatically charged freezer.stop() freezer = freeze_time("2018-04-01 12:00:01") freezer.start() capture_invoices() freezer.stop() invoices = Invoice.objects.all() self.assertEqual(invoices.count(), 2) self.assertEqual(invoices[1].status, "paid") self.assertEqual(Invoice.objects.all()[1].subscription.status, "active") freezer = freeze_time("2018-04-22 12:00:01") freezer.start() generate_invoices() capture_invoices() freezer.stop() self.assertEqual(invoices.count(), 3) self.assertEqual(invoices[2].status, "unpaid") self.assertEqual(Invoice.objects.all()[1].subscription.status, "active") freezer = freeze_time("2018-05-01 12:00:01") freezer.start() generate_invoices() capture_invoices() freezer.stop() self.assertEqual(invoices.count(), 3) self.assertEqual(invoices[2].status, "paid") self.assertEqual(Invoice.objects.all()[2].subscription.status, "active") freezer = freeze_time("2018-05-22 12:00:01") freezer.start() generate_invoices() capture_invoices() freezer.stop() self.assertEqual(invoices.count(), 4) self.assertEqual(invoices[3].status, "unpaid") self.assertEqual(Invoice.objects.all()[3].subscription.status, "complete") freezer = freeze_time("2018-06-01 12:00:01") freezer.start() generate_invoices() capture_invoices() freezer.stop() self.assertEqual(invoices.count(), 4) self.assertEqual(invoices[3].status, "paid") self.assertEqual(Invoice.objects.all()[3].subscription.status, "complete")