本文整理汇总了Python中subscriber.Subscriber.order_new_subscription方法的典型用法代码示例。如果您正苦于以下问题:Python Subscriber.order_new_subscription方法的具体用法?Python Subscriber.order_new_subscription怎么用?Python Subscriber.order_new_subscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subscriber.Subscriber
的用法示例。
在下文中一共展示了Subscriber.order_new_subscription方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSubscriber
# 需要导入模块: from subscriber import Subscriber [as 别名]
# 或者: from subscriber.Subscriber import order_new_subscription [as 别名]
class TestSubscriber(unittest.TestCase):
'''Tests the Subscriber class'''
def setUp(self):
'''Initialize the object and database'''
self.sub = Subscriber()
self.conn = sqlite3.Connection('../databases/test.db')
self.cursor = self.conn.cursor()
self.cursor.execute('DELETE FROM subscribers')
self.conn.commit()
def tearDown(self):
'''Close the database'''
self.cursor.close()
self.conn.close()
def test_subscriber_last_name(self):
'''Test if the subscriber is created with default values'''
self.assertEqual(self.sub.lastname, '')
def test_new_subscribtion(self):
'''Test if the order_new_subscription method add 6 issues left'''
former_issues_left = 3
self.sub.issues_to_receive = former_issues_left
self.sub.order_new_subscription()
self.assertEqual(self.sub.issues_to_receive, former_issues_left + 6)
def test_get_subscribers_from_name(self):
'''Retrieve a subsriber list using name'''
sql = """INSERT INTO subscribers (lastname, firstname)
VALUES ('DUPONT', 'Jean')"""
self.cursor.execute(sql)
self.conn.commit()
sub_class = Subscriber
self.sub = sub_class.get_subscribers_from_lastname('DUPONT')[0]
self.assertEqual(self.sub.firstname, 'Jean')
def test_get_subscribers_from_name_like(self):
'''Retrieve a subsriber list using beginning of the name'''
sql = """INSERT INTO subscribers (lastname, firstname)
VALUES ('DUPONT-ANDRE', 'Toto')"""
self.cursor.execute(sql)
self.conn.commit()
sub_class = Subscriber
self.sub = sub_class.get_subscribers_from_lastname('DUPONT')[0]
self.assertEqual(self.sub.firstname, 'Toto')
def test_get_subscribers_from_company(self):
'''Retrieve a subsriber list using a company name'''
sql = """INSERT INTO subscribers (company, name_addition)
VALUES ('Google', 'IsNotEvil')"""
self.cursor.execute(sql)
self.conn.commit()
sub_class = Subscriber
self.sub = sub_class.get_subscribers_from_company('Google')[0]
self.assertEqual(self.sub.name_addition, 'IsNotEvil')
def test_get_subscribers_from_company_like(self):
'''Retrieve a subsriber list using the beginning of company name'''
sql = """INSERT INTO subscribers (company, name_addition)
VALUES ('REDHAT', 'IsTrankil')"""
self.cursor.execute(sql)
self.conn.commit()
sub_class = Subscriber
self.sub = sub_class.get_subscribers_from_company('RED')[0]
self.assertEqual(self.sub.name_addition, 'IsTrankil')
def test_save_subscriber(self):
'''Test that subscriber information are saved in the DB'''
self.sub.firstname = 'John'
self.sub.lastname = 'Doe'
#TODO add other attributes
self.sub.save()
results = self.cursor.execute('SELECT firstname, lastname FROM subscribers')
for row in results:
self.assertEqual(row[0], 'John')
self.assertEqual(row[1], 'Doe')
def test_update_subscriber(self):
'''Test that a subscriber update is well commited in the data base'''
sql = """INSERT INTO subscribers (lastname, firstname)
VALUES ('DUPONT', 'Jean')"""
self.cursor.execute(sql)
sql = """INSERT INTO subscribers (lastname, firstname)
VALUES ('DUPONT', 'Jean')"""
self.cursor.execute(sql)
self.conn.commit()
sub_class = Subscriber
self.sub = sub_class.get_subscribers_from_lastname('DUPONT')[0]
expected = '[email protected]'
self.sub.email_address = expected
self.sub.save()
sql = """SELECT email_address FROM subscribers
WHERE lastname = 'DUPONT' AND id = ?"""
result = self.cursor.execute(sql, (self.sub.identifier,))
for row in result:
actual = row[0]
self.assertEqual(expected, actual)
def test_delete_customer(self):
#.........这里部分代码省略.........