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

lgeorge laurent.f.george at gmail.com
Sat Apr 4 00:04:13 CEST 2015


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))
-- 
2.1.4




More information about the weboob mailing list