本文整理匯總了Python中importer.Importer.process方法的典型用法代碼示例。如果您正苦於以下問題:Python Importer.process方法的具體用法?Python Importer.process怎麽用?Python Importer.process使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類importer.Importer
的用法示例。
在下文中一共展示了Importer.process方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setup
# 需要導入模塊: from importer import Importer [as 別名]
# 或者: from importer.Importer import process [as 別名]
class TestImporter:
def setup(self):
self.engine = create_engine('sqlite://')
self.Session = sessionmaker()
self.Session.configure(bind=self.engine)
Base.metadata.create_all(self.engine)
self.importer = Importer()
self.importer.dataAccess.Session = self.Session
self.entry1 = Expando()
self.entry1.title = u'entry 1 title é'
self.entry1.description = u'entry 1 description é'
self.entry1.link = u'http://entry1.linké'
self.entry2 = Expando()
self.entry2.title = u'entry 2 title é'
self.entry2.description = u'entry 2 description é'
self.entry2.link = self.entry1.link
self.entry3 = Expando()
self.entry3.title = u'entry 3 title é'
self.entry3.description = u'entry 3 description é'
self.entry3.link = u'http://entry3.linké'
self.entry4 = Expando()
self.entry4.title = u'entry 4 title é'
self.entry4.description = u'entry 4 description é'
self.entry4.link = u'http://entry4.linké'
self.entry5 = Expando()
self.entry5.title = u'entry 4 title é'
self.entry5.link = u'http://entry4.linké'
self.feed1 = u'http://feed1url.urlé'
self.feed2 = u'http://feed2url.urlé'
self.feed1contents = Expando()
self.feed1contents.entries = [self.entry1, self.entry2]
self.feed2contents = Expando()
self.feed2contents.entries = [self.entry3, self.entry4]
def teardown(self):
Base.metadata.drop_all(self.engine)
def test_process_newSubmission_isSaved(self):
self.importer.process(self.entry1, self.feed1)
saved = self.Session().query(Submission).first()
assert saved.title == self.entry1.title
assert saved.description == self.entry1.description
assert saved.url == self.entry1.link
assert saved.feed == self.feed1
assert saved.created != None
def test_process_submissionWithExistingLink_isNotSaved(self):
self.importer.process(self.entry1, self.feed1)
self.importer.process(self.entry2, self.feed2)
assert self.Session().query(Submission).count() == 1
def test_process_submissionWithNoDescription_isSaved(self):
self.importer.process(self.entry5, self.feed1)
assert self.Session().query(Submission).count() == 1
def test_importFeeds_entriesAreSaved(self):
self.importer.parse_feed = Mock(
side_effect=[self.feed1contents, self.feed2contents])
self.importer.process = MagicMock()
self.importer.import_feeds([self.feed1, self.feed2])
self.importer.process.assert_has_calls(
[call(self.entry1, self.feed1),
call(self.entry2, self.feed1),
call(self.entry3, self.feed2),
call(self.entry4, self.feed2)])