[weboob] [PATCH 1/1] adding tests for leboncoin modules

Benjamin CARTON carton_ben at yahoo.fr
Wed Apr 15 09:25:27 CEST 2015

>>here you have a page with no announce.

Hum that's funny, using ret > 10 we've got adverts :

     Le Mardi 14 avril 2015 23h23, Laurent George <laurent.f.george at gmail.com> a écrit :


2015-04-08 9:29 GMT+02:00 Benjamin CARTON <carton_ben at yahoo.fr>:

I have got few questions about your patch.

First of all why do you test if there is a minimum number of results ?

We can test if there are results or not but i cannot understand the advantage of testing the number of results.
I agree with you here just testing if there is a result is sufficient here.

Secondly, testing  each type of announce (RENT/SALE)  is a good idea because url are not the same, but testing each type of house is, to my mind, useless. 

I had some problems with parking for instance that didn't works some time ago.. but I can't remember if it was on leboncoin or seloger. So I think it doesn't cost a lot to check for each type of  house if we have a result (but if you think it's not relevant, I will not fight for it, and I can redo a commit if you want).

I did not had a look at it but does the query fail on leboncoin website if the form is sent with a random number in type of house value or does it return the result of the research ignoring this part of the form ? 
you mean  using 9 for example for the house_type like : 


here you have a page with no announce.



 S'il vous plaît, évitez de m'envoyer des pièces jointes au format Word, PowerPoint ou Excel.
Voir http://www.gnu.org/philosophy/no-word-attachments.fr.html 

     Le Samedi 4 avril 2015 0h04, lgeorge <laurent.f.george at gmail.com> a écrit :

 We check for each type of announce (RENT/SALE) if there is a minimum
number of results for each type of house except for unknown type wich
does not work well with leboncoin (I guess)

Signed-off-by: lgeorge <laurent.george at srand.fr>
 modules/leboncoin/test.py | 47 +++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 41 insertions(+), 6 deletions(-)

diff --git a/modules/leboncoin/test.py b/modules/leboncoin/test.py
index e24fc11..a9e1bfd 100644
--- a/modules/leboncoin/test.py
+++ b/modules/leboncoin/test.py
@@ -25,15 +25,50 @@ from weboob.capabilities.housing import Query
 class LeboncoinTest(BackendTest):
    MODULE = 'leboncoin'
-    def test_leboncoin(self):
-        query = Query()
-        query.cities = []
+    def setUp(self):
+        self.query = Query()
+        self.query.cities = []
        for city in self.backend.search_city('lille'):
            city.backend = self.backend.name
-            query.cities.append(city)
+            self.query.cities.append(city)
+    def check_search_return_minimum_number_of_results(self, max_requested_results=20, min_results=1):
+        """
+        Check if we get a mininum number of results for a query
+        :param max_requested_results:
+        :param min_results: expected number of results (should be bellow max_requested_results)
+        """
+        results = list(itertools.islice(self.backend.search_housings(self.query), 0, max_requested_results))
+        n_results = len(results)
+        self.assertTrue( n_results > min_results,
+                        'Number of results ({}) for {} is bellow minimum ({})'.format(
+                            n_results,  self.query.house_types, min_results))
+        return results
+    def check_all_house_type(self, request_type=0):
+        """
+        Test rent for all house_type except Unknown
+        For all this we loop over possible types of query and possible type of house, as there is no parameterized test
+        in weboob (we require thing like : http://feldboris.alwaysdata.net/blog/unittest-template.html) for now
+        if a test fail other are not ran
-        results = list(itertools.islice(self.backend.search_housings(query), 0, 20))
-        self.assertTrue(len(results) > 0)
+        :param request_type: 0 for TYPE_RENT, and 1 for TYPE_SALE
+        """
+        for house_type in self.query.HOUSE_TYPES.values:
+            if 'Unknown' in house_type:
+                continue
+            self.query.type = request_type
+            self.query.house_types = [house_type]
+            self.check_search_return_minimum_number_of_results()
+    def test_leboncoin_rent(self):
+        self.check_all_house_type(self.query.TYPE_RENT)
+    def test_leboncoin_sale(self):
+        self.check_all_house_type(self.query.TYPE_SALE)
+    def test_leboncoin(self):
+        results = self.check_search_return_minimum_number_of_results()
        obj = self.backend.fillobj(results[0])
        self.assertTrue(obj.area is not None, 'Area for "%s"' % (obj.id))

weboob mailing list
weboob at lists.symlink.me


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.symlink.me/pipermail/weboob/attachments/20150415/cc472ae8/attachment-0001.html>

More information about the weboob mailing list