Esempio n. 1
0
    def test_request_no_auth(self):
        def stubbed_request(method, url, data, auth):
            self.assertEqual(auth, None)
            return FakeResponse(json.dumps({'data': {}}))

        self.monkey_patch(requests, 'request', stubbed_request)

        client = DiamondashApiClient()
        client.request('put', 'foo', {}),
Esempio n. 2
0
    def test_request_no_auth(self):
        def stubbed_request(method, url, data, auth):
            self.assertEqual(auth, None)
            return FakeResponse(json.dumps({'data': {}}))

        self.monkey_patch(requests, 'request', stubbed_request)

        client = DiamondashApiClient()
        client.request('put', 'foo', {}),
Esempio n. 3
0
    def test_raw_request_for_error_responses(self):
        resp = FakeErrorResponse(':(')
        self.monkey_patch(requests, 'request', lambda *a, **kw: resp)

        client = DiamondashApiClient()
        self.assertRaises(DiamondashApiError, client.raw_request, 'put', 'foo',
                          'bar')
Esempio n. 4
0
    def test_raw_request(self):
        self.vumi_helper.patch_settings(DIAMONDASH_API_USERNAME='******',
                                        DIAMONDASH_API_PASSWORD='******')

        resp = FakeResponse('spam', 201)

        def stubbed_request(method, url, data, auth):
            self.assertEqual(method, 'put')
            self.assertEqual(url, 'http://diamondash.moc/api/foo')
            self.assertEqual(data, 'bar')
            self.assertEqual(auth, ('username', 'password'))
            return resp

        self.monkey_patch(requests, 'request', stubbed_request)

        client = DiamondashApiClient()
        self.assertEqual(client.raw_request('put', 'foo', 'bar'), {
            'code': 201,
            'content': 'spam'
        })
Esempio n. 5
0
    def test_raw_request(self):
        self.vumi_helper.patch_settings(
            DIAMONDASH_API_USERNAME='******',
            DIAMONDASH_API_PASSWORD='******')

        resp = FakeResponse('spam', 201)

        def stubbed_request(method, url, data, auth):
            self.assertEqual(method, 'put')
            self.assertEqual(url, 'http://diamondash.moc/api/foo')
            self.assertEqual(data, 'bar')
            self.assertEqual(auth, ('username', 'password'))
            return resp

        self.monkey_patch(requests, 'request', stubbed_request)

        client = DiamondashApiClient()
        self.assertEqual(client.raw_request('put', 'foo', 'bar'), {
            'code': 201,
            'content': 'spam'
        })
Esempio n. 6
0
    def test_request(self):
        self.vumi_helper.patch_settings(
            DIAMONDASH_API_USERNAME='******',
            DIAMONDASH_API_PASSWORD='******')

        resp = FakeResponse(json.dumps({
            'success': True,
            'data': {'spam': 'ham'}
        }))

        def stubbed_request(method, url, data, auth):
            self.assertEqual(method, 'put')
            self.assertEqual(url, 'http://diamondash.moc/api/foo')
            self.assertEqual(data, json.dumps({'bar': 'baz'}))
            self.assertEqual(auth, ('username', 'password'))
            return resp

        self.monkey_patch(requests, 'request', stubbed_request)

        client = DiamondashApiClient()
        self.assertEqual(
            client.request('put', 'foo', {'bar': 'baz'}),
            {'spam': 'ham'})
Esempio n. 7
0
    def test_request(self):
        self.vumi_helper.patch_settings(DIAMONDASH_API_USERNAME='******',
                                        DIAMONDASH_API_PASSWORD='******')

        resp = FakeResponse(
            json.dumps({
                'success': True,
                'data': {
                    'spam': 'ham'
                }
            }))

        def stubbed_request(method, url, data, auth):
            self.assertEqual(method, 'put')
            self.assertEqual(url, 'http://diamondash.moc/api/foo')
            self.assertEqual(data, json.dumps({'bar': 'baz'}))
            self.assertEqual(auth, ('username', 'password'))
            return resp

        self.monkey_patch(requests, 'request', stubbed_request)

        client = DiamondashApiClient()
        self.assertEqual(client.request('put', 'foo', {'bar': 'baz'}),
                         {'spam': 'ham'})
Esempio n. 8
0
    def test_make_api_url(self):
        client = DiamondashApiClient()

        self.assertEqual(
            client.make_api_url('dashboards'),
            'http://diamondash.moc/api/dashboards')
Esempio n. 9
0
    def test_make_api_url(self):
        client = DiamondashApiClient()

        self.assertEqual(client.make_api_url('dashboards'),
                         'http://diamondash.moc/api/dashboards')