Ejemplo n.º 1
0
    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'])
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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]))
Ejemplo n.º 4
0
    def test_initialization(self):
        """Test whether attributes are initializated."""

        ab = Askbot(ASKBOT_URL, tag='test')

        self.assertEqual(ab.url, ASKBOT_URL)
        self.assertEqual(ab.tag, 'test')
        self.assertIsNone(ab.client, None)

        # When tag is empty or None it will be set to
        # the value in url
        ab = Askbot(ASKBOT_URL)
        self.assertEqual(ab.url, ASKBOT_URL)
        self.assertEqual(ab.tag, ASKBOT_URL)

        ab = Askbot(ASKBOT_URL, tag='')
        self.assertEqual(ab.url, ASKBOT_URL)
        self.assertEqual(ab.tag, ASKBOT_URL)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
 def setUp(self):
     super().setUp()
     self.backend = Askbot(ASKBOT_URL, archive=self.archive)
Ejemplo n.º 7
0
    def test_has_archiving(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Askbot.has_archiving(), True)
Ejemplo n.º 8
0
 def setUp(self):
     super().setUp()
     self.backend_write_archive = Askbot(ASKBOT_URL, archive=self.archive)
     self.backend_read_archive = Askbot(ASKBOT_URL, archive=self.archive)
Ejemplo n.º 9
0
    def test_has_caching(self):
        """Test if it returns True when has_caching is called."""

        self.assertEqual(Askbot.has_caching(), False)