def setUpClass(cls): super().setUpClass() billing_contact = accounting_generator.create_arbitrary_web_user_name() dimagi_user = accounting_generator.create_arbitrary_web_user_name(is_dimagi=True) plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) account_no_hubspot = accounting_generator.billing_account( dimagi_user, billing_contact ) account_no_hubspot.block_hubspot_data_for_all_users = True account_no_hubspot.save() cls.domain_no_hubspot = Domain.get_or_create_with_name( "domain-no-hubspot-001", is_active=True ) cls.subscription_no_hubspot = Subscription.new_domain_subscription( account=account_no_hubspot, domain=cls.domain_no_hubspot.name, plan_version=plan, ) regular_account = accounting_generator.billing_account( dimagi_user, billing_contact ) cls.regular_domain = Domain.get_or_create_with_name( "domain-with-analytics-001", is_active=True ) cls.regular_subscription = Subscription.new_domain_subscription( account=regular_account, domain=cls.regular_domain.name, plan_version=plan, )
def setUp(self): super(TestCustomerBillingRecord, self).setUp() self.billing_contact = generator.create_arbitrary_web_user_name() self.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) self.domain = Domain(name='test') self.domain.save() self.invoice_start, self.invoice_end = get_previous_month_date_range() self.currency = generator.init_default_currency() self.account = generator.billing_account(self.dimagi_user, self.billing_contact) self.account.is_customer_billing_account = True self.account.save() self.subscription_length = 4 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, self.subscription_length) self.subscription = generator.generate_domain_subscription( self.account, self.domain, date_start=subscription_start_date, date_end=subscription_end_date, ) self.invoice = CustomerInvoice( account=self.account, date_start=self.invoice_start, date_end=self.invoice_end, is_hidden=False ) self.customer_billing_record = CustomerBillingRecord(invoice=self.invoice)
def setUp(self): super(TestBillingRecord, self).setUp() self.billing_contact = generator.create_arbitrary_web_user_name() self.dimagi_user = generator.create_arbitrary_web_user_name( is_dimagi=True) self.domain = Domain(name='test') self.domain.save() self.invoice_start, self.invoice_end = get_previous_month_date_range() self.currency = generator.init_default_currency() self.account = generator.billing_account(self.dimagi_user, self.billing_contact) self.subscription_length = 4 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, self.subscription_length) self.subscription = generator.generate_domain_subscription( self.account, self.domain, date_start=subscription_start_date, date_end=subscription_end_date, ) self.invoice = Invoice( subscription=self.subscription, date_start=self.invoice_start, date_end=self.invoice_end, is_hidden=False, ) self.billing_record = BillingRecord(invoice=self.invoice)
def setUp(self): super(TestBillingAccount, self).setUp() self.billing_contact = generator.create_arbitrary_web_user_name() self.dimagi_user = generator.create_arbitrary_web_user_name( is_dimagi=True) self.currency = generator.init_default_currency() self.billing_account = generator.billing_account( self.dimagi_user, self.billing_contact)
def setUpClass(cls): super(BaseCustomerInvoiceCase, cls).setUpClass() if cls.is_using_test_plans: generator.bootstrap_test_software_plan_versions() cls.billing_contact = generator.create_arbitrary_web_user_name() cls.dimagi_user = generator.create_arbitrary_web_user_name( is_dimagi=True) cls.account = generator.billing_account(cls.dimagi_user, cls.billing_contact) cls.domain = generator.arbitrary_domain() cls.account.is_customer_billing_account = True cls.account.save() cls.advanced_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED) cls.advanced_plan.plan.is_customer_software_plan = True cls.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length) cls.subscription = generator.generate_domain_subscription( cls.account, cls.domain, date_start=subscription_start_date, date_end=subscription_end_date, ) advanced_subscription_end_date = add_months_to_date( subscription_end_date, 2) cls.domain2 = generator.arbitrary_domain() cls.sub2 = generator.generate_domain_subscription( cls.account, cls.domain2, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=cls.advanced_plan) cls.domain3 = generator.arbitrary_domain() cls.sub3 = generator.generate_domain_subscription( cls.account, cls.domain3, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=cls.advanced_plan) # This subscription should not be included in any customer invoices in these tests cls.domain_community = generator.arbitrary_domain() cls.sub3 = generator.generate_domain_subscription( cls.account, cls.domain3, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.COMMUNITY))
def setUpClass(cls): super(BaseCustomerInvoiceCase, cls).setUpClass() if cls.is_using_test_plans: generator.bootstrap_test_software_plan_versions() cls.billing_contact = generator.create_arbitrary_web_user_name() cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) cls.account = generator.billing_account( cls.dimagi_user, cls.billing_contact) cls.domain = generator.arbitrary_domain() cls.account.is_customer_billing_account = True cls.account.save() cls.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) cls.advanced_plan.plan.is_customer_software_plan = True cls.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length) cls.subscription = generator.generate_domain_subscription( cls.account, cls.domain, date_start=subscription_start_date, date_end=subscription_end_date, ) advanced_subscription_end_date = add_months_to_date(subscription_end_date, 2) cls.domain2 = generator.arbitrary_domain() cls.sub2 = generator.generate_domain_subscription( cls.account, cls.domain2, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=cls.advanced_plan ) cls.domain3 = generator.arbitrary_domain() cls.sub3 = generator.generate_domain_subscription( cls.account, cls.domain3, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=cls.advanced_plan ) # This subscription should not be included in any customer invoices in these tests cls.domain_community = generator.arbitrary_domain() cls.sub3 = generator.generate_domain_subscription( cls.account, cls.domain3, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.COMMUNITY) )
def _generate_invoice_and_subscription(days_ago, is_customer_billing_account=False): """ :param days_ago: The number of days ago an invoice should be due :return: random domain, with invoices generated on the backend """ invoice_due_date = datetime.date.today() - datetime.timedelta(days=days_ago) billing_contact = generator.create_arbitrary_web_user_name() dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) account = generator.billing_account( dimagi_user, billing_contact ) account.is_customer_billing_account = is_customer_billing_account account.save() domain = generator.arbitrary_domain() subscription_start_date = utils.months_from_date(invoice_due_date, -2) subscription = generator.generate_domain_subscription( account, domain, date_start=subscription_start_date, date_end=None, plan_version=DefaultProductPlan.get_default_plan_version( SoftwarePlanEdition.ADVANCED ), service_type=SubscriptionType.PRODUCT, ) subscription.is_active = True subscription.save() invoice_date = utils.months_from_date(invoice_due_date, -1) DomainUserHistory.objects.create( domain=domain.name, num_users=20, record_date=invoice_date - datetime.timedelta(days=1) ) tasks.generate_invoices(invoice_date) # for testing purposes, force the latest invoice due_date to be # the "invoice_due_date" specified above if is_customer_billing_account: latest_invoice = CustomerInvoice.objects.filter( account=account, ).latest('date_created') else: latest_invoice = subscription.invoice_set.latest('date_created') latest_invoice.date_due = invoice_due_date latest_invoice.save() return domain, latest_invoice
def setUp(self): super(TestUserRoleSubscriptionChanges, self).setUp() self.domain = Domain( name="test-sub-changes", is_active=True, ) self.domain.save() self.other_domain = Domain( name="other-domain", is_active=True, ) self.other_domain.save() UserRole.init_domain_with_presets(self.domain.name) self.user_roles = UserRole.by_domain(self.domain.name) self.custom_role = UserRole.get_or_create_with_permissions( self.domain.name, Permissions( edit_apps=True, edit_web_users=True, view_web_users=True, view_roles=True, ), "Custom Role") self.custom_role.save() self.read_only_role = UserRole.get_read_only_role_by_domain( self.domain.name) self.admin_username = generator.create_arbitrary_web_user_name() self.web_users = [] self.commcare_users = [] for role in [self.custom_role] + self.user_roles: web_user = WebUser.create( self.other_domain.name, generator.create_arbitrary_web_user_name(), 'test123', None, None) web_user.is_active = True web_user.add_domain_membership(self.domain.name, role_id=role.get_id) web_user.save() self.web_users.append(web_user) commcare_user = generator.arbitrary_commcare_user( domain=self.domain.name) commcare_user.set_role(self.domain.name, role.get_qualified_id()) commcare_user.save() self.commcare_users.append(commcare_user) self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_username)[0] self.advanced_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED)
def setUp(self): super(TestUserRoleSubscriptionChanges, self).setUp() self.domain = Domain( name="test-sub-changes", is_active=True, ) self.domain.save() self.other_domain = Domain( name="other-domain", is_active=True, ) self.other_domain.save() UserRole.init_domain_with_presets(self.domain.name) self.user_roles = UserRole.by_domain(self.domain.name) self.custom_role = UserRole.get_or_create_with_permissions( self.domain.name, Permissions( edit_apps=True, edit_web_users=True, view_web_users=True, view_roles=True, ), "Custom Role" ) self.custom_role.save() self.read_only_role = UserRole.get_read_only_role_by_domain(self.domain.name) self.admin_username = generator.create_arbitrary_web_user_name() self.web_users = [] self.commcare_users = [] for role in [self.custom_role] + self.user_roles: web_user = WebUser.create( self.other_domain.name, generator.create_arbitrary_web_user_name(), 'test123' ) web_user.is_active = True web_user.add_domain_membership(self.domain.name, role_id=role.get_id) web_user.save() self.web_users.append(web_user) commcare_user = generator.arbitrary_commcare_user( domain=self.domain.name) commcare_user.set_role(self.domain.name, role.get_qualified_id()) commcare_user.save() self.commcare_users.append(commcare_user) self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_username)[0] self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED)
def test_autopay_user(self): self.assertFalse(self.billing_account.auto_pay_enabled) mail.outbox = [] autopay_user = generator.create_arbitrary_web_user_name() self.billing_account.update_autopay_user(autopay_user, None) self.assertEqual(len(mail.outbox), 1) self.assertTrue(self.billing_account.auto_pay_enabled) self.assertEqual(self.billing_account.auto_pay_user, autopay_user) mail.outbox = [] other_autopay_user = generator.create_arbitrary_web_user_name() self.billing_account.update_autopay_user(other_autopay_user, None) self.assertEqual(len(mail.outbox), 2) self.assertEqual(self.billing_account.auto_pay_user, other_autopay_user)
def setUpClass(cls): super().setUpClass() cls.domain = Domain(name="test-enterprise-001", is_active=True) cls.domain.save() cls.enterprise_admin = WebUser.create( cls.domain.name, generator.create_arbitrary_web_user_name(), 'testpwd', None, None) cls.other_domain_user = WebUser.create( cls.domain.name, generator.create_arbitrary_web_user_name(), 'testpwd', None, None) cls.account = BillingAccount.get_or_create_account_by_domain( cls.domain.name, created_by=cls.enterprise_admin.username)[0] cls.account.is_customer_billing_account = True cls.account.enterprise_admin_emails = [cls.enterprise_admin.username] cls.account.save()
def test_autopay_user(self): self.assertFalse(self.billing_account.auto_pay_enabled) mail.outbox = [] autopay_user = generator.create_arbitrary_web_user_name() self.billing_account.update_autopay_user(autopay_user, None) self.assertEqual(len(mail.outbox), 1) self.assertTrue(self.billing_account.auto_pay_enabled) self.assertEqual(self.billing_account.auto_pay_user, autopay_user) mail.outbox = [] other_autopay_user = generator.create_arbitrary_web_user_name() self.billing_account.update_autopay_user(other_autopay_user, None) self.assertEqual(len(mail.outbox), 2) self.assertEqual(self.billing_account.auto_pay_user, other_autopay_user)
def test_invoice_credit(self): """ Make sure that subscription and account level credits get applied to the invoice balance appropriately. """ invoice_monthly_total = self.product_rate.monthly_fee + self.monthly_user_fee subscription_credit, account_credit = self._generate_subscription_and_account_invoice_credits( invoice_monthly_total, self.subscription, self.account ) # other subscription credit that shouldn't count toward this invoice other_domain = generator.arbitrary_domain() # so that the other subscription doesn't draw from the same account credits, have it start 4 months later new_subscription_start = utils.months_from_date(self.subscription.date_start, 4) other_subscription = generator.generate_domain_subscription( self.account, other_domain, date_start=new_subscription_start, date_end=add_months_to_date(new_subscription_start, self.min_subscription_length), ) # other account credit that shouldn't count toward this invoice other_account = generator.billing_account(self.dimagi_user, generator.create_arbitrary_web_user_name()) self._generate_subscription_and_account_invoice_credits( invoice_monthly_total, other_subscription, other_account ) self._test_final_invoice_balance() self._test_credit_use(subscription_credit) self._test_credit_use(account_credit) other_domain.delete()
def setUp(self): super(TestStripePaymentMethod, self).setUp() self.web_user = generator.create_arbitrary_web_user_name() self.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) self.fake_card = FakeStripeCard() self.fake_stripe_customer = FakeStripeCustomer(cards=[self.fake_card]) self.currency = generator.init_default_currency() self.billing_account = generator.billing_account(self.dimagi_user, self.web_user) self.billing_account_2 = generator.billing_account(self.dimagi_user, self.web_user) self.payment_method = StripePaymentMethod(web_user=self.web_user, customer_id=self.fake_stripe_customer.id) self.payment_method.save()
def setUp(self): super(TestSubscriptionForm, self).setUp() self.domain = Domain( name="test-sub-form", is_active=True ) self.domain.save() self.domain2 = Domain( name="test-sub-form-2", is_active=True ) self.domain2.save() self.web_user = WebUser.create( self.domain.name, generator.create_arbitrary_web_user_name(), 'testpwd' ) self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.web_user.username )[0] self.account.save() self.customer_account = BillingAccount.get_or_create_account_by_domain( self.domain2.name, created_by=self.web_user.username )[0] self.customer_account.is_customer_billing_account = True self.customer_account.save() self.plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) self.customer_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) self.customer_plan.plan.is_customer_software_plan = True
def setUp(self): super(TestStripePaymentMethod, self).setUp() self.web_user = generator.create_arbitrary_web_user_name() self.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) self.fake_card = FakeStripeCard() self.fake_stripe_customer = FakeStripeCustomer(cards=[self.fake_card]) self.currency = generator.init_default_currency() self.billing_account = generator.billing_account(self.dimagi_user, self.web_user) self.billing_account_2 = generator.billing_account(self.dimagi_user, self.web_user) self.payment_method = StripePaymentMethod(web_user=self.web_user, customer_id=self.fake_stripe_customer.id) self.payment_method.save()
def setUp(self): super(TestRenewSubscriptions, self).setUp() self.domain = Domain( name="test-domain-sub", is_active=True, ) self.domain.save() self.admin_username = generator.create_arbitrary_web_user_name() self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_username)[0] self.standard_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.STANDARD) today = datetime.date.today() yesterday = today + datetime.timedelta(days=-1) tomorrow = today + datetime.timedelta(days=1) self.subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.standard_plan, web_user=self.admin_username, date_start=yesterday, date_end=tomorrow, ) self.subscription.save()
def test_set_autopay(self, fake_customer): fake_customer.__get__ = mock.Mock( return_value=self.fake_stripe_customer) self.assertEqual(self.billing_account.auto_pay_user, None) self.assertFalse(self.billing_account.auto_pay_enabled) self.payment_method.set_autopay(self.fake_card, self.billing_account, None) self.assertEqual( self.fake_card.metadata, {"auto_pay_{}".format(self.billing_account.id): 'True'}) self.assertEqual(self.billing_account.auto_pay_user, self.web_user) self.assertTrue(self.billing_account.auto_pay_enabled) self.payment_method.set_autopay(self.fake_card, self.billing_account_2, None) self.assertEqual( self.fake_card.metadata, { "auto_pay_{}".format(self.billing_account.id): 'True', "auto_pay_{}".format(self.billing_account_2.id): 'True' }) other_web_user = generator.create_arbitrary_web_user_name() other_payment_method = StripePaymentMethod(web_user=other_web_user) different_fake_card = FakeStripeCard() other_payment_method.set_autopay(different_fake_card, self.billing_account, None) self.assertEqual(self.billing_account.auto_pay_user, other_web_user) self.assertTrue(different_fake_card.metadata["auto_pay_{}".format( self.billing_account.id)]) self.assertFalse(self.fake_card.metadata["auto_pay_{}".format( self.billing_account.id)] == 'True')
def _generate_non_autopayable_entities(cls): """ Create account, domain, and subscription linked to the autopay user, but that don't have autopay enabled """ cls.non_autopay_account = generator.billing_account( web_user_creator=generator.create_arbitrary_web_user_name( is_dimagi=True), web_user_contact=cls.autopay_user_email) cls.non_autopay_domain = generator.arbitrary_domain() # Non-autopay subscription has same parameters as the autopayable subscription cheap_plan = SoftwarePlan.objects.create(name='cheap') cheap_product_rate = SoftwareProductRate.objects.create( monthly_fee=100, name=cheap_plan.name) cheap_plan_version = SoftwarePlanVersion.objects.create( plan=cheap_plan, product_rate=cheap_product_rate, role=Role.objects.first(), ) cls.non_autopay_subscription = generator.generate_domain_subscription( cls.non_autopay_account, cls.non_autopay_domain, plan_version=cheap_plan_version, date_start=cls.subscription.date_start, date_end=add_months_to_date(cls.subscription.date_start, cls.subscription_length), )
def test_invoice_credit(self): """ Make sure that subscription and account level credits get applied to the invoice balance appropriately. """ invoice_monthly_total = self.product_rate.monthly_fee + self.monthly_user_fee subscription_credit, account_credit = self._generate_subscription_and_account_invoice_credits( invoice_monthly_total, self.subscription, self.account ) # other subscription credit that shouldn't count toward this invoice other_domain = generator.arbitrary_domain() # so that the other subscription doesn't draw from the same account credits, have it start 4 months later new_subscription_start = utils.months_from_date(self.subscription.date_start, 4) other_subscription = generator.generate_domain_subscription( self.account, other_domain, date_start=new_subscription_start, date_end=add_months_to_date(new_subscription_start, self.min_subscription_length), ) # other account credit that shouldn't count toward this invoice other_account = generator.billing_account(self.dimagi_user, generator.create_arbitrary_web_user_name()) self._generate_subscription_and_account_invoice_credits( invoice_monthly_total, other_subscription, other_account ) self._test_final_invoice_balance() self._test_credit_use(subscription_credit) self._test_credit_use(account_credit) other_domain.delete()
def setUp(self): super(TestRenewSubscriptions, self).setUp() self.domain = Domain( name="test-domain-sub", is_active=True, ) self.domain.save() self.admin_username = generator.create_arbitrary_web_user_name() self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_username)[0] self.standard_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.STANDARD) today = datetime.date.today() yesterday = today + datetime.timedelta(days=-1) tomorrow = today + datetime.timedelta(days=1) self.subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.standard_plan, web_user=self.admin_username, date_start=yesterday, date_end=tomorrow, ) self.subscription.save()
def setUp(self): super(TestSubscriptionForm, self).setUp() self.domain = Domain( name="test-sub-form", is_active=True ) self.domain.save() self.domain2 = Domain( name="test-sub-form-2", is_active=True ) self.domain2.save() self.web_user = WebUser.create( self.domain.name, generator.create_arbitrary_web_user_name(), 'testpwd' ) self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.web_user.username )[0] self.account.save() self.customer_account = BillingAccount.get_or_create_account_by_domain( self.domain2.name, created_by=self.web_user.username )[0] self.customer_account.is_customer_billing_account = True self.customer_account.save() self.plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) self.customer_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) self.customer_plan.plan.is_customer_software_plan = True
def setUpClass(cls): super(BaseCustomerInvoiceCase, cls).setUpClass() cls.billing_contact = generator.create_arbitrary_web_user_name() cls.dimagi_user = generator.create_arbitrary_web_user_name( is_dimagi=True) cls.account = generator.billing_account(cls.dimagi_user, cls.billing_contact) cls.domain = generator.arbitrary_domain() cls.account.is_customer_billing_account = True cls.account.save() cls.advanced_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED) cls.advanced_plan.plan.is_customer_software_plan = True cls.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length) cls.subscription = generator.generate_domain_subscription( cls.account, cls.domain, date_start=subscription_start_date, date_end=subscription_end_date, ) cls.subscription.plan_version.plan.is_customer_software_plan = True advanced_subscription_end_date = add_months_to_date( subscription_end_date, 2) cls.domain2 = generator.arbitrary_domain() cls.sub2 = generator.generate_domain_subscription( cls.account, cls.domain2, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=cls.advanced_plan) cls.sub2.plan_version.plan.is_customer_software_plan = True cls.domain3 = generator.arbitrary_domain() cls.sub3 = generator.generate_domain_subscription( cls.account, cls.domain3, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=cls.advanced_plan) cls.sub3.plan_version.plan.is_customer_software_plan = True
def setUpClass(cls): super(BaseCustomerInvoiceCase, cls).setUpClass() cls.billing_contact = generator.create_arbitrary_web_user_name() cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) cls.account = generator.billing_account( cls.dimagi_user, cls.billing_contact) cls.domain = generator.arbitrary_domain() cls.account.is_customer_billing_account = True cls.account.save() cls.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) cls.advanced_plan.plan.is_customer_software_plan = True cls.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length) cls.subscription = generator.generate_domain_subscription( cls.account, cls.domain, date_start=subscription_start_date, date_end=subscription_end_date, ) cls.subscription.plan_version.plan.is_customer_software_plan = True advanced_subscription_end_date = add_months_to_date(subscription_end_date, 2) cls.domain2 = generator.arbitrary_domain() cls.sub2 = generator.generate_domain_subscription( cls.account, cls.domain2, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=cls.advanced_plan ) cls.sub2.plan_version.plan.is_customer_software_plan = True cls.domain3 = generator.arbitrary_domain() cls.sub3 = generator.generate_domain_subscription( cls.account, cls.domain3, date_start=subscription_start_date, date_end=advanced_subscription_end_date, plan_version=cls.advanced_plan ) cls.sub3.plan_version.plan.is_customer_software_plan = True
def setUp(self): super(TestSubscription, self).setUp() self.billing_contact = generator.create_arbitrary_web_user_name() self.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) self.domain = Domain(name='test') self.domain.save() self.currency = generator.init_default_currency() self.account = generator.billing_account(self.dimagi_user, self.billing_contact) self.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, self.subscription_length) self.subscription = generator.generate_domain_subscription( self.account, self.domain, date_start=subscription_start_date, date_end=subscription_end_date, )
def setUp(self): super(TestSubscription, self).setUp() self.billing_contact = generator.create_arbitrary_web_user_name() self.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) self.domain = Domain(name='test') self.domain.save() self.currency = generator.init_default_currency() self.account = generator.billing_account(self.dimagi_user, self.billing_contact) self.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, self.subscription_length) self.subscription = generator.generate_domain_subscription( self.account, self.domain, date_start=subscription_start_date, date_end=subscription_end_date, )
def setUpClass(cls): super(BaseInvoiceTestCase, cls).setUpClass() generator.bootstrap_test_plans() # TODO - only call for subclasses that actually need the test plans cls.billing_contact = generator.create_arbitrary_web_user_name() cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) cls.currency = generator.init_default_currency() cls.account = generator.billing_account( cls.dimagi_user, cls.billing_contact) cls.domain = generator.arbitrary_domain() cls.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length) cls.subscription = generator.generate_domain_subscription( cls.account, cls.domain, date_start=subscription_start_date, date_end=subscription_end_date, )
def setUpClass(cls): super(TestCreditTransfers, cls).setUpClass() cls.product_credit_amt = Decimal('500.00') cls.feature_credit_amt = Decimal('200.00') cls.subscription_credit_amt = Decimal('600.00') cls.domain = generator.arbitrary_domain() cls.account = BillingAccount.get_or_create_account_by_domain( cls.domain, created_by="*****@*****.**", )[0] cls.web_user_name = generator.create_arbitrary_web_user_name() cls.other_account = generator.billing_account(cls.web_user_name, cls.web_user_name)
def setUpClass(cls): super(TestCreditTransfers, cls).setUpClass() cls.product_credit_amt = Decimal('500.00') cls.feature_credit_amt = Decimal('200.00') cls.subscription_credit_amt = Decimal('600.00') cls.domain = generator.arbitrary_domain() cls.account = BillingAccount.get_or_create_account_by_domain( cls.domain, created_by="*****@*****.**", )[0] cls.web_user_name = generator.create_arbitrary_web_user_name() cls.other_account = generator.billing_account(cls.web_user_name, cls.web_user_name)
def _generate_autopayable_entities(cls): """ Create account, domain and subscription linked to the autopay user that have autopay enabled """ cls.autopay_account = cls.account cls.autopay_account.created_by_domain = cls.domain cls.autopay_account.save() cls.autopay_user_email = generator.create_arbitrary_web_user_name() cls.fake_card = FakeStripeCard() cls.fake_stripe_customer = FakeStripeCustomer(cards=[cls.fake_card]) cls.autopay_account.update_autopay_user(cls.autopay_user_email, cls.domain)
def setUpClass(cls): super(TestUserSubscriptionChangeTransfers, cls).setUpClass() generator.bootstrap_test_software_plan_versions() generator.init_default_currency() cls.billing_contact = generator.create_arbitrary_web_user_name() cls.domain = generator.arbitrary_domain() cls.account = BillingAccount.get_or_create_account_by_domain( cls.domain, created_by=cls.billing_contact, )[0] generator.arbitrary_contact_info(cls.account, cls.billing_contact)
def _generate_autopayable_entities(cls): """ Create account, domain and subscription linked to the autopay user that have autopay enabled """ cls.autopay_account = cls.account cls.autopay_account.created_by_domain = cls.domain cls.autopay_account.save() cls.autopay_user_email = generator.create_arbitrary_web_user_name() cls.fake_card = FakeStripeCard() cls.fake_stripe_customer = FakeStripeCustomer(cards=[cls.fake_card]) cls.autopay_account.update_autopay_user(cls.autopay_user_email, cls.domain)
def setUpClass(cls): super(BaseInvoiceTestCase, cls).setUpClass() if cls.is_using_test_plans: generator.bootstrap_test_software_plan_versions() cls.billing_contact = generator.create_arbitrary_web_user_name() cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) cls.currency = generator.init_default_currency() cls.account = generator.billing_account( cls.dimagi_user, cls.billing_contact) cls.domain = generator.arbitrary_domain() cls.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length) cls.subscription = generator.generate_domain_subscription( cls.account, cls.domain, date_start=subscription_start_date, date_end=subscription_end_date, )
def setUpClass(cls): super(BaseInvoiceTestCase, cls).setUpClass() if cls.is_using_test_plans: generator.bootstrap_test_software_plan_versions() cls.billing_contact = generator.create_arbitrary_web_user_name() cls.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) cls.currency = generator.init_default_currency() cls.account = generator.billing_account( cls.dimagi_user, cls.billing_contact) cls.domain = generator.arbitrary_domain() cls.subscription_length = 15 # months subscription_start_date = datetime.date(2016, 2, 23) subscription_end_date = add_months_to_date(subscription_start_date, cls.subscription_length) cls.subscription = generator.generate_domain_subscription( cls.account, cls.domain, date_start=subscription_start_date, date_end=subscription_end_date, )
def _setup_product_subscription_with_admin_user(self): self.subscription.service_type = SubscriptionType.PRODUCT self.subscription.save() self.subscription.account.billingcontactinfo.email_list = [] self.subscription.account.billingcontactinfo.save() web_user = WebUser.create( domain=self.domain.name, username=generator.create_arbitrary_web_user_name(), password='******', email="*****@*****.**", ) web_user.set_role(self.domain.name, "admin") web_user.save()
def _setup_product_subscription_with_admin_user(self): self.subscription.service_type = SubscriptionType.PRODUCT self.subscription.save() self.subscription.account.billingcontactinfo.email_list = [] self.subscription.account.billingcontactinfo.save() web_user = WebUser.create( domain=self.domain.name, username=generator.create_arbitrary_web_user_name(), password='******', email="*****@*****.**", ) web_user.set_role(self.domain.name, "admin") web_user.save()
def setUp(self): super(TestSubscriptionPermissionsChanges, self).setUp() self.project = Domain( name="test-sub-changes", is_active=True, ) self.project.save() self.admin_username = generator.create_arbitrary_web_user_name() self.account = BillingAccount.get_or_create_account_by_domain( self.project.name, created_by=self.admin_username)[0] self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) self._init_pro_with_rb_plan_and_version()
def setUp(self): super(TestSubscriptionPermissionsChanges, self).setUp() self.project = Domain( name="test-sub-changes", is_active=True, ) self.project.save() self.admin_username = generator.create_arbitrary_web_user_name() self.account = BillingAccount.get_or_create_account_by_domain( self.project.name, created_by=self.admin_username)[0] self.advanced_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED) self._init_pro_with_rb_plan_and_version()
def _generate_non_autopayable_entities(cls): """ Create account, domain, and subscription linked to the autopay user, but that don't have autopay enabled """ cls.non_autopay_account = generator.billing_account( web_user_creator=generator.create_arbitrary_web_user_name( is_dimagi=True), web_user_contact=cls.autopay_user_email) cls.non_autopay_domain = generator.arbitrary_domain() # Non-autopay subscription has same parameters as the autopayable subscription cls.non_autopay_subscription = generator.generate_domain_subscription( cls.non_autopay_account, cls.non_autopay_domain, date_start=cls.subscription.date_start, date_end=add_months_to_date(cls.subscription.date_start, cls.subscription_length), )
def setUp(self): super(TestSoftwarePlanChanges, self).setUp() self.domain = Domain( name="test-plan-changes", is_active=True, ) self.domain.save() self.domain2 = Domain( name="other-domain", is_active=True, ) self.domain2.save() self.admin_username = generator.create_arbitrary_web_user_name() self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_username)[0] self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) self.advanced_plan.plan.max_domains = 1 self.community_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.COMMUNITY)
def setUp(self): super(TestSoftwarePlanChanges, self).setUp() self.domain = Domain( name="test-plan-changes", is_active=True, ) self.domain.save() self.domain2 = Domain( name="other-domain", is_active=True, ) self.domain2.save() self.admin_username = generator.create_arbitrary_web_user_name() self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_username)[0] self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) self.advanced_plan.plan.max_domains = 1 self.community_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.COMMUNITY)
def test_set_autopay(self, fake_customer): fake_customer.__get__ = mock.Mock(return_value=self.fake_stripe_customer) self.assertEqual(self.billing_account.auto_pay_user, None) self.assertFalse(self.billing_account.auto_pay_enabled) self.payment_method.set_autopay(self.fake_card, self.billing_account, None) self.assertEqual(self.fake_card.metadata, {"auto_pay_{}".format(self.billing_account.id): 'True'}) self.assertEqual(self.billing_account.auto_pay_user, self.web_user) self.assertTrue(self.billing_account.auto_pay_enabled) self.payment_method.set_autopay(self.fake_card, self.billing_account_2, None) self.assertEqual(self.fake_card.metadata, {"auto_pay_{}".format(self.billing_account.id): 'True', "auto_pay_{}".format(self.billing_account_2.id): 'True'}) other_web_user = generator.create_arbitrary_web_user_name() other_payment_method = StripePaymentMethod(web_user=other_web_user) different_fake_card = FakeStripeCard() other_payment_method.set_autopay(different_fake_card, self.billing_account, None) self.assertEqual(self.billing_account.auto_pay_user, other_web_user) self.assertTrue(different_fake_card.metadata["auto_pay_{}".format(self.billing_account.id)]) self.assertFalse(self.fake_card.metadata["auto_pay_{}".format(self.billing_account.id)] == 'True')
def setUp(self): super(TestNewDomainSubscription, self).setUp() self.domain = Domain( name="test-domain-sub", is_active=True, ) self.domain.save() self.domain2 = Domain( name="test-domain-sub2", is_active=True, ) self.domain2.save() self.admin_user_name = generator.create_arbitrary_web_user_name() self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_user_name)[0] self.account2 = BillingAccount.get_or_create_account_by_domain( self.domain2.name, created_by=self.admin_user_name)[0] self.standard_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.STANDARD) self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED)
def setUp(self): super(TestNewDomainSubscription, self).setUp() self.domain = Domain( name="test-domain-sub", is_active=True, ) self.domain.save() self.domain2 = Domain( name="test-domain-sub2", is_active=True, ) self.domain2.save() self.admin_user_name = generator.create_arbitrary_web_user_name() self.account = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by=self.admin_user_name)[0] self.account2 = BillingAccount.get_or_create_account_by_domain( self.domain2.name, created_by=self.admin_user_name)[0] self.standard_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.STANDARD) self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED)
def _generate_non_autopayable_entities(cls): """ Create account, domain, and subscription linked to the autopay user, but that don't have autopay enabled """ cls.non_autopay_account = generator.billing_account( web_user_creator=generator.create_arbitrary_web_user_name(is_dimagi=True), web_user_contact=cls.autopay_user_email ) cls.non_autopay_domain = generator.arbitrary_domain() # Non-autopay subscription has same parameters as the autopayable subscription cheap_plan = SoftwarePlan.objects.create(name='cheap') cheap_product_rate = SoftwareProductRate.objects.create(monthly_fee=100, name=cheap_plan.name) cheap_plan_version = SoftwarePlanVersion.objects.create( plan=cheap_plan, product_rate=cheap_product_rate, role=Role.objects.first(), ) cls.non_autopay_subscription = generator.generate_domain_subscription( cls.non_autopay_account, cls.non_autopay_domain, plan_version=cheap_plan_version, date_start=cls.subscription.date_start, date_end=add_months_to_date(cls.subscription.date_start, cls.subscription_length), )
def setUp(self): super(TestBillingAccount, self).setUp() self.billing_contact = generator.create_arbitrary_web_user_name() self.dimagi_user = generator.create_arbitrary_web_user_name(is_dimagi=True) self.currency = generator.init_default_currency() self.billing_account = generator.billing_account(self.dimagi_user, self.billing_contact)
def setUpClass(cls): super().setUpClass() cls.domain1, subscriber1 = generator.arbitrary_domain_and_subscriber() cls.domain2, subscriber2 = generator.arbitrary_domain_and_subscriber() cls.admin_web_user = generator.create_arbitrary_web_user_name() account = generator.billing_account(cls.admin_web_user, cls.admin_web_user) account.is_customer_billing_account = True account.save() enterprise_plan = SoftwarePlan.objects.create( name="Helping Earth INGO Enterprise Plan", description="Enterprise plan for Helping Earth", edition=SoftwarePlanEdition.ENTERPRISE, visibility=SoftwarePlanVisibility.INTERNAL, is_customer_software_plan=True, ) first_product_rate = SoftwareProductRate.objects.create( monthly_fee=3000, name="HQ Enterprise") cls.first_version = SoftwarePlanVersion.objects.create( plan=enterprise_plan, role=Role.objects.first(), product_rate=first_product_rate) cls.first_version.save() today = datetime.date.today() two_months_ago = today - datetime.timedelta(days=60) next_month = today + datetime.timedelta(days=30) subscription1 = Subscription( account=account, plan_version=cls.first_version, subscriber=subscriber1, date_start=two_months_ago, date_end=None, service_type=SubscriptionType.IMPLEMENTATION, ) subscription1.is_active = True subscription1.save() subscription2 = Subscription( account=account, plan_version=cls.first_version, subscriber=subscriber2, date_start=two_months_ago, date_end=next_month, service_type=SubscriptionType.IMPLEMENTATION, ) subscription2.is_active = True subscription2.save() new_product_rate = SoftwareProductRate.objects.create( monthly_fee=5000, name="HQ Enterprise") cls.newest_version = SoftwarePlanVersion.objects.create( plan=enterprise_plan, role=Role.objects.first(), product_rate=new_product_rate) cls.newest_version.save()
def get_billing_account_for_idp(): billing_contact = accounting_gen.create_arbitrary_web_user_name() dimagi_user = accounting_gen.create_arbitrary_web_user_name(is_dimagi=True) return accounting_gen.billing_account( dimagi_user, billing_contact, is_customer_account=True )