Example #1
0
def arbitrary_sms_billables_for_domain(domain,
                                       message_month_date,
                                       num_sms,
                                       direction=None,
                                       multipart_count=1):
    direction = direction or random.choice(DIRECTIONS)

    gateway_fee = SmsGatewayFee.create_new('MACH', direction, Decimal(0.5))
    usage_fee = SmsUsageFee.create_new(direction, Decimal(0.25))

    _, last_day_message = calendar.monthrange(message_month_date.year,
                                              message_month_date.month)

    billables = []
    for _ in range(0, num_sms):
        sms_billable = SmsBillable(
            gateway_fee=gateway_fee,
            usage_fee=usage_fee,
            log_id=data_gen.arbitrary_unique_name()[:50],
            phone_number=data_gen.random_phonenumber(),
            domain=domain,
            direction=direction,
            date_sent=datetime.date(message_month_date.year,
                                    message_month_date.month,
                                    random.randint(1, last_day_message)),
            multipart_count=multipart_count,
        )
        sms_billable.save()
        billables.append(sms_billable)
    return billables
Example #2
0
def generate_domain_subscription_from_date(date_start, billing_account, domain,
                                           min_num_months=None, is_immediately_active=False,
                                           delay_invoicing_until=None, save=True):
    # make sure the first month is never a full month (for testing)
    date_start = date_start.replace(day=max(2, date_start.day))

    subscription_length = random.randint(min_num_months or 3, 25)
    date_end_year, date_end_month = add_months(date_start.year, date_start.month, subscription_length)
    date_end_last_day = calendar.monthrange(date_end_year, date_end_month)[1]

    # make sure that the last month is never a full month (for testing)
    date_end = datetime.date(date_end_year, date_end_month, min(date_end_last_day - 1, date_start.day + 1))

    subscriber, _ = Subscriber.objects.get_or_create(domain=domain, organization=None)
    subscription = Subscription(
        account=billing_account,
        plan_version=arbitrary_subscribable_plan(),
        subscriber=subscriber,
        salesforce_contract_id=data_gen.arbitrary_unique_name("SFC")[:80],
        date_start=date_start,
        date_end=date_end,
        is_active=is_immediately_active,
        date_delay_invoicing=delay_invoicing_until,
    )
    if save:
        subscription.save()
    return subscription, subscription_length
Example #3
0
def arbitrary_sms_billables_for_domain(domain, direction, message_month_date,
                                       num_sms):
    from corehq.apps.smsbillables.models import SmsBillable, SmsGatewayFee, SmsUsageFee
    from corehq.apps.smsbillables import generator as sms_gen

    gateway_fee = SmsGatewayFee.create_new('MACH', direction,
                                           sms_gen.arbitrary_fee())
    usage_fee = SmsUsageFee.create_new(direction, sms_gen.arbitrary_fee())

    _, last_day_message = calendar.monthrange(message_month_date.year,
                                              message_month_date.month)

    for _ in range(0, num_sms):
        sms_billable = SmsBillable(
            gateway_fee=gateway_fee,
            usage_fee=usage_fee,
            log_id=data_gen.arbitrary_unique_name()[:50],
            phone_number=data_gen.random_phonenumber(),
            domain=domain,
            direction=direction,
            date_sent=datetime.date(message_month_date.year,
                                    message_month_date.month,
                                    random.randint(1, last_day_message)),
        )
        sms_billable.save()
Example #4
0
def arbitrary_domain():
    domain = Domain(
        name=data_gen.arbitrary_unique_name()[:20],
        is_active=True,
    )
    domain.save()
    return domain
Example #5
0
def arbitrary_web_user(save=True, is_dimagi=False):
    domain = data_gen.arbitrary_unique_name().lower()[:25]
    username = "******" % (data_gen.arbitrary_username(), 'dimagi' if is_dimagi else 'gmail')
    web_user = WebUser.create(domain, username, 'test123')
    if save:
        web_user.save()
    return web_user
