AnthonyBloomer / daftlistings

A library that enables programmatic interaction with daft.ie. Daft.ie has nationwide coverage and contains about 80% of the total available properties in Ireland.
MIT License
171 stars 54 forks source link

Facilities filtering #122

Closed EricNeville closed 3 years ago

EricNeville commented 3 years ago

Added ability to filter searches by facilities. Compared to other filters already included, the available facilities for search are heavily dependent on the SearchType. As a result there are checks for SearchType being set before facilities as well as compatibility of Facility with SearchType. This closes #121. For example:

from daftlistings.daft import Daft
from daftlistings.enums import SearchType, PropertyType, Facility
from daftlistings.location import Location

daft = Daft()
daft.set_location(Location.IFSC_DUBLIN)
daft.set_property_type(PropertyType.APARTMENT)
daft.set_facility(Facility.PARKING)
daft.set_search_type(SearchType.RESIDENTIAL_RENT)

listings = daft.search()

returns output:

ValueError: SearchType must be set before Facility

and:

from daftlistings.daft import Daft
from daftlistings.enums import SearchType, PropertyType, Facility
from daftlistings.location import Location

daft = Daft()
daft.set_search_type(SearchType.RESIDENTIAL_RENT)
daft.set_location(Location.IFSC_DUBLIN)
daft.set_property_type(PropertyType.APARTMENT)
daft.set_facility(Facility.TOILETS)

listings = daft.search()

returns output:

ValueError: Facility TOILETS incompatible with SearchType RESIDENTIAL_RENT
The following facilities are compatible with this SearchType:
['ALARM', 'PARKING', 'WHEELCHAIR_ACCESS', 'CABLE_TELEVISION', 'DISHWASHER', 'GARDEN_PATIO_BALCONY', 'CENTRAL_HEATING', 'INTERNET', 'MICROWAVE', 'PETS_ALLOWED', 'SMOKING', 'SERVICED_PROPERTY', 'DRYER', 'WASHING_MACHINE']

An example of searching for facilities is also included in the examples folder and the README.

codecov[bot] commented 3 years ago

Codecov Report

Merging #122 (e5c9dea) into dev (bf730db) will decrease coverage by 0.20%. The diff coverage is 80.76%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #122      +/-   ##
==========================================
- Coverage   98.56%   98.36%   -0.21%     
==========================================
  Files           6        6              
  Lines        4545     4597      +52     
==========================================
+ Hits         4480     4522      +42     
- Misses         65       75      +10     
Impacted Files Coverage Δ
daftlistings/daft.py 81.06% <50.00%> (-4.17%) :arrow_down:
daftlistings/enums.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update bf730db...e5c9dea. Read the comment docs.

EricNeville commented 3 years ago

For testing, I can't just add a facility filter to the current search test because the search there is of SearchType New Homes and that type has no facilities. If it is okay to change that to a different search then I can do so.

AnthonyBloomer commented 3 years ago

Great work, thanks @EricNeville! To get some test coverage for this PR, you could update test_search, change the search type and add your set_facility method. You'll need to also update the expected payload.

EricNeville commented 3 years ago

Sounds good, doing that now. I just wanted to make sure it's okay to change that. I'm not too familiar with these tests so am I right in thinking I just need to change the search type to say RESIDENTIAL_SALE and add my facility filter in the Daft object, and then reflect these two changes in the expected payload i.e changing section and adding andFilters accordingly?

AnthonyBloomer commented 3 years ago

Exactly, that sounds good. The test just ensures that when the Daft class methods are set the payload is constructured properly.