예제 #1
0
    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,
        )
예제 #2
0
 def setUp(self):
     super(TestBillingAccount, self).setUp()
     self.billing_contact = generator.arbitrary_web_user()
     self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True)
     self.currency = generator.init_default_currency()
     self.billing_account = generator.billing_account(
         self.dimagi_user, self.billing_contact)
예제 #3
0
    def setUp(self):
        super(TestBillingRecord, self).setUp()
        self.billing_contact = generator.arbitrary_web_user()
        self.dimagi_user = generator.arbitrary_web_user(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)
예제 #4
0
    def setUp(self):
        super(TestStripePaymentMethod, self).setUp()

        self.web_user = generator.arbitrary_web_user()
        self.dimagi_user = generator.arbitrary_web_user(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.username,
                                                  customer_id=self.fake_stripe_customer.id)
        self.payment_method.save()
예제 #5
0
    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.arbitrary_web_user())

        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)
예제 #6
0
    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()
예제 #7
0
    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)
예제 #8
0
    def setUpClass(cls):
        super(TestEnterpriseSMSBillablesReport, cls).setUpClass()
        cls.domain = 'test-domain'
        cls.domain_obj = create_domain(cls.domain)
        cls.user = WebUser.create(
            cls.domain,
            "test-user",
            "123",
            None,
            None,
        )

        cls.account = generator.billing_account(cls.user,
                                                "*****@*****.**")
        cls.subscription_length = 15  # months
        subscription_start_date = datetime(2021, 1, 1)
        cls.subscription = generator.generate_domain_subscription(
            cls.account,
            cls.domain_obj,
            date_start=subscription_start_date,
            date_end=None)
        cls.subscription.is_active = True
        cls.subscription.save()

        cls.backend = SQLTestSMSBackend(
            name="TEST",
            is_global=True,
            domain=cls.domain,
            hq_api_id=SQLTestSMSBackend.get_api_id())
        cls.backend.save()
예제 #9
0
 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),
     )
예제 #10
0
    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()
예제 #11
0
    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))
예제 #12
0
    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)
        )
예제 #13
0
 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)
예제 #14
0
 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)
예제 #15
0
 def setUp(self):
     super(TestCreditTransfers, self).setUp()
     self.product_credit_amt = Decimal('500.00')
     self.feature_credit_amt = Decimal('200.00')
     self.subscription_credit_amt = Decimal('600.00')
     self.domain = generator.arbitrary_domain()
     self.account = BillingAccount.get_or_create_account_by_domain(
         self.domain, created_by="*****@*****.**",
     )[0]
     self.web_user = generator.arbitrary_web_user()
     # TODO - refactor interface to generator.billing_account so web user object is not required
     self.other_account = generator.billing_account(self.web_user, self.web_user)
예제 #16
0
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
예제 #17
0
 def setUp(self):
     super(TestCreditTransfers, self).setUp()
     self.product_credit_amt = Decimal('500.00')
     self.feature_credit_amt = Decimal('200.00')
     self.subscription_credit_amt = Decimal('600.00')
     self.domain = generator.arbitrary_domain()
     self.account = BillingAccount.get_or_create_account_by_domain(
         self.domain,
         created_by="*****@*****.**",
     )[0]
     self.web_user = generator.arbitrary_web_user()
     # TODO - refactor interface to generator.billing_account so web user object is not required
     self.other_account = generator.billing_account(self.web_user,
                                                    self.web_user)
예제 #18
0
 def _generate_non_autopayable_entities(self):
     """
     Create account, domain, and subscription linked to the autopay user, but that don't have autopay enabled
     """
     self.non_autopay_account = generator.billing_account(
         web_user_creator=generator.arbitrary_web_user(is_dimagi=True),
         web_user_contact=self.autopay_user
     )
     self.non_autopay_domain = generator.arbitrary_domain()
     # Non-autopay subscription has same parameters as the autopayable subscription
     self.non_autopay_subscription = generator.generate_domain_subscription(
         self.non_autopay_account,
         self.non_autopay_domain,
         date_start=self.subscription.date_start,
         date_end=add_months_to_date(self.subscription.date_start, self.subscription_length),
     )
예제 #19
0
 def _generate_non_autopayable_entities(self):
     """
     Create account, domain, and subscription linked to the autopay user, but that don't have autopay enabled
     """
     self.non_autopay_account = generator.billing_account(
         web_user_creator=generator.arbitrary_web_user(is_dimagi=True),
         web_user_contact=self.autopay_user)
     self.non_autopay_domain = generator.arbitrary_domain()
     # Non-autopay subscription has same parameters as the autopayable subscription
     self.non_autopay_subscription = generator.generate_domain_subscription(
         self.non_autopay_account,
         self.non_autopay_domain,
         date_start=self.subscription.date_start,
         date_end=add_months_to_date(self.subscription.date_start,
                                     self.subscription_length),
     )
    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(TestDomainsInLineItemForCustomerInvoicing, cls).setUpClass()

        cls.customer_account = generator.billing_account('*****@*****.**', '*****@*****.**')
        cls.customer_account.is_customer_billing_account = True
        cls.customer_account.save()

        cls.customer_plan_version = DefaultProductPlan.get_default_plan_version()
        cls.customer_plan_version.plan.is_customer_software_plan = True
        cls.customer_plan_version.plan.save()

        cls.mock_customer_invoice = Mock()
        cls.mock_customer_invoice.date_start = date(2019, 5, 1)
        cls.mock_customer_invoice.date_end = date(2019, 5, 31)

        cls.domain = Domain(name='test_domain')
        cls.domain.save()
예제 #22
0
    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
예제 #23
0
    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,
        )
