def test_worker_parsing_next_page(self): worker = BasicUserParseWorker("https://www.reddit.com/user/Chrikelnel") file_path = '%s/%s' % (os.path.dirname(os.path.realpath(__file__)), 'test_resources/sample_GET_response.html') with codecs.open(file_path, encoding='utf-8') as f: text = f.read() results, next_page = worker.parse_text( str(text).strip().replace('\r\n', '')) self.assertIsNotNone(next_page) self.assertGreater(len(next_page), 0)
def test_worker_add_results components(self): #test if all three are properly added to results worker = BasicUserParseWorker("https://www.reddit.com/user/Chrikelnel") file_path = '%s/%s' % (os.path.dirname(os.path.realpath(__file__)), 'test_resources/sample_GET_response.html') with codecs.open(file_path, encoding='utf-8') as f: text = f.read() results, next_page = worker.parse_text(str(text).strip().replace('\r\n', '')) self.assertGreater(len(results[0]), 0) self.assertGreater(len(results[1]), 0) self.assertGreater(len(results[2]), 0)
def test_worker_parsing(self): """ Purpose: Test regular parsing mechanisms of worker Expectation: Load html file, send it to worker to parse, should return list of results :return: """ worker = BasicUserParseWorker("https://www.reddit.com/user/Chrikelnel") file_path = '%s/%s' % (os.path.dirname(os.path.realpath(__file__)), 'test_resources/sample_GET_response.html') with codecs.open(file_path, encoding='utf-8') as f: text = f.read() results, next_page = worker.parse_text(str(text).strip().replace('\r\n', '')) self.assertGreater(len(results), 0) # Check that results are returned self.assertEqual(len(results[0]), 3) # Check that results are in triplets (check formatting)
def test_worker_parsing_results_not_empty(self): worker = BasicUserParseWorker("https://www.reddit.com/user/Chrikelnel") file_path = '%s/%s' % (os.path.dirname(os.path.realpath(__file__)), 'test_resources/sample_GET_response.html') with codecs.open(file_path, encoding='utf-8') as f: text = f.read() results, next_page = worker.parse_text( str(text).strip().replace('\r\n', '')) self.assertIsNotNone( results) # Check if results were created and returned self.assertTrue( len(results) > 0) # Check if number of results is positive self.assertIs(type(results), type([])) # Check if results is a list self.assertNotEqual(results[0], ()) # Check if results value is not an empty tuple