Example #6
0
def generate_domain_subscription_from_date(date_start,
                                           billing_account,
                                           domain,
                                           min_num_months=None,
                                           is_immediately_active=False,
                                           delay_invoicing_until=None,
                                           save=True):
    # make sure the first month is never a full month (for testing)
    date_start = date_start.replace(day=max(2, date_start.day))

    subscription_length = random.randint(min_num_months or 3, 25)
    date_end_year, date_end_month = add_months(date_start.year,
                                               date_start.month,
                                               subscription_length)
    date_end_last_day = calendar.monthrange(date_end_year, date_end_month)[1]

    # make sure that the last month is never a full month (for testing)
    date_end = datetime.date(date_end_year, date_end_month,
                             min(date_end_last_day - 1, date_start.day + 1))

    subscriber, _ = Subscriber.objects.get_or_create(domain=domain,
                                                     organization=None)
    subscription = Subscription(
        account=billing_account,
        plan_version=arbitrary_subscribable_plan(),
        subscriber=subscriber,
        salesforce_contract_id=data_gen.arbitrary_unique_name("SFC")[:80],
        date_start=date_start,
        date_end=date_end,
        is_active=is_immediately_active,
        date_delay_invoicing=delay_invoicing_until,
    )
    if save:
        subscription.save()
    return subscription, subscription_length
Example #7
0
def arbitrary_domain():
    domain = Domain(
        name=data_gen.arbitrary_unique_name()[:20],
        is_active=True,
    )
    domain.save()
    return domain
Example #8
0
def billing_account(web_user_creator, web_user_contact, currency=None, save=True):
    account_name = data_gen.arbitrary_unique_name(prefix="BA")[:40]
    currency = currency or Currency.objects.get(code=settings.DEFAULT_CURRENCY)
    billing_account = BillingAccount(
        name=account_name,
        created_by=web_user_creator.username,
        currency=currency,
    )
    if save:
        billing_account.save()
        billing_contact = BillingContactInfo(
            account=billing_account,
            first_name=data_gen.arbitrary_firstname(),
            last_name=data_gen.arbitrary_lastname(),
            emails=web_user_creator.username,
            phone_number="+15555555",
            company_name="Company Name",
            first_line="585 Mass Ave",
            city="Cambridge",
            state_province_region="MA",
            postal_code="02139",
            country="US",
        )
        billing_contact.save()
        billing_account.billing_admins =\
            [BillingAccountAdmin.objects.get_or_create(web_user=web_user_contact.username)[0]]
        billing_account.save()

    return billing_account
Example #9
0
def arbitrary_sms_billables_for_domain(domain, message_month_date, num_sms, direction=None, multipart_count=1):
    from corehq.apps.smsbillables.models import SmsBillable, SmsGatewayFee, SmsUsageFee

    direction = direction or random.choice(DIRECTIONS)

    gateway_fee = SmsGatewayFee.create_new('MACH', direction, Decimal(0.5))
    usage_fee = SmsUsageFee.create_new(direction, Decimal(0.25))

    _, last_day_message = calendar.monthrange(message_month_date.year, message_month_date.month)

    billables = []
    for _ in range(0, num_sms):
        sms_billable = SmsBillable(
            gateway_fee=gateway_fee,
            usage_fee=usage_fee,
            log_id=data_gen.arbitrary_unique_name()[:50],
            phone_number=data_gen.random_phonenumber(),
            domain=domain,
            direction=direction,
            date_sent=datetime.date(message_month_date.year, message_month_date.month,
                                    random.randint(1, last_day_message)),
            multipart_count=multipart_count,
        )
        sms_billable.save()
        billables.append(sms_billable)
    return billables
