Exemplo n.º 1
0
    def test_post(self):
        """Test post API call"""

        # Set up a mock HTTP server
        body = read_file('data/discourse_post.json')
        httpretty.register_uri(httpretty.GET,
                               DISCOURSE_POST_URL_1,
                               body=body,
                               status=200)

        # Call API
        client = DiscourseClient(DISCOURSE_SERVER_URL, api_key='aaaa')
        response = client.post(21)

        self.assertEqual(response, body)

        # Check request params
        expected = {
            'api_key': ['aaaa'],
        }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/posts/21.json')
        self.assertDictEqual(req.querystring, expected)
Exemplo n.º 2
0
    def test_post(self):
        """Test post API call"""

        # Set up a mock HTTP server
        body = read_file('data/discourse_post.json')
        httpretty.register_uri(httpretty.GET,
                               DISCOURSE_POST_URL_1,
                               body=body, status=200)

        # Call API
        client = DiscourseClient(DISCOURSE_SERVER_URL, api_key='aaaa')
        response = client.post(21)

        self.assertEqual(response, body)

        # Check request params
        expected = {
                    'api_key' : ['aaaa'],
                   }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/posts/21.json')
        self.assertDictEqual(req.querystring, expected)
Exemplo n.º 3
0
    def test_init(self):
        """Test whether attributes are initializated"""

        client = DiscourseClient(DISCOURSE_SERVER_URL, api_key='aaaa')

        self.assertEqual(client.url, DISCOURSE_SERVER_URL)
        self.assertEqual(client.api_key, 'aaaa')
Exemplo n.º 4
0
    def test_topics_page(self):
        """Test topics_page API call"""

        # Set up a mock HTTP server
        body = read_file('data/discourse_topics.json')
        httpretty.register_uri(httpretty.GET,
                               DISCOURSE_TOPICS_URL,
                               body=body, status=200)

        # Call API without args
        client = DiscourseClient(DISCOURSE_SERVER_URL, api_key='aaaa')
        response = client.topics_page()

        self.assertEqual(response, body)

        # Check request params
        expected = {
                    'api_key' : ['aaaa']
                   }

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/latest.json')
        self.assertDictEqual(req.querystring, expected)

        # Call API selecting a page
        response = client.topics_page(page=1)

        self.assertEqual(response, body)

        # Check request params
        expected = {
                    'api_key' : ['aaaa'],
                    'page' : ['1']
                   }

        req = httpretty.last_request()

        self.assertDictEqual(req.querystring, expected)
Exemplo n.º 5
0
    def test_topics_page(self):
        """Test topics_page API call"""

        # Set up a mock HTTP server
        body = read_file('data/discourse_topics.json')
        httpretty.register_uri(httpretty.GET,
                               DISCOURSE_TOPICS_URL,
                               body=body,
                               status=200)

        # Call API without args
        client = DiscourseClient(DISCOURSE_SERVER_URL, api_key='aaaa')
        response = client.topics_page()

        self.assertEqual(response, body)

        # Check request params
        expected = {'api_key': ['aaaa']}

        req = httpretty.last_request()

        self.assertEqual(req.method, 'GET')
        self.assertRegex(req.path, '/latest.json')
        self.assertDictEqual(req.querystring, expected)

        # Call API selecting a page
        response = client.topics_page(page=1)

        self.assertEqual(response, body)

        # Check request params
        expected = {'api_key': ['aaaa'], 'page': ['1']}

        req = httpretty.last_request()

        self.assertDictEqual(req.querystring, expected)