示例#1
0
 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)
示例#2
0
 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 €')
示例#3
0
 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\'}')
示例#4
0
 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
示例#5
0
文件: __init__.py 项目: SamR1/lbc2rss
    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
示例#6
0
 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
示例#7
0
 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')
示例#8
0
 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
示例#9
0
 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')
示例#10
0
 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/')