Example #10
0
def billing_account(web_user_creator, web_user_contact, currency=None, save=True):
    account_name = data_gen.arbitrary_unique_name(prefix="BA")[:40]
    currency = currency or Currency.objects.get(code=settings.DEFAULT_CURRENCY)
    billing_account = BillingAccount(name=account_name, created_by=web_user_creator.username, currency=currency)
    if save:
        billing_account.save()
        billing_contact = arbitrary_contact_info(billing_account, web_user_contact)
        billing_contact.save()
    return billing_account
Example #11
0
def arbitrary_commcare_user(domain, is_active=True):
    username = data_gen.arbitrary_unique_name()[:80]
    try:
        commcare_user = CommCareUser.create(domain, username, 'test123')
        commcare_user.is_active = is_active
        commcare_user.save()
        return commcare_user
    except Exception:
        pass
Example #12
0
def arbitrary_commcare_user(domain, is_active=True):
    username = data_gen.arbitrary_unique_name()[:80]
    try:
        commcare_user = CommCareUser.create(domain, username, 'test123')
        commcare_user.is_active = is_active
        commcare_user.save()
        return commcare_user
    except Exception:
        pass
Example #13
0
def arbitrary_backend_ids():
    backend_ids = {}
    for backend in get_available_backends().values():
        backend_instance = data_gen.arbitrary_unique_name("back")
        backend_ids[backend.get_api_id()] = backend_instance
        sms_backend = SMSBackend()
        sms_backend._id = backend_instance
        sms_backend.is_global = True
        sms_backend.save()
    return backend_ids
Example #14
0
def arbitrary_backend_ids():
    backend_ids = {}
    for backend in get_available_backends().values():
        backend_instance = data_gen.arbitrary_unique_name("back")
        backend_ids[backend.get_api_id()] = backend_instance
        sms_backend = SMSBackend()
        sms_backend._id = backend_instance
        sms_backend.is_global = True
        sms_backend.save()
    return backend_ids
Example #15
0
def billing_account(web_user_creator, web_user_contact):
    account_name = data_gen.arbitrary_unique_name(prefix="BA")[:40]
    currency = Currency.objects.get(code=settings.DEFAULT_CURRENCY)
    billing_account = BillingAccount.objects.create(
        name=account_name,
        created_by=web_user_creator,
        currency=currency,
    )
    arbitrary_contact_info(billing_account, web_user_contact)
    return billing_account
Example #16
0
def arbitrary_backend_ids():
    backend_ids = {}
    for backend in _available_gateway_fee_backends():
        backend_instance = data_gen.arbitrary_unique_name("back")
        backend_ids[backend.get_api_id()] = backend_instance
        sms_backend = backend()
        sms_backend.hq_api_id = backend.get_api_id()
        sms_backend.couch_id = backend_instance
        sms_backend.name = backend_instance
        sms_backend.is_global = True
        sms_backend.save()
    return backend_ids
Example #17
0
def arbitrary_web_user(save=True, is_dimagi=False):
    domain = data_gen.arbitrary_unique_name().lower()[:25]
    username = "******" % (data_gen.arbitrary_username(),
                              'dimagi' if is_dimagi else 'gmail')
    try:
        web_user = WebUser.create(domain, username, 'test123')
    except Exception:
        web_user = WebUser.get_by_username(username)
    web_user.is_active = True
    if save:
        web_user.save()
    return web_user
Example #18
0
def arbitrary_non_global_backend_ids():
    backend_ids = {}
    for backend in _available_gateway_fee_backends():
        backend_instance = data_gen.arbitrary_unique_name("back")
        backend_ids[backend.get_api_id()] = backend_instance
        sms_backend = backend()
        sms_backend.hq_api_id = backend.get_api_id()
        sms_backend.couch_id = backend_instance
        sms_backend.name = backend_instance
        sms_backend.is_global = False
        sms_backend.save()
    return backend_ids
