def test_month_full_name(self): ''' This test that we gat the correct month for long month name ''' valid_from = "Valid From May 09 - August 25" self.assertEqual( [date(2014, 05, 9), date(2014, 8, 25)], deal_valid(valid_from))
def test_valid_from(self): ''' Testing the case of Valid from "month day - month day" ''' valid_from = "Valid from May 09 - May 15" self.assertEqual( [date(2014, 05, 9), date(2014, 05, 15)], deal_valid(valid_from))
def test_deal_expires_in(self): ''' Testing the case of Valid from "Deal expires in 5 days" ''' my_date = date.today() + timedelta(5) valid_from = "Deal expires in 5 days." self.assertEqual([None, my_date], deal_valid(valid_from))
def parse_product(self, response): ''' Parse_product get the data from the parse_deals_links and extract the data that we need. ''' sel = Selector(response) data = StopandshopItem() data['store_location'] = response.request.meta['store_location'] data['store_name'] = 'Stop and Shop' product = sel.xpath('//article[@class="sl_detail_left clearfix"]') data['product_name'] = product.xpath('//h1[@class="sl_detail_title"\ ]/text()').extract()[0].strip() data['discount_price'] = product.xpath( '//div[@class="sl_detail_dealdesc"]/text()').extract()[0].strip() picture = product.xpath('//img[@class="sl_detail_image"]/@src')\ .extract() if len(picture) > 0: data['product_picture'] = picture[0].strip() else: data['product_picture'] = None [data['start_date'], data['end_date']] = deal_valid( product.xpath('//div[@class="sl_detail_dates"]/text()').extract() [0].strip()) description = product.xpath('//div[@class="sl_detail_description"\ ]/text()').extract() if len(description) > 0: data['description'] = description[0].strip() else: data['description'] = None notes = product.xpath('//div[@class="sl_detail_price_qualifier"\ ]/text()').extract() if len(notes) > 0: data['notes'] = notes[0].strip() else: data['notes'] = None return data
def test_no_date_deal_expiration(self): ''' Testeing if non o the option is there. ''' valid_from = "Some day" self.assertRaises(TypeError, lambda: deal_valid(valid_from))
def test_deal_expires(self): ''' Testing the case of Valid from "Deal expires today" ''' valid_from = "Deal expires today." self.assertEqual([None, date.today()], deal_valid(valid_from))