예제 #24
0
    def setUp(self):
        super(TestSubscription, self).setUp()
        self.billing_contact = generator.arbitrary_web_user()
        self.dimagi_user = generator.arbitrary_web_user(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,
        )
예제 #25
0
    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,
        )
예제 #26
0
    def setUp(self):
        super(BaseInvoiceTestCase, self).setUp()
        self.billing_contact = generator.arbitrary_web_user()
        self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True)
        self.currency = generator.init_default_currency()
        self.account = generator.billing_account(
            self.dimagi_user, self.billing_contact)
        self.domain = generator.arbitrary_domain()

        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,
        )

        self.community_plan = DefaultProductPlan.get_default_plan_version()
예제 #27
0
    def setUp(self):
        super(BaseInvoiceTestCase, self).setUp()
        self.billing_contact = generator.arbitrary_web_user()
        self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True)
        self.currency = generator.init_default_currency()
        self.account = generator.billing_account(
            self.dimagi_user, self.billing_contact)
        self.domain = generator.arbitrary_domain()

        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,
        )

        self.community_plan = DefaultProductPlan.get_default_plan_version()
예제 #28
0
파일: utils.py 프로젝트: soitun/commcare-hq
def create_enterprise_permissions(email,
                                  source_domain,
                                  domains=None,
                                  other_domains=None):
    """
    Creates an account using the given email address and sets up enterprise permissions
    with the given source domain. Both `domains` and `other_domains` are added to the new account,
    but only `domains` are controlled by enterprise permissions.

    All given domains must exist.
    """
    account = generator.billing_account(email, email, is_customer_account=True)
    plan_version = generator.subscribable_plan_version(
        edition=SoftwarePlanEdition.ENTERPRISE)
    start_date = datetime.now().date()
    end_date = start_date + timedelta(days=365)
    subscriptions = []

    all_domains = [source_domain]
    if domains:
        all_domains.extend(domains)
    if other_domains:
        all_domains.extend(other_domains)
    for domain in all_domains:
        subscriptions.append(
            generator.generate_domain_subscription(
                account,
                Domain.get_by_name(domain),
                date_start=start_date,
                date_end=end_date,
                plan_version=plan_version,
                is_active=True,
            ))

    EnterprisePermissions(
        account=account,
        is_enabled=True,
        source_domain=source_domain,
        domains=domains,
    ).save()
예제 #29
0
    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,
        )
예제 #30
0
    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,
        )
예제 #31
0
 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),
     )
예제 #32
0
    def setUpClass(cls):
        super().setUpClass()

        plan = DefaultProductPlan.get_default_plan_version(
            edition=SoftwarePlanEdition.ADVANCED)

        cls.blocked_account = generator.billing_account(
            '*****@*****.**', '*****@*****.**')
        cls.blocked_account.block_hubspot_data_for_all_users = True
        cls.blocked_account.save()

        # this is one domain linked to the billing account that blocks hubspot
        cls.blocked_domain = create_domain('block-domain-hubspot')
        first_blocked_sub = Subscription.new_domain_subscription(
            cls.blocked_account, cls.blocked_domain.name, plan)
        first_blocked_sub.is_active = True
        first_blocked_sub.save()

        # this is another domain linked to the billing account that blocks hubspot
        cls.second_blocked_domain = create_domain('block-domain-hubspot-002')
        second_blocked_sub = Subscription.new_domain_subscription(
            cls.blocked_account, cls.second_blocked_domain.name, plan)
        second_blocked_sub.is_active = True
        second_blocked_sub.save()

        # this domain is not linked to an account that is blocking hubspot
        cls.allowed_domain = create_domain('allow-domain-hubspot')
        allowed_account = generator.billing_account('*****@*****.**',
                                                    '*****@*****.**')
        allowed_sub = Subscription.new_domain_subscription(
            allowed_account, cls.allowed_domain.name, plan)
        allowed_sub.is_active = True
        allowed_sub.save()

        cls.allowed_user = WebUser.create(cls.allowed_domain.name,
                                          '*****@*****.**', '*****', None,
                                          None)
        cls.allowed_user.save()

        cls.blocked_user = WebUser.create(cls.blocked_domain.name,
                                          '*****@*****.**', '*****', None,
                                          None)
        cls.blocked_user.save()
        cls.blocked_couch_user = CouchUser.get_by_username(
            cls.blocked_user.username)

        cls.second_blocked_user = WebUser.create(
            cls.second_blocked_domain.name, '*****@*****.**', '*****',
            None, None)
        cls.second_blocked_user.save()
        cls.second_blocked_couch_user = CouchUser.get_by_username(
            cls.second_blocked_user.username)

        cls.blocked_invitation_user = WebUser.create(
            cls.blocked_domain.name, '*****@*****.**',
            '*****', None, None)
        invite_to_blocked_domain = Invitation(
            email=cls.blocked_invitation_user.username,
            is_accepted=True,
            domain=cls.blocked_domain.name,
            invited_on=datetime.now(),
            invited_by="*****@*****.**",
        )
        invite_to_blocked_domain.save()

        cls.blocked_commcare_user = CommCareUser.create(
            cls.blocked_domain.name, 'testuser', '****', None, None)
        cls.blocked_commcare_user.save()
예제 #33
0
    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()
예제 #34
0
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
    )
예제 #35
0
 def setUp(self):
     super(TestBillingAccount, self).setUp()
     self.billing_contact = generator.arbitrary_web_user()
     self.dimagi_user = generator.arbitrary_web_user(is_dimagi=True)
     self.currency = generator.init_default_currency()
     self.billing_account = generator.billing_account(self.dimagi_user, self.billing_contact)