def it_returns_selected_article_summary(self, client, sample_article, db_session): article_1 = create_article(title='test 1') create_article(title='test 2') article_ids = "{},{}".format(sample_article.id, article_1.id) response = client.get( url_for('articles.get_articles_summary', ids=article_ids), headers=[create_authorization_header()] ) assert response.status_code == 200 data = json.loads(response.get_data(as_text=True)) assert len(data) == 2 assert set([str(sample_article.id), str(article_1.id)]) == set(article_ids.split(','))
def it_returns_up_to_4_articles_summary(self, client, sample_article, db_session): create_article(title='test 1') create_article(title='test 2') create_article(title='test 3') create_article(title='test 4') create_article(title='test 5') response = client.get( url_for('articles.get_articles_summary'), headers=[create_authorization_header()] ) assert response.status_code == 200 data = json.loads(response.get_data(as_text=True)) assert len(data) == 5
def it_creates_a_article(self, db_session): article = create_article() assert Article.query.count() == 1 article_from_db = Article.query.filter(Article.id == Article.id).first() assert article == article_from_db
def it_removes_html_tags_on_article_summary(self, db_session): long_content_with_tags = '<h1>' clean_long_content = '' clean_very_short_content_length = 0 clean_short_content_length = 0 for i in range(120): long_content_with_tags += '{}<div>text</div> '.format(i) clean_long_content += '{}text '.format(i) if i == 30: clean_very_short_content_length = len(clean_long_content) - 1 if i == 110: clean_short_content_length = len(clean_long_content) - 1 article = create_article(content=long_content_with_tags) assert article.serialize_summary() == { 'id': str(article.id), 'author': article.author, 'title': article.title, 'short_content': clean_long_content[:clean_short_content_length] + '...', 'very_short_content': clean_long_content[:clean_very_short_content_length] + '...', }
def it_shows_article_summary_json_on_serialize(self, db, db_session): article = create_article() assert article.serialize_summary() == { 'id': str(article.id), 'author': article.author, 'title': article.title, 'short_content': article.content, 'very_short_content': article.content, }
def it_shows_shortened_content_article_summary_json_on_serialize_long_content( self, db_session): long_content = '' short_content_length = 0 very_short_content_length = 0 for i in range(120): long_content += '{}some-text '.format(i) if i == 30: very_short_content_length = len(long_content) - 1 if i == 110: short_content_length = len(long_content) - 1 article = create_article(content=long_content) assert article.serialize_summary() == { 'id': str(article.id), 'author': article.author, 'title': article.title, 'short_content': long_content[:short_content_length] + '...', 'very_short_content': long_content[:very_short_content_length] + '...' }
def it_gets_a_article_by_id(self, db, db_session, sample_article): article = create_article() fetched_article = dao_get_article_by_id(article.id) assert fetched_article == article
def it_gets_all_articles(self, db, db_session, sample_article): articles = [create_article(), sample_article] articles_from_db = dao_get_articles() assert Article.query.count() == 2 assert set(articles) == set(articles_from_db)
def sample_article(db): return create_article(title='Ancient Greece')