async def test_rename_documents_in_batch(self, answers, db, prompt, source_file): # Fixtures source_file_1 = source_file.symlink('blog/2019/03-08.batch_1.html') original_1 = ArticleFactory( uri='batch_1', title="To Rename", lead="To be renamed.", body="Please rename me!", ) assert original_1.last_update is None source_file_2 = source_file.symlink('blog/2019/03-08.batch_2.html') original_2 = ArticleFactory( uri='batch_2', title="To Rename", lead="To be renamed.", body="Please rename me!", ) assert original_2.last_update is None # Test new_path_1 = source_file.symlink('blog/2019/03-08.new_name_1.html') handler_1 = self.handler(source_file_1, prompt=prompt) renamed_1 = await handler_1.rename(new_path_1, batch=True) assert renamed_1 is original_1 assert renamed_1.uri == 'new_name_1' assert renamed_1.last_update is None new_path_2 = source_file.symlink('blog/2019/03-08.new_name_2.html') handler_2 = self.handler(source_file_2, prompt=prompt) renamed_2 = await handler_2.rename(new_path_2, batch=True) assert renamed_2 is original_2 assert renamed_2.uri == 'new_name_2' assert renamed_2.last_update is None prompt.answer_quiz() renamed_1.save() renamed_2.save() # Assertions assert renamed_1 is original_1 assert renamed_1.uri == 'new_name_1' assert renamed_1.last_update == date.today() self.assert_article_has_been_saved(renamed_1) assert renamed_2 is original_2 assert renamed_2.uri == 'new_name_2' assert renamed_2.last_update == date.today() self.assert_article_has_been_saved(renamed_2)
async def test_insert_new_category(self, answers, db, prompt, source_file): source_file.move('blog/2019/03-06.insert_category.html') article = ArticleFactory(uri='insert_category') await self.handler(source_file, prompt=prompt).insert_category() assert article.category.uri == 'music' assert article.category.name == 'Music'
def test_delete_document(self, db): article = ArticleFactory(uri='delete') source_file = PurePath('blog/2019/01-30.delete.html') assert Article.all() == [article] self.handler(source_file).delete() assert Article.all() == []
async def test_insert_existing_category(self, db, source_file): source_file.move('blog/2019/03-06.insert_category.html') article = ArticleFactory(uri='insert_category') category = CategoryFactory(uri='music', name='Musika') await self.handler(source_file).insert_category() # Let's be sure that attributes have not changed. assert article.category is category assert category.uri == 'music' assert category.name == 'Musika'
def create_articles(count: int) -> List[Article]: """Create blog articles, with different publication dates. Articles are sorted by publication date, in ascending order. :param count: number of articles to create. """ today = date.today() return [ ArticleFactory(publication_date=today - timedelta(days=days)) for days in range(count, 0, -1) ]
async def test_insert_new_tags(self, answers, db, prompt, source_file): source_file.move('blog/2019/03-06.insert_tags.html') article = ArticleFactory(uri='insert_tags') await self.handler(source_file, prompt=prompt).insert_tags() assert len(article.tags) == 3 assert article.tags[0].uri == 'electro' assert article.tags[0].name == 'Electro' assert article.tags[1].uri == 'funk' assert article.tags[1].name == 'Funk' assert article.tags[2].uri == 'house' assert article.tags[2].name == 'House'
async def test_insert_category_later(self, answers, db, prompt, source_file): source_file.move('blog/2019/03-07.insert_category.html') category = CategoryFactory() article = ArticleFactory(uri='insert_category', category=category) handler = self.handler(source_file, prompt=prompt) await handler.insert_category(later=True) assert article.category is category prompt.answer_quiz() assert article.category is not category assert article.category.uri == 'music' assert article.category.name == 'Music'
async def test_update_document(self, answers, db, prompt, source_file): original = ArticleFactory( uri='update', title="To Update", lead="To be updated.", body="Please update me!", ) assert original.last_update is None source_file.move('blog/2019/01-31.update.html') updated = await self.handler(source_file, prompt=prompt).update() assert updated is original assert updated.uri == 'update' assert updated.last_update == date.today() self.assert_article_has_been_saved(updated)
async def test_rename_document(self, answers, db, prompt, source_file): original = ArticleFactory( uri='rename', title="To Rename", lead="To be renamed.", body="Please rename me!", ) assert original.last_update is None source_file.move('blog/2019/01-31.rename.html') new_path = source_file.symlink('blog/2019/01-31.new_name.html') handler = self.handler(source_file, prompt=prompt) renamed = await handler.rename(new_path) assert renamed is original assert renamed.uri == 'new_name' assert renamed.last_update == date.today() self.assert_article_has_been_saved(renamed)
async def test_insert_tags_that_do_not_all_exist( self, answers, db, prompt, source_file): source_file.move('blog/2019/03-06.insert_tags.html') article = ArticleFactory(uri='insert_tags') existing = TagFactory(uri='funk', name='Funky') handler = self.handler(source_file, prompt=prompt) await handler.insert_tags() assert len(article.tags) == 3 assert article.tags[0].uri == 'electro' assert article.tags[0].name == 'Electro' assert article.tags[2].uri == 'house' assert article.tags[2].name == 'House' # Let's be sure that attributes of the existing tag have not changed. assert article.tags[1] is existing assert article.tags[1].uri == 'funk' assert article.tags[1].name == 'Funky'
async def test_insert_existing_tags(self, db, source_file): source_file.move('blog/2019/03-06.insert_tags.html') article = ArticleFactory(uri='insert_tags') expected = [ TagFactory(uri='electro', name='Electrico'), TagFactory(uri='funk', name='Funky'), TagFactory(uri='house', name='Maison'), ] await self.handler(source_file).insert_tags() # Let's be sure that attributes have not changed. assert len(article.tags) == len(expected) assert article.tags[0].uri == 'electro' assert article.tags[0].name == 'Electrico' assert article.tags[1].uri == 'funk' assert article.tags[1].name == 'Funky' assert article.tags[2].uri == 'house' assert article.tags[2].name == 'Maison'
async def test_insert_already_existing_document(self, db, source_file): ArticleFactory(uri='existing') source_file.move('blog/2019/01-31.existing.html') with pytest.raises(exceptions.ItemAlreadyExisting): await self.handler(source_file).insert()