Пример #1
0
 def setUp(self):
     self.grabber = InfibeamGrabber({
             "url" : "http://localhost/page",
             "parser" : InfibeamInventory,
             "crawler" : InfibeamCrawler,
             "dbname" : "GrabberTest",
             "dbhost" : "localhost",
             "source" : "IBEAM"
             })
     self.grabber.db.pages.drop()
     self.grabber.db.inventory.drop()
Пример #2
0
class TestInfibeamGrabber(unittest.TestCase):

    def setUp(self):
        self.grabber = InfibeamGrabber({
                "url" : "http://localhost/page",
                "parser" : InfibeamInventory,
                "crawler" : InfibeamCrawler,
                "dbname" : "GrabberTest",
                "dbhost" : "localhost",
                "source" : "IBEAM"
                })
        self.grabber.db.pages.drop()
        self.grabber.db.inventory.drop()
        
    def tearDown(self):
        self.grabber.db.pages.drop()
        self.grabber.db.inventory.drop()
    
    @staticmethod
    def FakeResponse(a):
        test = file("backend/test/data/inventory/test_20120310_055847_infibeam.html", "r").read()
        test_data = str(bsoup(test).fetch('ul', 'srch_result portrait')[0].fetch('li')[0])

        #monkey patching test-data to get the correct minimal test-data 
        test_data = str("<ul class='srch_result portrait'>" + test_data + "</ul>")
        return '200 OK', test_data        
    
    @patch.object(Http, 'request', FakeResponse)
    def test_inventory_grab(self):
        # kick inventory grabber.
        self.grabber.grab()
        
        #assert inventory insertion
        self.assertEquals(1, self.grabber.db.inventory.count())

        #assert page insertion
        self.assertEquals(1, self.grabber.db.pages.count())