本文整理汇总了Python中subscriber.Subscriber类的典型用法代码示例。如果您正苦于以下问题:Python Subscriber类的具体用法?Python Subscriber怎么用?Python Subscriber使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Subscriber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
def add(self, msisdn, credit):
sub = Subscriber()
sms = SMS();
try:
mysub = sub.get(msisdn)
except SubscriberException as e:
raise CreditException(e)
current_balance = sub.get_balance(msisdn)
new_balance = Decimal(str(credit)) + Decimal(str(current_balance))
# update subscriber balance
try:
cur = db_conn.cursor()
cur.execute('UPDATE subscribers SET balance=%(new_balance)s WHERE msisdn=%(msisdn)s', {'new_balance': Decimal(str(new_balance)), 'msisdn': msisdn})
sms.send(config['smsc'], msisdn, sms_credit_added % (credit, new_balance))
except psycopg2.DatabaseError as e:
raise CreditException('PG_HLR error updating subscriber balance: %s' % e)
# insert transaction into the credit history
try:
cur = db_conn.cursor()
cur.execute('INSERT INTO credit_history(msisdn,previous_balance,current_balance,amount) VALUES(%s,%s,%s,%s)', (msisdn, current_balance, new_balance, credit))
except psycopg2.DatabaseError as e:
db_conn.rollback()
raise CreditException('PG_HLR error inserting invoice in the history: %s' % e)
finally:
db_conn.commit()
示例2: validate_data
def validate_data(self, pin):
res_log.debug('Check PIN length')
if len(pin) > 4 or len(pin) < 4:
raise ResellerException('PIN invalid length')
res_log.debug('Check if Reseller exists')
# check if reseller exists in the database and the PIN is valid
try:
cur = db_conn.cursor()
cur.execute('SELECT msisdn,pin FROM resellers WHERE msisdn=%(msisdn)s', {'msisdn': str(self.reseller_msisdn)})
if cur.rowcount > 0:
res_log.debug('Valid Reseller found')
res_log.debug('Auth PIN')
data = cur.fetchone()
if data[1] != pin:
raise ResellerException('Invalid PIN!')
res_log.debug('Check if subscriber is valid')
# check if subscriber exists
try:
sub = Subscriber()
sub.get(self.subscriber_msisdn)
except SubscriberException as e:
raise ResellerException('Invalid subscriber')
else:
raise ResellerException('Invalid Reseller')
except psycopg2.DatabaseError as e:
raise ResellerException('Database error getting reseller msisdn: %s' % e)
示例3: test_non_ascii_char
def test_non_ascii_char(self):
subscriber = Subscriber()
subscriber.lastname = u'Toto°°'
subscriber.issues_to_receive = 1
subscriber.save()
line = get_first_line()
self.assertTrue(line is not None)
示例4: test_email_in_lowercase
def test_email_in_lowercase(self):
"""Tests that in generated file, the emails are in lower case"""
subscriber = Subscriber()
subscriber.issues_to_receive = 0
subscriber.email_address = '[email protected]'
subscriber.save()
lines = self.export_and_get_lines()
self.assertEqual('[email protected]', lines.strip())
示例5: test_remaining_issues_subscriber
def test_remaining_issues_subscriber(self):
"""Tests when the subscriber has remaining issues"""
subs = Subscriber()
subs.issues_to_receive = 1
subs.email_address = '[email protected]'
subs.save()
lines = self.export_and_get_lines()
self.assertEqual('', lines)
示例6: test_one_email
def test_one_email(self):
"""Test retrieval of one subscriber's email"""
subscriber = Subscriber()
subscriber.issues_to_receive = 0
subscriber.email_address = '[email protected]'
subscriber.save()
lines = self.export_and_get_lines()
self.assertEqual('[email protected]', lines.strip())
示例7: test_null_post_code_format
def test_null_post_code_format(self):
"""Test the postcode format when a null postcode is in db: 00000 is
ugly"""
sub = Subscriber()
sub.lastname = 'toto'
address = Address()
address.post_code = 0
sub.address = address
sub.save()
dict_list = SubscriberAdapter.get_subscribers_from_lastname('toto')
new_sub = dict_list[0]
self.assertEquals('', new_sub['post_code'])
示例8: SubscriberTest
class SubscriberTest(unittest.TestCase):
def setUp(self):
self.subscriber = Subscriber('asd', '[email protected]')
def test_get_id(self):
self.assertEqual(-1, self.subscriber.get_id())
def test_get_name(self):
self.assertEqual('asd', self.subscriber.get_name())
def test_get_email(self):
self.assertEqual('[email protected]', self.subscriber.get_email())
示例9: set_regular_subscriber
def set_regular_subscriber(self):
sub = Subscriber()
sub.lastname = 'Nom'
sub.firstname = 'Prenom'
sub.name_addition = 'NameAddition'
a = Address()
a.address1 = 'Adresse'
a.address2 = 'Addition'
a.post_code = 12345
a.city = 'Ville'
sub.address = a
return sub
示例10: test_5_digit_post_code
def test_5_digit_post_code(self):
"""Checks that the exported post_code is always written with 5 digits,
even if the first one is 0."""
sub = Subscriber()
sub.issues_to_receive = 1
a = Address()
a.post_code = 1300
sub.address = a
sub.save()
line = self.export_and_get_first_line()
splitted_line = line.split('\t')
self.assertEqual(splitted_line[8], '01300')
示例11: test_create_and_delete_subscriber
def test_create_and_delete_subscriber(self):
sub = Subscriber()
sub.lastname = 'toto'
sub.save()
ident = sub.identifier
SubscriberAdapter.delete_from_id(ident)
actual_result_count = len(
Subscriber.get_subscribers_from_lastname('toto')
)
self.assertEqual(0, actual_result_count)
示例12: test_subscriber_without_remaining_issue
def test_subscriber_without_remaining_issue(self):
"""Test if a subscriber that has no issue left will not receive a free
number :)"""
subscriber = Subscriber()
subscriber.lastname = 'toto'
subscriber.issues_to_receive = 1
subscriber.save()
subscriber = Subscriber()
subscriber.lastname = 'tata'
subscriber.issues_to_receive = 0
subscriber.save()
self.exporter.do_export()
self.__test_presence_toto_tata()
示例13: test_empty_email
def test_empty_email(self):
"""Tests what appens when a subscriber has no email"""
subscriber = Subscriber()
subscriber.email_address = '[email protected]'
subscriber.issues_to_receive = 0
subscriber.save()
subscriber = Subscriber()
subscriber.email_address = ''
subscriber.issues_to_receive = 0
subscriber.save()
lines = self.export_and_get_lines()
self.assertEqual('[email protected]\n', lines)
示例14: test_two_email
def test_two_email(self):
"""Tests when we have two emails in generated file"""
subscriber = Subscriber()
subscriber.email_address = '[email protected]'
subscriber.issues_to_receive = 0
subscriber.save()
subscriber = Subscriber()
subscriber.email_address = '[email protected]'
subscriber.issues_to_receive = 0
subscriber.save()
lines = self.export_and_get_lines()
self.assertEqual('[email protected]\[email protected]\n', lines)
示例15: send_subscription_fee_notice
def send_subscription_fee_notice(self, msg):
# get all subscribers
try:
sub = Subscriber()
subscribers_list = sub.get_all()
except SubscriberException as e:
raise SubscriptionException('%s' % e)
sms = SMS()
for mysub in subscribers_list:
self.logger.debug("Send sms to %s %s" % (mysub[1], msg))
sms.send(config['smsc'],mysub[1], msg)