def test_get_text_for_word_counts_not_full_text(self): """Test get_text_for_word_counts() with full text RSS disabled.""" story_description = 'Not full text RSS description' download_texts = [ 'Not full text 1', 'Not full text 2', 'Not full text 3', ] assert len(story_description) < len("\n\n".join(download_texts)) self.test_story = self.db().update_by_id( table='stories', object_id=self.test_story['stories_id'], update_hash={ 'title': 'Not full text RSS title', 'description': story_description, 'full_text_rss': False, }, ) for download_text in download_texts: test_download = create_download_for_story(self.db(), feed=self.test_feed, story=self.test_story) downloads_id = test_download['downloads_id'] self.db().create( table='download_texts', insert_hash={ 'downloads_id': downloads_id, 'download_text': download_text, 'download_text_length': len(download_text), }) story_text = get_text_for_word_counts(db=self.db(), story=self.test_story) assert story_text == "Not full text 1.\n\nNot full text 2.\n\nNot full text 3"
def setUp(self) -> None: super().setUp() self.test_medium = create_test_medium(self.db(), 'downloads test') self.test_feed = create_test_feed(self.db(), 'downloads test', self.test_medium) self.test_story = create_test_story(self.db(), label='downloads est', feed=self.test_feed) self.test_download = create_download_for_story(self.db(), feed=self.test_feed, story=self.test_story)
def setUp(self) -> None: """Set config for tests.""" super().setUp() self.config = mediawords.util.config.get_config() self.test_medium = create_test_medium(self.db(), 'downloads test') self.test_feed = create_test_feed(self.db(), 'downloads test', self.test_medium) self.test_story = create_test_story(self.db(), label='downloads est', feed=self.test_feed) self.test_download = create_download_for_story(self.db(), feed=self.test_feed, story=self.test_story) self.test_download['path'] = 'postgresql:foo' self.test_download['state'] = 'success' self.test_download['stories_id'] = self.test_story['stories_id'] self.db().update_by_id('downloads', self.test_download['downloads_id'], self.test_download) mediawords.dbi.downloads.store_content(self.db(), self.test_download, self.__TEST_CONTENT) self.save_config = copy.deepcopy(self.config)
def setUp(self) -> None: """Set config for tests.""" super().setUp() self.test_medium = create_test_medium(self.db(), self.TEST_MEDIUM_NAME) self.test_feed = create_test_feed(self.db(), self.TEST_FEED_NAME, self.test_medium) self.test_story = create_test_story(self.db(), label=self.TEST_STORY_NAME, feed=self.test_feed) self.test_download = create_download_for_story(self.db(), feed=self.test_feed, story=self.test_story)
def setUp(self) -> None: super().setUp() self.test_medium = create_test_medium(self.db(), 'downloads test') self.test_feed = create_test_feed(self.db(), 'downloads test', self.test_medium) self.test_story = create_test_story(self.db(), label='downloads est', feed=self.test_feed) self.test_download = create_download_for_story(self.db(), feed=self.test_feed, story=self.test_story)
def setUp(self) -> None: """Set config for tests.""" super().setUp() self.db = connect_to_db() self.test_medium = create_test_medium(self.db, 'downloads test') self.test_feed = create_test_feed(self.db, 'downloads test', self.test_medium) self.test_download_feed = create_download_for_feed(self.db, self.test_feed) self.test_story = create_test_story(self.db, label='downloads est', feed=self.test_feed) self.test_download = create_download_for_story(self.db, feed=self.test_feed, story=self.test_story) store_content(db=self.db, download=self.test_download, content=self.__TEST_CONTENT)
def setUp(self) -> None: """Set config for tests.""" super().setUp() self.test_medium = create_test_medium(self.db(), self.TEST_MEDIUM_NAME) self.test_feed = create_test_feed(self.db(), self.TEST_FEED_NAME, self.test_medium) self.test_story = create_test_story(self.db(), label=self.TEST_STORY_NAME, feed=self.test_feed) self.test_download = create_download_for_story(self.db(), feed=self.test_feed, story=self.test_story)
def setUp(self): """Create test_story and test_download.""" super().setUp() self.db = connect_to_db() media = create_test_story_stack(self.db, {'A': {'B': [1]}}) story = media['A']['feeds']['B']['stories']['1'] download = create_download_for_story( db=self.db, feed=media['A']['feeds']['B'], story=story, ) store_content(self.db, download, '<p>foo</p>') self.test_story = story self.test_download = download
def setUp(self) -> None: """Set config for tests.""" super().setUp() self.config = mediawords.util.config.get_config() self.test_medium = create_test_medium(self.db(), 'downloads test') self.test_feed = create_test_feed(self.db(), 'downloads test', self.test_medium) self.test_story = create_test_story(self.db(), label='downloads est', feed=self.test_feed) self.test_download = create_download_for_story(self.db(), feed=self.test_feed, story=self.test_story) self.test_download['path'] = 'postgresql:foo' self.test_download['state'] = 'success' self.test_download['stories_id'] = self.test_story['stories_id'] self.db().update_by_id('downloads', self.test_download['downloads_id'], self.test_download) mediawords.dbi.downloads.store_content(self.db(), self.test_download, self.__TEST_CONTENT) self.save_config = copy.deepcopy(self.config)
def test_get_extracted_text(self): download_texts = [ 'Text 1', 'Text 2', 'Text 3', ] for download_text in download_texts: test_download = create_download_for_story(self.db(), feed=self.test_feed, story=self.test_story) downloads_id = test_download['downloads_id'] self.db().create( table='download_texts', insert_hash={ 'downloads_id': downloads_id, 'download_text': download_text, 'download_text_length': len(download_text), }) extracted_text = _get_extracted_text(db=self.db(), story=self.test_story) assert extracted_text == "Text 1.\n\nText 2.\n\nText 3"
def test_get_extracted_text(self): download_texts = [ 'Text 1', 'Text 2', 'Text 3', ] for download_text in download_texts: test_download = create_download_for_story(self.db, feed=self.test_feed, story=self.test_story) downloads_id = test_download['downloads_id'] self.db.create(table='download_texts', insert_hash={ 'downloads_id': downloads_id, 'download_text': download_text, 'download_text_length': len(download_text), }) extracted_text = _get_extracted_text(db=self.db, story=self.test_story) assert extracted_text == "Text 1.\n\nText 2.\n\nText 3"
def test_get_text_for_word_counts_not_full_text(self): """Test get_text_for_word_counts() with full text RSS disabled.""" story_description = 'Not full text RSS description' download_texts = [ 'Not full text 1', 'Not full text 2', 'Not full text 3', ] assert len(story_description) < len("\n\n".join(download_texts)) self.test_story = self.db.update_by_id( table='stories', object_id=self.test_story['stories_id'], update_hash={ 'title': 'Not full text RSS title', 'description': story_description, 'full_text_rss': False, }, ) for download_text in download_texts: test_download = create_download_for_story(self.db, feed=self.test_feed, story=self.test_story) downloads_id = test_download['downloads_id'] self.db.create(table='download_texts', insert_hash={ 'downloads_id': downloads_id, 'download_text': download_text, 'download_text_length': len(download_text), }) story_text = get_text_for_word_counts(db=self.db, story=self.test_story) assert story_text == "Not full text 1.\n\nNot full text 2.\n\nNot full text 3"