def test_feed_entry_date_is_ad_publication_date(self) -> None: ad_result = SearchResult() feed = generate_ads_feed('locations', get_results([ad_result]), {}) parsed = feedparser.parse(feed) entry = parsed.entries[0] assert (ad_result.publication_date.strftime('%a, %d %b %Y %H:%M:%S') in entry.updated)
def test_feed_entry_title_is_ad_title(self) -> None: ad_result = SearchResult() feed = generate_ads_feed('locations', get_results([ad_result]), {}) parsed = feedparser.parse(feed) entry = parsed.entries[0] assert entry.title == ( 'Appartement - Lyon, 69000 - Studio 30m2 - 430 €')
def test_feed_description_with_params_is_returned(self) -> None: feed = generate_ads_feed('locations', get_results([]), {"cities": "Lyon|69000"}) parsed = feedparser.parse(feed) assert parsed['feed']['description'] == ( 'Résultat de la recherche des offres "locations" sur Leboncoin' ', paramètres : {\'cities\': \'Lyon|69000\'}')
def test_feed_with_10_entries_is_returned(self) -> None: feed = generate_ads_feed( 'locations', get_results([SearchResult()] * 10), {"cities": "Lyon|69000"}, ) parsed = feedparser.parse(feed) assert len(parsed.entries) == 10
def ads_feed(category: str) -> Tuple[str, int]: try: query = LBCQuery(category=category) except InvalidCategory: return 'Invalid category.', 404 try: params = dict(request.args.copy()) query.add_search_parameters(params) except InvalidParameters as error_message: return str(error_message), 400 results = query.get_results() return generate_ads_feed(category, results, params), 200
def test_feed_entry_summary_is_formatted_ad(self) -> None: ad_result = SearchResult() feed = generate_ads_feed('locations', get_results([ad_result]), {}) parsed = feedparser.parse(feed) entry = parsed.entries[0] assert entry.summary == FORMATTED_ITEM
def test_feed_title_is_returned(self) -> None: feed = generate_ads_feed('locations', get_results([]), {}) parsed = feedparser.parse(feed) assert (parsed['feed']['title'] == 'Recherche des offres "locations" sur Leboncoin')
def test_feed_entry_link_is_ad_url(self) -> None: ad_result = SearchResult() feed = generate_ads_feed('locations', get_results([ad_result]), {}) parsed = feedparser.parse(feed) entry = parsed.entries[0] assert entry.link == ad_result.url
def test_feed_description_is_returned(self) -> None: feed = generate_ads_feed('locations', get_results([]), {}) parsed = feedparser.parse(feed) assert ( parsed['feed']['description'] == 'Résultat de la recherche des offres "locations" sur Leboncoin')
def test_feed_link_is_returned(self) -> None: feed = generate_ads_feed('locations', get_results([]), {}) parsed = feedparser.parse(feed) assert (parsed['feed']['link'] == 'https://www.leboncoin.fr/annonces/offres/')