Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up Invoicing Tests #35576

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions corehq/apps/accounting/tests/base_tests.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import datetime

from django.test import TestCase

from dateutil.relativedelta import relativedelta
from django_prbac.models import Role

from corehq.apps.accounting import utils
from corehq.apps.accounting.tasks import (
calculate_users_in_all_domains,
calculate_web_users_in_all_billing_accounts,
generate_invoices_based_on_date,
)
from corehq.apps.accounting.tests import generator


Expand All @@ -11,3 +20,62 @@ class BaseAccountingTest(TestCase):
def setUpClass(cls):
super(BaseAccountingTest, cls).setUpClass()
Role.get_cache().clear()


class BaseInvoiceTestCase(BaseAccountingTest):

is_using_test_plans = False
min_subscription_length = 3
is_testing_web_user_feature = False

@classmethod
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
cls.subscription_start_date = datetime.date(2016, 2, 23)
cls.subscription_is_active = False
if cls.is_testing_web_user_feature:
# make sure the subscription is still active when we count web users
cls.subscription_is_active = True
cls.subscription_end_date = cls.subscription_start_date + relativedelta(months=cls.subscription_length)
cls.subscription = generator.generate_domain_subscription(
cls.account,
cls.domain,
date_start=cls.subscription_start_date,
date_end=cls.subscription_end_date,
is_active=cls.subscription_is_active
)

def tearDown(self):
for user in self.domain.all_users():
user.delete(self.domain.name, deleted_by=None)
super(BaseAccountingTest, self).tearDown()

@classmethod
def tearDownClass(cls):
cls.domain.delete()

if cls.is_using_test_plans:
utils.clear_plan_version_cache()

super(BaseInvoiceTestCase, cls).tearDownClass()

def create_invoices(self, date, calculate_users=True, calculate_web_users=False):
if calculate_users:
calculate_users_in_all_domains(date)

if calculate_web_users:
calculate_web_users_in_all_billing_accounts(date)

generate_invoices_based_on_date(date)
191 changes: 0 additions & 191 deletions corehq/apps/accounting/tests/test_invoice_factory.py

This file was deleted.

Loading
Loading