fix(parsers): устойчивость trade-страниц к пустым подкатегориям и парсинг chips#105
Open
Flummy1 wants to merge 1 commit into
Open
fix(parsers): устойчивость trade-страниц к пустым подкатегориям и парсинг chips#105Flummy1 wants to merge 1 commit into
Flummy1 wants to merge 1 commit into
Conversation
MyOffersPageParser and MyChipsPageParser crashed on subcategories with no offers: FunPay renders /lots|/chips/<id>/trade without div.showcase-table (offers) or form.form-ajax-simple (chips), so table.html / form.html raised AttributeError and surfaced as ParsingError. MyChipsPageParser additionally never worked for non-empty subcategories: it feeds the bare <form> HTML to OfferFieldsParser, which only looked for 'div.page-content > form' and raised IndexError on the missing wrapper. Changes: - MyOffersPageParser: guard header/body/content-lots/showcase-table; a missing table is treated as zero offers. - MyChipsPageParser: guard header/body/form; a missing form yields empty fields. - OfferFieldsParser: fall back from 'div.page-content > form' to a plain 'form' lookup, and return empty OfferFields when there is no form. - PageHeaderParser / AppDataParser: return empty objects on a missing header / empty app-data instead of raising (makes the header/body guards meaningful and hardens all page parsers). - Add regression tests for both trade page parsers and the empty-source behavior of the affected leaf parsers.
8a3b763 to
112c7aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема
MyOffersPageParserиMyChipsPageParserпадают сParsingError, когда упродавца нет предложений в подкатегории — это штатное состояние страницы.
/lots/<id>/tradeбезdiv.showcase-table. Парсер обращался кtable.htmlнаNone→AttributeError→ParsingError.form.form-ajax-simple→form.htmlнаNone→ та же ошибка.Дополнительно
MyChipsPageParserне работал ни для какой категории (даженепустой): он передаёт в
OfferFieldsParserHTML голой<form>, а тот искалтолько
div.page-content > formи падал сIndexErrorна отсутствующей обёртке.Изменения
MyOffersPageParser— guard дляheader/body/div.content-lots/div.showcase-table. Отсутствие таблицы трактуется как «ноль офферов»(
MyOffersPage(offers={})).MyChipsPageParser— guard дляheader/body/form. Отсутствие формыдаёт пустые
OfferFields.OfferFieldsParser— fallback сdiv.page-content > formна обычныйform(парсит и голую форму из chips-парсера) и возврат пустыхOfferFields,когда формы нет. Поведение на
offerEdit-странице не меняется.PageHeaderParser/AppDataParser— возвращают пустые объекты приотсутствии
<header>/ пустомdata-app-dataвместо падения.Тесты
Регрессионные тесты (раньше у trade page-парсеров их не было):
my_offers_page_parser_test.py— пустая категория, категория с оффером,не-trade страница.
my_chips_page_parser_test.py— пустая категория, непустая категория,не-trade страница.
page_header_parser_test.py— пустой/отсутствующий header.appdata_parser_test.py— пустойdata-app-data+ валидный.offer_fields_parser_extras_test.py— устойчивостьOfferFieldsParser(пустой ввод, ввод без формы, голая
<form>).Test plan
pytest --doctest-modules— 486 passed.force-push, дождаться зелёного статуса.
MyOffersPage(offers={})безParsingError; непустая → офферы парсятся;chips-категория → поля парсятся.