class TestSaholicGrabber(unittest.TestCase): def setUp(self): self.grabber = SaholicGrabber({ "url" : "http://localhost/page", "parser" : SaholicInventory, "crawler" : SaholicCrawler, "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_saholic.html", "r").read() test_data = str(bsoup(test).fetch('div', 'productItem')[0]) 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())
def setUp(self): self.grabber = SaholicGrabber({ "url" : "http://localhost/page", "parser" : SaholicInventory, "crawler" : SaholicCrawler, "dbname" : "GrabberTest", "dbhost" : "localhost", "source" : "IBEAM" }) self.grabber.db.pages.drop() self.grabber.db.inventory.drop()