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 test_transfers(self): advanced_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED ) standard_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.STANDARD ) first_sub = Subscription.new_domain_subscription( self.account, self.domain.name, advanced_plan, date_start=datetime.date.today() - relativedelta(days=1), ) product_credit = CreditLine.add_credit( self.product_credit_amt, subscription=first_sub, is_product=True, ) feature_credit = CreditLine.add_credit( self.feature_credit_amt, subscription=first_sub, feature_type=FeatureType.USER, ) subscription_credit = CreditLine.add_credit( self.subscription_credit_amt, subscription=first_sub, ) original_credits = [ product_credit, feature_credit, subscription_credit, ] second_sub = first_sub.change_plan(standard_plan) second_credits = self._ensure_transfer(original_credits) for credit_line in second_credits: self.assertEqual(credit_line.subscription.pk, second_sub.pk) second_sub.date_end = datetime.date.today() + datetime.timedelta(days=5) second_sub.save() third_sub = second_sub.renew_subscription() deactivate_subscriptions(second_sub.date_end) third_sub = Subscription.visible_objects.get(id=third_sub.id) third_credits = self._ensure_transfer(second_credits) for credit_line in third_credits: self.assertEqual(credit_line.subscription.pk, third_sub.pk) third_sub.date_end = third_sub.date_start + relativedelta(days=1) third_sub.save() Subscription.new_domain_subscription( self.other_account, self.domain, DefaultProductPlan.get_default_plan_version(), date_start=third_sub.date_end, ) deactivate_subscriptions(third_sub.date_end) account_credits = self._ensure_transfer(third_credits) for credit_line in account_credits: self.assertIsNone(credit_line.subscription) self.assertEqual(credit_line.account.pk, self.account.pk)
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 test_community_over_limit(self): """ For a domain under community (no subscription) with users over the community limit, make sure that: - base_description is None - base_cost is 0.0 - unit_description is not None - unit_cost is equal to the per_excess_fee on the user rate - quantity is equal to number of commcare users in that domain minus the monthly_limit on the user rate - total and subtotals are equal to number of extra users * per_excess_fee """ domain = generator.arbitrary_domain() num_active = generator.create_excess_community_users(domain) account = BillingAccount.get_or_create_account_by_domain( domain, created_by=self.dimagi_user)[0] billing_contact = generator.arbitrary_contact_info(account, self.dimagi_user) account.date_confirmed_extra_charges = datetime.date.today() account.save() tasks.generate_invoices() subscriber = Subscriber.objects.get(domain=domain.name) invoice = Invoice.objects.filter(subscription__subscriber=subscriber).get() user_line_item = invoice.lineitem_set.get_feature_by_type(FeatureType.USER).get() self.assertIsNone(user_line_item.base_description) self.assertEqual(user_line_item.base_cost, Decimal('0.0000')) community_plan = DefaultProductPlan.get_default_plan_version() num_to_charge = num_active - community_plan.user_limit self.assertIsNotNone(user_line_item.unit_description) self.assertEqual(user_line_item.quantity, num_to_charge) self.assertEqual(user_line_item.unit_cost, self.user_rate.per_excess_fee) self.assertEqual(user_line_item.subtotal, num_to_charge * self.user_rate.per_excess_fee) self.assertEqual(user_line_item.total, num_to_charge * self.user_rate.per_excess_fee) domain.delete()
def _test_plan_versions_ensured(self, bootstrap_config): ensure_plans(bootstrap_config, True, apps) for (edition, is_trial, has_report_builder), config in six.iteritems(bootstrap_config): software_plan_version = DefaultProductPlan.get_default_plan_version( edition=edition, is_trial=is_trial, is_report_builder_enabled=has_report_builder ) self.assertEqual(software_plan_version.role.slug, config['role']) self.assertEqual(software_plan_version.product_rate.monthly_fee, config['product_rate_monthly_fee']) self.assertEqual( software_plan_version.user_limit, config['feature_rates'][FeatureType.USER]['monthly_limit'] ) self.assertEqual( software_plan_version.user_feature.per_excess_fee, config['feature_rates'][FeatureType.USER]['per_excess_fee'] ) sms_feature_rate = software_plan_version.feature_rates.get(feature__feature_type=FeatureType.SMS) self.assertEqual( sms_feature_rate.monthly_limit, config['feature_rates'][FeatureType.SMS]['monthly_limit'] ) self.assertEqual(sms_feature_rate.per_excess_fee, 0)
def cancel_subscription(self): self.subscription.change_plan( new_plan_version=DefaultProductPlan.get_default_plan_version(), note=self.cancel_form.cleaned_data['note'], web_user=self.request.user.username, ) self.subscription_canceled = True
def setUp(self): super(TestDeleteDomain, self).setUp() self.domain = Domain(name="test", is_active=True) self.domain.save() self.domain.convert_to_commtrack() self.current_subscription = Subscription.new_domain_subscription( BillingAccount.get_or_create_account_by_domain(self.domain.name, created_by='tests')[0], self.domain.name, DefaultProductPlan.get_default_plan_version(SoftwarePlanEdition.ADVANCED), date_start=date.today() - relativedelta(days=1), ) self.domain2 = Domain(name="test2", is_active=True) self.domain2.save() self.domain2.convert_to_commtrack() LocationType.objects.create( domain='test', name='facility', ) LocationType.objects.create( domain='test2', name='facility', ) LocationType.objects.create( domain='test', name='facility2', ) LocationType.objects.create( domain='test2', name='facility2', )
def assign_explicit_community_subscription(domain_name, start_date): future_subscriptions = Subscription.objects.filter( CONSISTENT_DATES_CHECK ).filter( date_start__gt=start_date, subscriber__domain=domain_name, ) if future_subscriptions.exists(): end_date = future_subscriptions.latest('date_start').date_start else: end_date = None return Subscription.new_domain_subscription( account=BillingAccount.get_or_create_account_by_domain( domain_name, created_by='assign_explicit_community_subscriptions', entry_point=EntryPoint.SELF_STARTED, )[0], domain=domain_name, plan_version=DefaultProductPlan.get_default_plan_version(), date_start=start_date, date_end=end_date, skip_invoicing_if_no_feature_charges=True, adjustment_method=SubscriptionAdjustmentMethod.TASK, internal_change=True, service_type=SubscriptionType.PRODUCT, )
def _init_pro_with_rb_plan_and_version(self): plan = SoftwarePlan( name="Pro_with_30_RB_reports", description="Pro + 30 report builder reports", edition=SoftwarePlanEdition.PRO, visibility=SoftwarePlanVisibility.INTERNAL, ) plan.save() role = Role.objects.create( slug="pro_with_rb_30_role", name="Pro + 30 rb reports", ) for privilege in [privileges.REPORT_BUILDER_30]: # Doesn't actually include the pro roles... privilege = Role.objects.get(slug=privilege) Grant.objects.create( from_role=role, to_role=privilege, ) self.pro_rb_version = SoftwarePlanVersion( plan=plan, role=role ) self.pro_rb_version.product_rate = DefaultProductPlan.get_default_plan_version( SoftwarePlanEdition.PRO ).product_rate self.pro_rb_version.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_resubscription(self): subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, web_user=self.admin_user.username ) self._change_std_roles() new_subscription = subscription.change_plan(DefaultProductPlan.get_default_plan_version()) custom_role = UserRole.get(self.custom_role.get_id) self.assertTrue(custom_role.is_archived) new_subscription.change_plan(self.advanced_plan, web_user=self.admin_user.username) custom_role = UserRole.get(self.custom_role.get_id) self.assertFalse(custom_role.is_archived) # disable this part of the test until we improve the UX for notifying # downgraded users of their privilege changes # custom_web_user = WebUser.get(self.web_users[0].get_id) # custom_commcare_user = CommCareUser.get(self.commcare_users[0].get_id) # self.assertEqual( # custom_web_user.get_domain_membership(self.domain.name).role_id, # self.read_only_role.get_id # ) # self.assertIsNone( # custom_commcare_user.get_domain_membership(self.domain.name).role_id # ) self._assertInitialRoles() self._assertStdUsers()
def assign_explicit_community_subscription(domain_name, start_date, method, account=None, web_user=None): future_subscriptions = Subscription.visible_objects.filter( date_start__gt=start_date, subscriber__domain=domain_name, ) if future_subscriptions.exists(): end_date = future_subscriptions.earliest('date_start').date_start else: end_date = None if account is None: account = BillingAccount.get_or_create_account_by_domain( domain_name, created_by='assign_explicit_community_subscriptions', entry_point=EntryPoint.SELF_STARTED, )[0] return Subscription.new_domain_subscription( account=account, domain=domain_name, plan_version=DefaultProductPlan.get_default_plan_version(), date_start=start_date, date_end=end_date, skip_invoicing_if_no_feature_charges=True, adjustment_method=method, internal_change=True, service_type=SubscriptionType.PRODUCT, web_user=web_user, )
def _downgrade_domain(subscription): subscription.change_plan( DefaultProductPlan.get_default_plan_version( SoftwarePlanEdition.COMMUNITY ), note='Automatic downgrade to community for invoice 60 days late', internal_change=True )
def test_app_icon_permissions(self): LOGO_HOME = 'hq_logo_android_home' LOGO_LOGIN = '******' advanced_sub = self._subscribe_to_advanced() with open(os.path.join(os.path.dirname(__file__), 'data', 'app-commcare-icon-standard.json')) as f: standard_source = json.load(f) with open(os.path.join(os.path.dirname(__file__), 'data', 'app-commcare-icon-build.json')) as f: build_source = json.load(f) app_standard = Application.wrap(standard_source) app_standard.save() self.assertEqual(self.project.name, app_standard.domain) app_build = Application.wrap(build_source) app_build.save() self.assertEqual(self.project.name, app_build.domain) self.assertTrue(LOGO_HOME in app_standard.logo_refs) self.assertTrue(LOGO_LOGIN in app_standard.logo_refs) self.assertTrue(LOGO_HOME in app_build.logo_refs) self.assertTrue(LOGO_LOGIN in app_build.logo_refs) community_sub = advanced_sub.change_plan(DefaultProductPlan.get_default_plan_version()) app_standard = Application.get(app_standard._id) app_build = Application.get(app_build._id) self.assertFalse(LOGO_HOME in app_standard.logo_refs) self.assertFalse(LOGO_LOGIN in app_standard.logo_refs) self.assertFalse(LOGO_HOME in app_build.logo_refs) self.assertFalse(LOGO_LOGIN in app_build.logo_refs) community_sub.change_plan( DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) ) app_standard = Application.get(app_standard._id) app_build = Application.get(app_build._id) self.assertTrue(LOGO_HOME in app_standard.logo_refs) self.assertTrue(LOGO_LOGIN in app_standard.logo_refs) self.assertTrue(LOGO_HOME in app_build.logo_refs) self.assertTrue(LOGO_LOGIN in app_build.logo_refs)
def _downgrade_domain(subscription): subscription.change_plan( DefaultProductPlan.get_default_plan_version( SoftwarePlanEdition.COMMUNITY ), adjustment_method=SubscriptionAdjustmentMethod.AUTOMATIC_DOWNGRADE, note='Automatic downgrade to community for invoice 60 days late', internal_change=True )
def test_change_plan_on_renewal(self): new_edition = SoftwarePlanEdition.ADVANCED new_plan = DefaultProductPlan.get_default_plan_version(new_edition) self.renewed_subscription = self.subscription.renew_subscription( new_version=new_plan ) self.assertEqual(self.renewed_subscription.plan_version, new_plan)
def test_subscription_credits_transfer_in_invoice(self): standard_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.STANDARD ) pro_plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.PRO ) first_sub = Subscription.new_domain_subscription( self.account, self.domain.name, standard_plan, date_start=datetime.date(2019, 9, 1), ) credit_amount = Decimal('5000.00') CreditLine.add_credit( credit_amount, subscription=first_sub, ) # this is the key step where the expected transfer happens second_sub = first_sub.change_plan(pro_plan) first_sub = Subscription.visible_objects.get(id=first_sub.id) first_sub.date_end = datetime.date(2019, 9, 10) first_sub.save() second_sub.date_start = first_sub.date_end second_sub.save() invoice_date = utils.months_from_date(first_sub.date_start, 1) user_record_date = invoice_date - relativedelta(days=1) DomainUserHistory.objects.create( domain=self.domain, num_users=0, record_date=user_record_date ) tasks.generate_invoices(utils.months_from_date(first_sub.date_start, 1)) self.assertEqual(first_sub.invoice_set.count(), 1) self.assertEqual(second_sub.invoice_set.count(), 1) first_invoice = first_sub.invoice_set.first() second_invoice = second_sub.invoice_set.first() self.assertEqual(first_invoice.balance, Decimal('0.0000')) self.assertEqual(second_invoice.balance, Decimal('0.0000')) self.assertEqual(self._get_credit_total(second_sub), Decimal('4490.0000'))
def setup_subscription(cls, domain_name, software_plan): generator.instantiate_accounting() plan = DefaultProductPlan.get_default_plan_version(edition=software_plan) cls.account = BillingAccount.get_or_create_account_by_domain( domain_name, created_by="automated-test" + cls.__name__ )[0] cls.subscription = Subscription.new_domain_subscription(cls.account, domain_name, plan) cls.subscription.is_active = True cls.subscription.save()
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 setUpClass(cls): super(TestOdataFeed, cls).setUpClass() cls.client = Client() cls.domain = Domain(name='test_domain') cls.domain.save() cls.web_user = WebUser.create(cls.domain.name, 'test_user', 'my_password') cls.account, _ = BillingAccount.get_or_create_account_by_domain(cls.domain.name, created_by='') plan_version = DefaultProductPlan.get_default_plan_version(SoftwarePlanEdition.STANDARD) cls.subscription = Subscription.new_domain_subscription(cls.account, cls.domain.name, plan_version)
def apply_prbac(cls, request): subscription = (Subscription.get_active_subscription_by_domain( request.domain) if hasattr(request, 'domain') else None) if subscription: plan_version = subscription.plan_version request.role = plan_version.role request.plan = plan_version request.subscription = subscription else: plan_version = DefaultProductPlan.get_default_plan_version() request.role = plan_version.role request.plan = plan_version
def bootrap_domain_for_zapier(domain_name): domain_object = Domain.get_or_create_with_name(domain_name, is_active=True) account = BillingAccount.get_or_create_account_by_domain(domain_name, created_by="automated-test")[0] plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.STANDARD) subscription = Subscription.new_domain_subscription(account, domain_name, plan) subscription.is_active = True subscription.save() web_user = WebUser.create(domain_name, 'test', '******') api_key_object, _ = ApiKey.objects.get_or_create(user=web_user.get_django_user()) return ZapierDomainConfig(domain_object, web_user, api_key_object.key)
def _setup_subscription(cls, domain_name, software_plan): plan = DefaultProductPlan.get_default_plan_version(edition=software_plan) account = BillingAccount.get_or_create_account_by_domain( domain_name, created_by="automated-test" + cls.__name__ )[0] subscription = Subscription.new_domain_subscription( account, domain_name, plan, date_start=datetime.date.today() - datetime.timedelta(days=1), date_end=datetime.date.today() + datetime.timedelta(days=5)) subscription.save()
def rows_for_domain(self, domain): subscription = Subscription.get_active_subscription_by_domain( domain.name) plan_version = subscription.plan_version if subscription else DefaultProductPlan.get_default_plan_version( ) return [[ plan_version.plan.name, self.format_date(domain.date_created), get_mobile_user_count(domain.name, include_inactive=False), get_web_user_count(domain.name, include_inactive=False), self.format_date(get_last_form_submission_received(domain.name)), ] + self.domain_properties(domain)]
def _setup_subscription(cls, domain_name, software_plan): plan = DefaultProductPlan.get_default_plan_version( edition=software_plan) account = BillingAccount.get_or_create_account_by_domain( domain_name, created_by="automated-test" + cls.__name__)[0] subscription = Subscription.new_domain_subscription( account, domain_name, plan, date_start=datetime.date.today() - datetime.timedelta(days=1), date_end=datetime.date.today() + datetime.timedelta(days=5)) subscription.save()
def prepare_domain(domain_name): from corehq.apps.commtrack.tests.util import bootstrap_domain domain = bootstrap_domain(domain_name) previous = None for name, administrative in [ ("MOHSW", True), ("MSDZONE", True), ("REGION", True), ("DISTRICT", True), ("FACILITY", False) ]: previous, _ = LocationType.objects.get_or_create( domain=domain_name, name=name, parent_type=previous, administrative=administrative, ) generator.instantiate_accounting() account = BillingAccount.get_or_create_account_by_domain( domain.name, created_by="automated-test", )[0] plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED ) commtrack = domain.commtrack_settings commtrack.actions.append( CommtrackActionConfig(action='receipts', keyword='delivered', caption='Delivered') ) commtrack.save() subscription = Subscription.new_domain_subscription( account, domain.name, plan ) subscription.is_active = True subscription.save() ils_config = ILSGatewayConfig(enabled=True, domain=domain.name, all_stock_data=True) ils_config.save() fields_definition = CustomDataFieldsDefinition.get_or_create(domain.name, 'LocationFields') fields_definition.fields.append(CustomDataField( slug='group', label='Group', is_required=False, choices=['A', 'B', 'C'], is_multiple_choice=False )) fields_definition.save() return domain
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 test_cancellation(self): subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, web_user=self.admin_username ) self._change_std_roles() subscription.change_plan(DefaultProductPlan.get_default_plan_version()) custom_role = UserRole.objects.by_couch_id(self.custom_role.get_id) self.assertTrue(custom_role.is_archived) self._assertInitialRoles() self._assertStdUsers()
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 _domain_rows(self, domain): subscription = Subscription.get_active_subscription_by_domain( domain.name) plan_version = subscription.plan_version if subscription else DefaultProductPlan.get_default_plan_version( ) return [ self._domain_properties(domain) + [ plan_version.plan.name, str(get_mobile_user_count(domain.name, include_inactive=False)), str(get_web_user_count(domain.name, include_inactive=False)), ] ]
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(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 apply_prbac(cls, request): subscription = ( Subscription.get_active_subscription_by_domain(request.domain) if hasattr(request, 'domain') else None ) if subscription: plan_version = subscription.plan_version request.role = plan_version.role request.plan = plan_version request.subscription = subscription else: plan_version = DefaultProductPlan.get_default_plan_version() request.role = plan_version.role request.plan = plan_version
def prepare_domain(domain_name): domain = create_domain(domain_name) domain.convert_to_commtrack() domain.save() set_domain_default_backend_to_test_backend(domain.name) def _make_loc_type(name, administrative=False, parent_type=None): return LocationType.objects.get_or_create( domain=domain_name, name=name, administrative=administrative, parent_type=parent_type, )[0] country = _make_loc_type(name="country", administrative=True) _make_loc_type(name="Central Medical Store", parent_type=country) _make_loc_type(name="Teaching Hospital", parent_type=country) region = _make_loc_type(name="region", administrative=True, parent_type=country) _make_loc_type(name="Regional Medical Store", parent_type=region) _make_loc_type(name="Regional Hospital", parent_type=region) district = _make_loc_type(name="district", administrative=True, parent_type=region) _make_loc_type(name="Clinic", parent_type=district) _make_loc_type(name="District Hospital", parent_type=district) _make_loc_type(name="Health Centre", parent_type=district) _make_loc_type(name="CHPS Facility", parent_type=district) _make_loc_type(name="Hospital", parent_type=district) _make_loc_type(name="Psychiatric Hospital", parent_type=district) _make_loc_type(name="Polyclinic", parent_type=district) _make_loc_type(name="facility", parent_type=district) generator.instantiate_accounting() account = BillingAccount.get_or_create_account_by_domain( domain.name, created_by="automated-test", )[0] plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED ) subscription = Subscription.new_domain_subscription( account, domain.name, plan ) subscription.is_active = True subscription.save() ews_config = EWSGhanaConfig(enabled=True, domain=domain.name) ews_config.save() return domain
def setup_domain(cls, name): domain_obj = Domain(name=name, sms_mobile_worker_registration_enabled=True) domain_obj.save() plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) account = BillingAccount.get_or_create_account_by_domain( name, created_by="automated-test-" + cls.__name__ )[0] subscription = Subscription.new_domain_subscription(account, name, plan) subscription.is_active = True subscription.save() domain_obj = Domain.get(domain_obj.get_id) return (domain_obj, account, subscription)
def prepare_domain(domain_name): domain = create_domain(domain_name) domain.convert_to_commtrack() domain.save() set_domain_default_backend_to_test_backend(domain.name) def _make_loc_type(name, administrative=False, parent_type=None): return LocationType.objects.get_or_create( domain=domain_name, name=name, administrative=administrative, parent_type=parent_type, )[0] country = _make_loc_type(name="country", administrative=True) _make_loc_type(name="Central Medical Store", parent_type=country) _make_loc_type(name="Teaching Hospital", parent_type=country) region = _make_loc_type(name="region", administrative=True, parent_type=country) _make_loc_type(name="Regional Medical Store", parent_type=region) _make_loc_type(name="Regional Hospital", parent_type=region) district = _make_loc_type(name="district", administrative=True, parent_type=region) _make_loc_type(name="Clinic", parent_type=district) _make_loc_type(name="District Hospital", parent_type=district) _make_loc_type(name="Health Centre", parent_type=district) _make_loc_type(name="CHPS Facility", parent_type=district) _make_loc_type(name="Hospital", parent_type=district) _make_loc_type(name="Psychiatric Hospital", parent_type=district) _make_loc_type(name="Polyclinic", parent_type=district) _make_loc_type(name="facility", parent_type=district) generator.instantiate_accounting() account = BillingAccount.get_or_create_account_by_domain( domain.name, created_by="automated-test", )[0] plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED) subscription = Subscription.new_domain_subscription( account, domain.name, plan) subscription.is_active = True subscription.save() ews_config = EWSGhanaConfig(enabled=True, domain=domain.name) ews_config.save() return domain
def setUp(self): super(TestDomainInvoiceFactory, self).setUp() self.invoice_start, self.invoice_end = get_previous_month_date_range() self.domain = generator.arbitrary_domain() self.account = BillingAccount.get_or_create_account_by_domain( domain=self.domain.name, created_by="TEST")[0] self.community = DefaultProductPlan.get_default_plan_version() generator.arbitrary_commcare_users_for_domain( self.domain.name, self.community.user_limit + 1) self.invoice_factory = DomainInvoiceFactory(self.invoice_start, self.invoice_end, self.domain)
def setUp(self): super(TestInvoicingMethods, self).setUp() self.invoice_start = datetime.date(2018, 5, 1) self.invoice_end = datetime.date(2018, 5, 31) self.domain = generator.arbitrary_domain() self.account = BillingAccount.get_or_create_account_by_domain( domain=self.domain, created_by="TEST" )[0] self.account.is_customer_billing_account = True self.account.save() self.invoice_factory = CustomerAccountInvoiceFactory(self.invoice_start, self.invoice_end, self.account) self.advanced_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) self.advanced_plan.plan.is_customer_software_plan = True self.pro_plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.PRO) self.pro_plan.plan.is_customer_software_plan = True self.subscription = Subscription.new_domain_subscription( self.account, self.domain.name, self.advanced_plan, date_start=self.invoice_start, date_end=self.invoice_end )
def setUp(self): super(TestExportUtils, self).setUp() self.domain = generator.arbitrary_domain() self.account, _ = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by='*****@*****.**') self.account.save() subscription = Subscription.new_domain_subscription( self.account, self.domain.name, DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.COMMUNITY), date_start=date.today() - timedelta(days=3)) subscription.is_active = True subscription.save()
def setup_subscription(cls, domain_name, software_plan): generator.bootstrap_test_software_plan_versions() plan = DefaultProductPlan.get_default_plan_version(edition=software_plan) account = BillingAccount.get_or_create_account_by_domain( domain_name, created_by="automated-test" + cls.__name__ )[0] subscription = Subscription.new_domain_subscription(account, domain_name, plan) subscription.is_active = True subscription.save() cls.__subscriptions = cls.__subscriptions or {} cls.__subscriptions[domain_name] = subscription cls.__accounts = cls.__accounts or {} cls.__accounts[domain_name] = account
def setUpClass(cls): super().setUpClass() cls.project = create_domain(DOMAIN_NAME) account, __ = BillingAccount.get_or_create_account_by_domain( DOMAIN_NAME, created_by=ADMIN_USER) plan = DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ADVANCED) Subscription.new_domain_subscription( account, DOMAIN_NAME, plan, web_user=ADMIN_USER, )
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 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(TestExportUtils, self).setUp() self.domain = Domain.get_or_create_with_name('test-export-utils', is_active=True) self.account, _ = BillingAccount.get_or_create_account_by_domain( self.domain.name, created_by='*****@*****.**') self.account.save() subscription = Subscription.new_domain_subscription( self.account, self.domain.name, DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.ENTERPRISE), date_start=date.today() - timedelta(days=3)) subscription.is_active = True subscription.save()
def setUpClass(cls): super(TestZapierCreateCaseAction, cls).setUpClass() cls.domain_object = Domain.get_or_create_with_name('fruit', is_active=True) cls.domain = cls.domain_object.name account = BillingAccount.get_or_create_account_by_domain(cls.domain, created_by="automated-test")[0] plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.STANDARD) subscription = Subscription.new_domain_subscription(account, cls.domain, plan) subscription.is_active = True subscription.save() cls.query_string = "?domain=fruit&case_type=watermelon&owner_id=test_user&user=test" cls.data = {'case_name': 'test1', 'price': '11'} cls.accessor = CaseAccessors(cls.domain) cls.user = WebUser.create(cls.domain, 'test', '******') api_key_object, _ = ApiKey.objects.get_or_create(user=cls.user.get_django_user()) cls.api_key = api_key_object.key
def setUpClass(cls): super(TestOdataFeed, cls).setUpClass() cls.client = Client() cls.domain = Domain(name='test_domain') cls.domain.save() cls.web_user = WebUser.create(cls.domain.name, 'test_user', 'my_password') cls.account, _ = BillingAccount.get_or_create_account_by_domain( cls.domain.name, created_by='') plan_version = DefaultProductPlan.get_default_plan_version( SoftwarePlanEdition.STANDARD) cls.subscription = Subscription.new_domain_subscription( cls.account, cls.domain.name, plan_version)
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()
def test_accounting_future_subscription_suppressed(self): self.current_subscription.date_end = self.current_subscription.date_start + relativedelta( days=5) self.current_subscription.save() next_subscription = Subscription.new_domain_subscription( self.current_subscription.account, self.domain.name, DefaultProductPlan.get_default_plan_version( edition=SoftwarePlanEdition.PRO), date_start=self.current_subscription.date_end, ) self.domain.delete() self.assertTrue( Subscription.visible_and_suppressed_objects.get( id=next_subscription.id).is_hidden_to_ops)
def setUpClass(cls): super(APIResourceTest, cls).setUpClass() Role.get_cache().clear() cls.domain = Domain.get_or_create_with_name('qwerty', is_active=True) cls.list_endpoint = cls._get_list_endpoint() cls.username = '******' cls.password = '******' cls.user = WebUser.create(cls.domain.name, cls.username, cls.password) cls.user.set_role(cls.domain.name, 'admin') cls.user.save() cls.account = BillingAccount.get_or_create_account_by_domain(cls.domain.name, created_by="automated-test")[0] plan = DefaultProductPlan.get_default_plan_version(edition=SoftwarePlanEdition.ADVANCED) cls.subscription = Subscription.new_domain_subscription(cls.account, cls.domain.name, plan) cls.subscription.is_active = True cls.subscription.save() cls.api_key, _ = ApiKey.objects.get_or_create(user=WebUser.get_django_user(cls.user))