Example #1
0
    def test_text_response(self, get):
        api = Api({})

        dummy = Mock(text='some text')
        dummy.json.side_effect = Exception('Should not call this')
        get.return_value = dummy

        res = api.request('/me', result='text')
        self.assertEqual(res, 'some text')
Example #2
0
    def test_fail_on_request_exception(self, get):
        api = Api({})
        get.side_effect = RequestException('I\'m just working here man')

        with self.assertRaises(SystemExit):
            api.request('/me', auth=True)

        api2 = api.clone(sysexit=False)
        with self.assertRaises(ApiException):
            api2.request('/me', auth=True, csrf=True)
Example #3
0
    def test_fail_on_ssl(self, get):
        api = Api({})
        get.side_effect = SSLError('Hey hey')

        with self.assertRaises(SystemExit):
            api.request('/me', auth=True)

        api2 = api.clone(sysexit=False)
        with self.assertRaises(ApiException):
            api2.request('/me', auth=True)
Example #4
0
    def test_fail_on_errored_response(self, get):
        api = Api({})

        get.return_value = {'error': 'SomethingError'}

        with self.assertRaises(SystemExit):
            api.request('/me', auth=True)

        api2 = api.clone(sysexit=False)
        with self.assertRaises(ApiException):
            api2.request('/me', auth=True, csrf=True)
Example #5
0
    def test_create_post(self, post):
        api = Api({})

        api.create_post('new post, lala', ['tag1', 'tag2'])

        post.assert_called_once_with('https://point.im/api/post',
                                     data={
                                         'text': 'new post, lala',
                                         'tag': ['tag1', 'tag2'],
                                         'private': None
                                     },
                                     headers={
                                         'X-CSRF': '',
                                         'Authorization': ''
                                     })
Example #6
0
    def test_fail_on_json(self, get):
        api = Api({})
        dummy = Mock()
        dummy.json.side_effect = Exception('JSON parsing failed')
        dummy.text.return_value = 'something'

        get.return_value = dummy

        with self.assertRaises(SystemExit):
            api.request('/me', auth=True)

        api2 = api.clone(sysexit=False)

        with self.assertRaises(ApiException):
            api2.request('/me', auth=True)
Example #7
0
    def test_basic_request(self, post):
        api = Api({})
        api.request('/test', method='post', data={'tag': ['babuf']})

        post.assert_called_once_with('https://point.im/api/test',
                                     data={'tag': ['babuf']})
Example #8
0
 def __init__(self, config):
     self._config = config
     self._api = Api(config)