def test_search_fields(self): """Test whether the search_fields is properly set""" question_api_1 = read_file('data/askbot/askbot_api_questions.json') question_api_2 = read_file('data/askbot/askbot_api_questions_2.json') question_html_1 = read_file('data/askbot/askbot_question.html') question_html_2 = read_file( 'data/askbot/askbot_question_multipage_1.html') question_html_2_2 = read_file( 'data/askbot/askbot_question_multipage_2.html') comments = read_file('data/askbot/askbot_2481_multicomments.json') httpretty.register_uri(httpretty.GET, ASKBOT_QUESTIONS_API_URL, body=question_api_1, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTIONS_API_URL, body=question_api_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2481_URL, body=question_html_1, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2488_URL, body=question_html_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2488_URL, body=question_html_2_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_COMMENTS_API_URL, body=comments, status=200) backend = Askbot(ASKBOT_URL) questions = [question for question in backend.fetch()] question = questions[0] self.assertEqual(backend.metadata_id(question['data']), question['search_fields']['item_id']) self.assertListEqual(question['data']['tags'], ['askbot-sites']) self.assertEqual(question['data']['tags'], question['search_fields']['tags']) question = questions[1] self.assertEqual(backend.metadata_id(question['data']), question['search_fields']['item_id']) self.assertListEqual(question['data']['tags'], ['feature-request', 'messaging']) self.assertEqual(question['data']['tags'], question['search_fields']['tags'])
def test_fetch_from_date(self): """Test whether a list of questions is returned from a given date.""" question_api_1 = read_file('data/askbot/askbot_api_questions.json') question_api_2 = read_file('data/askbot/askbot_api_questions_2.json') question_html_1 = read_file('data/askbot/askbot_question.html') question_html_2 = read_file( 'data/askbot/askbot_question_multipage_1.html') question_html_2_2 = read_file( 'data/askbot/askbot_question_multipage_2.html') comments = read_file('data/askbot/askbot_2481_multicomments.json') httpretty.register_uri(httpretty.GET, ASKBOT_QUESTIONS_API_URL, body=question_api_1, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTIONS_API_URL, body=question_api_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2481_URL, body=question_html_1, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2488_URL, body=question_html_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2488_URL, body=question_html_2_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_COMMENTS_API_URL, body=comments, status=200) backend = Askbot(ASKBOT_URL) from_date = datetime.datetime(2013, 1, 1) questions = [ question for question in backend.fetch(from_date=from_date) ] self.assertEqual(questions[0]['tag'], 'http://example.com') self.assertEqual(questions[0]['uuid'], '3fb5f945a0dd223c60218a98ad35bad6043f9f5f') self.assertEqual(questions[0]['updated_on'], 1408116902.0) self.assertEqual(questions[0]['data']['id'], 2488) self.assertEqual(len(questions), 1)
def test_fetch(self): """Test whether a list of questions is returned""" question_api_1 = read_file('data/askbot/askbot_api_questions.json') question_api_2 = read_file('data/askbot/askbot_api_questions_2.json') question_html_1 = read_file('data/askbot/askbot_question.html') question_html_2 = read_file('data/askbot/askbot_question_multipage_1.html') question_html_2_2 = read_file('data/askbot/askbot_question_multipage_2.html') comments = read_file('data/askbot/askbot_2481_multicomments.json') httpretty.register_uri(httpretty.GET, ASKBOT_QUESTIONS_API_URL, body=question_api_1, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTIONS_API_URL, body=question_api_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2481_URL, body=question_html_1, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2488_URL, body=question_html_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2488_URL, body=question_html_2_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_COMMENTS_API_URL, body=comments, status=200) backend = Askbot(ASKBOT_URL) questions = [question for question in backend.fetch()] json_comments = json.loads(comments) self.assertEqual(len(questions[0]['data']['answers']), len(questions[0]['data']['answer_ids'])) self.assertTrue(questions[0]['data']['answers'][0]['accepted']) self.assertEqual(questions[0]['tag'], 'http://example.com') self.assertEqual(questions[0]['uuid'], '3fb5f945a0dd223c60218a98ad35bad6043f9f5f') self.assertEqual(questions[0]['updated_on'], 1408116902.0) self.assertEqual(questions[0]['data']['id'], 2488) self.assertEqual(questions[0]['category'], backend.metadata_category(questions[0])) self.assertEqual(questions[0]['data']['comments'][0], json_comments[0]) self.assertEqual(len(questions[0]['data']['comments']), len(json_comments)) self.assertEqual(len(questions[1]['data']['answers']), len(questions[1]['data']['answer_ids'])) self.assertFalse(questions[1]['data']['answers'][0]['accepted']) self.assertEqual(questions[1]['tag'], 'http://example.com') self.assertEqual(questions[1]['uuid'], 'ecc1320265e400edb28700cc3d02efc6d76410be') self.assertEqual(questions[1]['updated_on'], 1349928216.0) self.assertEqual(questions[1]['data']['id'], 2481) self.assertEqual(questions[1]['category'], backend.metadata_category(questions[1]))
def test_too_many_redirects(self): """Test whether a too many redirects error is properly handled""" question_api_1 = read_file('data/askbot/askbot_api_questions.json') question_api_2 = read_file('data/askbot/askbot_api_questions_2.json') question_html_2 = read_file( 'data/askbot/askbot_question_multipage_1.html') question_html_2_2 = read_file( 'data/askbot/askbot_question_multipage_2.html') comments = read_file('data/askbot/askbot_2481_multicomments.json') httpretty.register_uri(httpretty.GET, ASKBOT_QUESTIONS_API_URL, body=question_api_1, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTIONS_API_URL, body=question_api_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2481_URL, location=ASKBOT_QUESTION_2481_URL, status=301) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2488_URL, body=question_html_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_QUESTION_2488_URL, body=question_html_2_2, status=200) httpretty.register_uri(httpretty.GET, ASKBOT_COMMENTS_API_URL, body=comments, status=200) backend = Askbot(ASKBOT_URL) questions = [question for question in backend.fetch()] self.assertEqual(len(questions), 1)