class TestAdd(unittest.TestCase): def setUp(self): # create a sample file with an entry with open('test-history', 'w') as f: f.write('4510309329\n') self.cl = Craigslist(location='raleigh', history='test-history') self.posts = [ Post('4510309329', 'Lego Star Wars', '', ''), Post('4510309330', 'Lego R2-D2', '', ''), Post('4510309331', 'Megablocks for sell', '', '') ] def test_filter_old(self): '''Verify old posts are filtered out''' new_posts = self.posts[1:] # don't include first item self.assertEqual(self.cl.filter_old(self.posts), new_posts) def test_filter_blacklist(self): '''Verify a post that contains certain words is filtered out''' filtered_posts = self.posts[:-1] # don't include last item self.assertEqual(self.cl.filter_blacklist(self.posts), filtered_posts) def test_history(self): '''Verify non-blacklist items are written to history file''' self.cl.save_history(self.cl.filter_blacklist(self.posts)) with open(self.cl.history_filename) as f: content = [] for line in f.readlines(): content.append(line.strip()) self.assertEqual(content, ['4510309329', '4510309330'])
class TestAdd(unittest.TestCase): def setUp(self): # create a sample file with an entry with open('test-history', 'w') as f: f.write('4510309329\n') self.cl = Craigslist(location='raleigh', history='test-history') self.posts = [Post('4510309329', 'Lego Star Wars', '', ''), Post('4510309330', 'Lego R2-D2', '', ''), Post('4510309331', 'Megablocks for sell', '', '')] def test_filter_old(self): '''Verify old posts are filtered out''' new_posts = self.posts[1:] # don't include first item self.assertEqual(self.cl.filter_old(self.posts), new_posts) def test_filter_blacklist(self): '''Verify a post that contains certain words is filtered out''' filtered_posts = self.posts[:-1] # don't include last item self.assertEqual(self.cl.filter_blacklist(self.posts), filtered_posts) def test_history(self): '''Verify non-blacklist items are written to history file''' self.cl.save_history(self.cl.filter_blacklist(self.posts)) with open(self.cl.history_filename) as f: content = [] for line in f.readlines(): content.append(line.strip()) self.assertEqual(content, ['4510309329', '4510309330'])
def setUp(self): # create a sample file with an entry with open('test-history', 'w') as f: f.write('4510309329\n') self.cl = Craigslist(location='raleigh', history='test-history') self.posts = [ Post('4510309329', 'Lego Star Wars', '', ''), Post('4510309330', 'Lego R2-D2', '', ''), Post('4510309331', 'Megablocks for sell', '', '') ]
class TestQuery(unittest.TestCase): def setUp(self): self.cl = Craigslist(location='raleigh') def test_basic_query(self): ''' Verify query formation with a single word''' self.assertEqual(self.cl.form_query(['lego'], category='taa'), 'http://raleigh.craigslist.org/search/taa?query=lego') def test_advanced_query(self): ''' Verify query formation with more than one word''' self.assertEqual(self.cl.form_query(['lego', '10225'], category='taa'), 'http://raleigh.craigslist.org/search/taa?query=lego+10225')
class TestQuery(unittest.TestCase): def setUp(self): self.cl = Craigslist(location='raleigh') def test_basic_query(self): ''' Verify query formation with a single word''' self.assertEqual( self.cl.form_query(['lego'], category='taa'), 'http://raleigh.craigslist.org/search/taa?query=lego') def test_advanced_query(self): ''' Verify query formation with more than one word''' self.assertEqual( self.cl.form_query(['lego', '10225'], category='taa'), 'http://raleigh.craigslist.org/search/taa?query=lego+10225')
def setUp(self): # create a sample file with an entry with open('test-history', 'w') as f: f.write('4510309329\n') self.cl = Craigslist(location='raleigh', history='test-history') self.posts = [Post('4510309329', 'Lego Star Wars', '', ''), Post('4510309330', 'Lego R2-D2', '', ''), Post('4510309331', 'Megablocks for sell', '', '')]
def setUp(self, page_mock): cl = Craigslist(location='raleigh') self.post = cl.parse_post('http://raleigh.craigslist.org/tag/4510309330.html')
def setUp(self): with open(os.path.join(tests_dir, 'sample-no-results.html'), 'rb') as f: no_results = f.read() cl = Craigslist(location='raleigh') self.posts = cl.parse_search_results(no_results)
def setUp(self): self.cl = Craigslist(location='raleigh')
def setUp(self, page_mock): cl = Craigslist(location='raleigh') self.post = cl.parse_post( 'http://raleigh.craigslist.org/tag/4510309330.html')