def test_login_passwd(self): config = configparser.ConfigParser() config.read('test.ini') del(config['login']['passwd']) with open('test.ini', 'w') as config_file: config.write(config_file) with self.assertRaises(KeyError): spider = ruliweb_spiders.RuliwebSpider(name = 'test', ini_file = 'test.ini')
def test_file_article_urls_empty(self): config = configparser.ConfigParser() config.read('test.ini') config['crawl']['article_urls'] = '' with open('test.ini', 'w') as config_file: config.write(config_file) with self.assertRaises(AttributeError): spider = ruliweb_spiders.RuliwebSpider(name = 'test', ini_file = 'test.ini')
def test_login_id_empty(self): config = configparser.ConfigParser() config.read('test.ini') config['login']['id'] = '' with open('test.ini', 'w') as config_file: config.write(config_file) with self.assertRaises(AttributeError): spider = ruliweb_spiders.RuliwebSpider(name = 'test', ini_file = 'test.ini')
def test_file_page_number_re(self): config = configparser.ConfigParser() config.read('test.ini') del(config['crawl']['page_number_re']) with open('test.ini', 'w') as config_file: config.write(config_file) with self.assertRaises(KeyError): spider = ruliweb_spiders.RuliwebSpider(name = 'test', ini_file = 'test.ini')
def test_file_output_location(self): config = configparser.ConfigParser() config.read('test.ini') del(config['file']['output_location']) with open('test.ini', 'w') as config_file: config.write(config_file) with self.assertRaises(KeyError): spider = ruliweb_spiders.RuliwebSpider(name = 'test', ini_file = 'test.ini')
def test_debug(self): # debug config = configparser.ConfigParser() config.read('test.ini') del(config['debug']) with open('test.ini', 'w') as config_file: config.write(config_file) with self.assertRaises(KeyError): spider = ruliweb_spiders.RuliwebSpider(name = 'test', ini_file = 'test.ini')
def test_ini(self): with self.assertRaises(OSError): spider = ruliweb_spiders.RuliwebSpider(ini_file = 'dumy.ini')
def test_start_spider(self): mock_response = scrapy.http.Response(url='https://bbs.ruliweb.com') spider = ruliweb_spiders.RuliwebSpider(name='test') with self.assertRaises(Exception): spider.start_spider(mock_response)