本文整理汇总了Python中corehq.apps.smsbillables.models.SmsBillable.create方法的典型用法代码示例。如果您正苦于以下问题:Python SmsBillable.create方法的具体用法?Python SmsBillable.create怎么用?Python SmsBillable.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类corehq.apps.smsbillables.models.SmsBillable
的用法示例。
在下文中一共展示了SmsBillable.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def handle(self, *args, **options):
num_sms = 0
start_datetime = datetime.datetime(*str_to_int_tuple(args[0:6]))
end_datetime = datetime.datetime(*str_to_int_tuple(args[6:12]))
for domain in Domain.get_all():
key = [domain.name, 'SMSLog']
sms_docs = SMSLog.get_db().view('sms/by_domain',
reduce=False,
startkey=key + [start_datetime.isoformat()],
endkey=key + [end_datetime.isoformat(), {}],
)
for sms_doc in sms_docs:
sms_log = SMSLog.get(sms_doc['id'])
if options.get('create', False):
SmsBillable.create(sms_log)
print 'Created billable for SMSLog %s in domain %s from %s' \
% (sms_doc['id'], domain.name, sms_log.date)
else:
print 'Found SMSLog %s in domain %s from %s' \
% (sms_doc['id'], domain.name, sms_log.date)
num_sms += 1
print 'Number of SMSs in datetime range: %d' % num_sms
示例2: handle
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def handle(self, *args, **options):
billables_created = 0
for domain in Domain.get_all():
key = [domain.name, 'SMSLog']
start_date = [datetime.datetime(2014, 1, 1).isoformat()]
end_date = [datetime.datetime(2014, 1, 24).isoformat()]
sms_docs = SMSLog.get_db().view('sms/by_domain',
reduce=False,
startkey=key + start_date,
endkey=key + end_date + [{}])
for sms_doc in sms_docs:
sms_log = SMSLog.get(sms_doc['id'])
try:
if sms_log.phone_number is not None:
parse_phone_number(sms_log.phone_number)
except PhoneNumberParseException:
billables = SmsBillable.objects.filter(log_id=sms_log._id)
if len(billables) == 0:
SmsBillable.create(sms_log)
billables_created += 1
print 'created SmsBillable for invalid number %s in domain %s, id=%s'\
% (sms_log.phone_number, domain.name, sms_log._id)
elif len(billables) > 1:
print "Warning: >1 SmsBillable exists for SMSLog with id=%" % sms_log._id
print 'Number of SmsBillables created: %d' % billables_created
print 'Completed retrobilling.'
示例3: store_billable
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def store_billable(msg):
if msg._id and not SmsBillable.objects.filter(log_id=msg._id).exists():
try:
msg.text.encode('iso-8859-1')
msg_length = 160
except UnicodeEncodeError:
# This string contains unicode characters, so the allowed
# per-sms message length is shortened
msg_length = 70
for _ in range(int(math.ceil(float(len(msg.text)) / msg_length))):
SmsBillable.create(msg)
示例4: test_twilio_multipart_usage_charge
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def test_twilio_multipart_usage_charge(self):
self.apply_direction_fee()
twilio_backend = SQLTwilioBackend.objects.create(
name='TWILIO',
is_global=True,
hq_api_id=SQLTwilioBackend.get_api_id(),
couch_id='global_backend',
)
twilio_backend.set_extra_fields(
account_sid='sid',
auth_token='token',
)
twilio_backend.save()
messages = generator.arbitrary_messages_by_backend_and_direction(
{twilio_backend.hq_api_id: twilio_backend.couch_id}
)
for message in messages:
FakeTwilioMessageFactory.add_num_segments_for_message(message.backend_message_id, randint(1, 10))
FakeTwilioMessageFactory.add_price_for_message(message.backend_message_id, generator.arbitrary_fee())
for message in messages:
multipart_count = randint(1, 10) # Should be ignored
billable = SmsBillable.create(message, multipart_count=multipart_count)
self.assertIsNotNone(billable)
self.assertEqual(
billable.usage_charge,
(
self.least_specific_fees[message.direction]
* FakeTwilioMessageFactory.get_num_segments_for_message(
message.backend_message_id
)
)
)
示例5: test_prefix_fees
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def test_prefix_fees(self):
self.create_prefix_gateway_fees()
for phone_number, prefix in generator.arbitrary_phone_numbers_and_prefixes(
self.country_code_and_prefixes
):
messages = generator.arbitrary_messages_by_backend_and_direction(
{
random_key: self.backend_ids[random_key]
for random_key in [choice(self.backend_ids.keys())]
},
phone_number=phone_number,
)
for msg_log in messages:
billable = SmsBillable.create(msg_log)
self.assertIsNotNone(billable)
try:
self.assertEqual(
billable.gateway_charge,
self.prefix_fees
[billable.direction]
[billable.gateway_fee.criteria.backend_api_id]
[phone_number[:-10]]
[prefix]
[msg_log.backend_id]
)
except AssertionError:
raise Exception(
"Phone number: %s, " % phone_number
+ "given prefix: %s, " % prefix
+ "found prefix: %s" % billable.gateway_fee.criteria.prefix
)
示例6: test_only_direction
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def test_only_direction(self):
self.apply_direction_fee()
messages = generator.arbitrary_messages_by_backend_and_direction(self.backend_ids)
for message in messages:
billable = SmsBillable.create(message)
self.assertIsNotNone(billable)
self.assertEqual(billable.usage_charge, self.least_specific_fees[message.direction])
示例7: test_least_specific_fees
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def test_least_specific_fees(self):
self.create_least_specific_gateway_fees()
for msg_log in self.message_logs:
billable = SmsBillable.create(msg_log)
self.assertIsNotNone(billable)
self.assertEqual(
billable.gateway_charge,
self.least_specific_fees[billable.direction][billable.gateway_fee.criteria.backend_api_id]
)
示例8: store_billable
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def store_billable(self, msg):
if not isinstance(msg, SMS):
raise Exception("Expected msg to be an SMS")
if msg.couch_id and not SmsBillable.objects.filter(log_id=msg.couch_id).exists():
try:
msg.text.encode('iso-8859-1')
msg_length = 160
except UnicodeEncodeError:
# This string contains unicode characters, so the allowed
# per-sms message length is shortened
msg_length = 70
try:
SmsBillable.create(
msg,
multipart_count=int(math.ceil(float(len(msg.text)) / msg_length)),
)
except RetryBillableTaskException as e:
self.retry(exc=e)
示例9: test_domain_and_direction
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def test_domain_and_direction(self):
self.apply_direction_fee()
self.apply_direction_and_domain_fee()
for direction, domain_fee in self.most_specific_fees.items():
for domain in domain_fee:
messages = generator.arbitrary_messages_by_backend_and_direction(self.backend_ids, domain=domain)
for message in messages:
billable = SmsBillable.create(message)
self.assertIsNotNone(billable)
self.assertEqual(billable.usage_charge, self.most_specific_fees[message.direction][domain])
示例10: handle
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def handle(self, start_datetime, end_datetime, **options):
num_sms = 0
for domain in Domain.get_all():
result = SMS.by_domain(
domain.name,
start_date=start_datetime,
end_date=end_datetime,
)
for sms_log in result:
if options.get('create', False):
SmsBillable.create(sms_log)
print('Created billable for SMS %s in domain %s from %s' \
% (sms_log.couch_id, domain.name, sms_log.date))
else:
print('Found SMS %s in domain %s from %s' \
% (sms_log.couch_id, domain.name, sms_log.date))
num_sms += 1
print('Number of SMSs in datetime range: %d' % num_sms)
示例11: test_log_no_usage_fee
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def test_log_no_usage_fee(self):
self.apply_direction_fee()
self.apply_direction_and_domain_fee()
for direction, domain_fee in self.most_specific_fees.items():
for domain in domain_fee:
messages = generator.arbitrary_messages_by_backend_and_direction(
self.backend_ids, domain=domain, directions=["X", "Y"]
)
for message in messages:
billable = SmsBillable.create(message)
self.assertIsNotNone(billable)
self.assertIsNone(billable.usage_fee)
示例12: test_no_matching_fee
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def test_no_matching_fee(self):
self.create_least_specific_gateway_fees()
self.create_country_code_gateway_fees()
self.create_instance_gateway_fees()
self.create_most_specific_gateway_fees()
phone_numbers = [generator.arbitrary_phone_number() for i in range(10)]
for phone_number in phone_numbers:
messages = generator.arbitrary_messages_by_backend_and_direction(self.backend_ids,
phone_number=phone_number,
directions=['X', 'Y'])
for msg_log in messages:
billable = SmsBillable.create(msg_log)
self.assertIsNotNone(billable)
self.assertIsNone(billable.gateway_fee)
示例13: test_country_code_fees
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def test_country_code_fees(self):
self.create_least_specific_gateway_fees()
self.create_country_code_gateway_fees()
phone_numbers = [generator.arbitrary_phone_number() for i in range(10)]
for phone_number in phone_numbers:
messages = generator.arbitrary_messages_by_backend_and_direction(self.backend_ids,
phone_number=phone_number)
for msg_log in messages:
billable = SmsBillable.create(msg_log)
self.assertIsNotNone(billable)
self.assertEqual(
billable.gateway_charge,
self.country_code_fees[billable.direction]
[billable.gateway_fee.criteria.backend_api_id]
[int(phone_number[:-10])]
)
示例14: store_billable
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def store_billable(msg):
SmsBillable.create(msg)
示例15: store_billable
# 需要导入模块: from corehq.apps.smsbillables.models import SmsBillable [as 别名]
# 或者: from corehq.apps.smsbillables.models.SmsBillable import create [as 别名]
def store_billable(msg):
if not SmsBillable.objects.filter(log_id=msg._id).exists():
for _ in range(int(math.ceil(float(len(msg.text)) / 160))):
SmsBillable.create(msg)