Example #19
0
def arbitrary_backend_ids():
    backend_ids = {}
    for backend in get_sms_backend_classes().values():
        backend_instance = data_gen.arbitrary_unique_name("back")
        backend_ids[backend.get_api_id()] = backend_instance
        sms_backend = backend()
        sms_backend.hq_api_id = backend.get_api_id()
        sms_backend.couch_id = backend_instance
        sms_backend.name = backend_instance
        sms_backend.is_global = True
        sms_backend.save()
    return backend_ids
Example #20
0
def arbitrary_non_global_with_direct_fees_backends():
    backends = []
    for backend in _available_direct_fee_backends():
        backend_instance = data_gen.arbitrary_unique_name("back")
        sms_backend = backend()
        sms_backend.hq_api_id = backend.get_api_id()
        sms_backend.couch_id = backend_instance
        sms_backend.name = backend_instance
        sms_backend.is_global = False
        sms_backend.set_extra_fields(
            account_sid='sid',
            auth_token='token',
        )
        sms_backend.save()
        backends.append(sms_backend)
    return backends
Example #21
0
def billing_account(web_user_creator,
                    web_user_contact,
                    currency=None,
                    save=True):
    account_name = data_gen.arbitrary_unique_name(prefix="BA")[:40]
    currency = currency or Currency.objects.get(code=settings.DEFAULT_CURRENCY)
    billing_account = BillingAccount(
        name=account_name,
        created_by=web_user_creator.username,
        currency=currency,
    )
    if save:
        billing_account.save()
        billing_contact = arbitrary_contact_info(billing_account,
                                                 web_user_contact)
        billing_contact.save()
    return billing_account
Example #22
0
def create_idp(account=None, include_certs=False):
    if not account:
        account = get_billing_account_for_idp()
    idp_slug = data_gen.arbitrary_unique_name()[:20]
    idp = IdentityProvider(name=f"Azure AD for {account.name}",
                           slug=idp_slug,
                           owner=account)
    idp.save()
    if include_certs:
        idp.create_service_provider_certificate()
        idp.entity_id = "https://testidp.com/saml2/entity_id"
        idp.login_url = "https://testidp.com/saml2/login"
        idp.logout_url = "https://testidp.com/saml2/logout"
        key_pair = certificates.create_key_pair()
        cert = certificates.create_self_signed_cert(key_pair)
        idp.idp_cert_public = certificates.get_public_key(cert)
        idp.date_idp_cert_expiration = certificates.get_expiration_date(cert)
        idp.save()
    return idp
Example #23
0
def arbitrary_sms_billables_for_domain(domain, direction, message_month_date, num_sms):
    from corehq.apps.smsbillables.models import SmsBillable, SmsGatewayFee, SmsUsageFee
    from corehq.apps.smsbillables import generator as sms_gen

    gateway_fee = SmsGatewayFee.create_new('MACH', direction, sms_gen.arbitrary_fee())
    usage_fee = SmsUsageFee.create_new(direction, sms_gen.arbitrary_fee())

    _, last_day_message = calendar.monthrange(message_month_date.year, message_month_date.month)

    for _ in range(0, num_sms):
        sms_billable = SmsBillable(
            gateway_fee=gateway_fee,
            usage_fee=usage_fee,
            log_id=data_gen.arbitrary_unique_name()[:50],
            phone_number=data_gen.random_phonenumber(),
            domain=domain,
            direction=direction,
            date_sent=datetime.date(message_month_date.year, message_month_date.month,
                                    random.randint(1, last_day_message)),
        )
        sms_billable.save()
Example #24
0
def arbitrary_backend_ids():
    backend_ids = {}
    for backend in get_available_backends().values():
        backend_ids[backend.get_api_id()] = data_gen.arbitrary_unique_name(
            "back")
    return backend_ids
Example #25
0
def arbitrary_backend_ids():
    backend_ids = {}
    for backend in get_available_backends().values():
        backend_ids[backend.get_api_id()] = data_gen.arbitrary_unique_name("back")
    return backend_ids