Exemple #1
0
    def test_get_comments_old_url(self):
        """Test if commits call works with the old URL schema"""

        body = read_file('data/askbot/askbot_2481_multicomments.json')

        httpretty.register_uri(httpretty.GET,
                               ASKBOT_COMMENTS_API_URL,
                               body='',
                               status=404)
        httpretty.register_uri(httpretty.GET,
                               ASKBOT_COMMENTS_API_URL_OLD,
                               body=body,
                               status=200)

        client = AskbotClient(ASKBOT_URL)

        result = client.get_comments(17)

        self.assertEqual(result, body)

        expected = {
            'post_id': ['17'],
            'post_type': ['answer'],
            'avatar_size': ['0']
        }

        reqs = httpretty.httpretty.latest_requests

        self.assertEqual(len(reqs), 2)
        self.assertEqual(reqs[0].method, 'GET')
        self.assertRegex(reqs[0].path, '/s/post_comments')
        self.assertDictEqual(reqs[0].querystring, expected)
        self.assertEqual(reqs[1].method, 'GET')
        self.assertRegex(reqs[1].path, '/post_comments')
        self.assertDictEqual(reqs[1].querystring, expected)
Exemple #2
0
    def test_get_comments(self):
        """Test if comments call works"""

        body = read_file('data/askbot/askbot_2481_multicomments.json')

        httpretty.register_uri(httpretty.GET,
                               ASKBOT_COMMENTS_API_URL,
                               body=body,
                               status=200)

        client = AskbotClient(ASKBOT_URL)

        result = client.get_comments(17)

        self.assertEqual(result, body)

        expected = {
            'post_id': ['17'],
            'post_type': ['answer'],
            'avatar_size': ['0']
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, 's/post_comments')
        self.assertDictEqual(req.querystring, expected)
    def test_500_status_get_comments(self):
        """Test whether, when fetching comments, an exception is thrown if HTTPError is not 503"""

        httpretty.register_uri(httpretty.GET,
                               ASKBOT_COMMENTS_API_URL,
                               body="", status=500)

        client = AskbotClient(ASKBOT_URL)
        self.assertEqual(client.get_comments(5), '[]')
Exemple #4
0
    def test_wrong_status_get_comments(self):
        """Test whether, when fetching comments, an exception is thrown if HTTPError is not 404"""

        httpretty.register_uri(httpretty.GET,
                               ASKBOT_COMMENTS_API_URL,
                               body="", status=403)

        client = AskbotClient(ASKBOT_URL)

        with self.assertRaises(requests.exceptions.HTTPError):
            _ = client.get_comments(5)