def test_parser_parse(amocker, property_factory): parsed_property = property_factory() tag = amocker.Mock() parser = parsers.Parser() parser.get_items = amocker.Mock(return_value=[tag]) parser.build_property = amocker.Mock(return_value=parsed_property) assert parser.parse('') == [parsed_property] assert parser.get_items.called assert parser.build_property.called
def test_parser_build_absolute_url(amocker): base_url = 'https://www.bazaraki.com' path = '/adv/2206100_panthea-near-grammar-school/' expected = f'{base_url}{path}' parser = parsers.Parser() parser.get_base_url = amocker.Mock(return_value=base_url) with amocker.patch('urllib.parse.urljoin', return_value=expected) as urljoin_mock: assert parser.build_absolute_url(path) == expected assert parser.get_base_url.called assert parser.get_base_url.call_args == amocker.call() assert urljoin_mock.called assert urljoin_mock.call_args == amocker.call(base_url, path)
def test_parser_build_property(amocker, property_factory): item = amocker.Mock() expected_property = property_factory() parser = parsers.Parser() parser.get_item_title = amocker.Mock(return_value=expected_property.title) parser.get_item_url = amocker.Mock(return_value=expected_property.url) parser.get_item_price = amocker.Mock(return_value=expected_property.price) parser.get_item_created_at = amocker.Mock(return_value=expected_property.created_at) parser.build_absolute_url = amocker.Mock(return_value=expected_property.url) assert parser.build_property(item) == expected_property assert parser.get_item_title.called assert parser.get_item_url.called assert parser.get_item_price.called assert parser.get_item_created_at.called assert parser.build_absolute_url.called
def test_parser_get_item_created_at_raises_not_implemented(amocker): parser = parsers.Parser() with pytest.raises(NotImplementedError): item = amocker.Mock() parser.get_item_created_at(item)
def test_parser_get_items_raises_not_implemented(amocker): parser = parsers.Parser() with pytest.raises(NotImplementedError): soup = amocker.Mock() parser.get_items(soup)
def test_parser_get_base_url_raises_not_implemented(): parser = parsers.Parser() with pytest.raises(NotImplementedError): parser.get_base_url()