Ejemplo n.º 1
0
    def test_connect(self, mock_provider):
        mock_cookie = {'Cookie': 'cookie=testcookie'}
        mock_provider.return_value.auth_header.return_value = mock_cookie

        c = Client('server', 'user', 'pass')
        c.connect()

        self.assertEqual(c.headers, mock_cookie)
Ejemplo n.º 2
0
    def test_post(self):
        mock_response = mock.MagicMock()

        c = Client('server', 'user', 'pass')
        with mock.patch.object(c.session, 'post',
                               return_value=mock_response) as mock_requests:
            c.post({}, 'test')

            mock_requests.assert_called_once_with('api/test', json={})
            mock_response.raise_for_status.assert_called_once_with()
Ejemplo n.º 3
0
    def test_connect(self, mock_provider):
        mock_cookie = {'Cookie': 'cookie=testcookie'}
        mock_provider.return_value.auth_header.return_value = mock_cookie

        c = Client('server', 'user', 'pass')
        c.connect()

        self.assertTrue(
            all(item in c.session.headers.items()
                for item in mock_cookie.items()))
Ejemplo n.º 4
0
    def test_put_classmethod(self):
        mock_response = mock.MagicMock()

        Client.default = Client('server', 'user', 'pass')
        with mock.patch.object(Client.default.session,
                               'put',
                               return_value=mock_response) as mock_requests:
            Client.put({}, 'test')

            mock_requests.assert_called_once_with('api/test', json={})
            mock_response.raise_for_status.assert_called_once_with()
Ejemplo n.º 5
0
    def test_send_data(self):
        mock_requests = mock.MagicMock()

        c = Client('server', 'user', 'pass')
        c.send_data({}, 'test', mock_requests)

        mock_requests.assert_called_once_with(
            'api/test',
            json={},
        )
        mock_requests.return_value.raise_for_status.assert_called_once_with()
Ejemplo n.º 6
0
    def test_get_classmethod(self, mock_requests):
        mock_response = mock.MagicMock()
        mock_requests.get.return_value = mock_response

        Client.default = Client('server', 'user', 'pass')
        Client.get('test')

        mock_requests.get.assert_called_once_with(
            'api/test',
            headers={},
            verify=True)
        mock_response.raise_for_status.assert_called_once_with()
Ejemplo n.º 7
0
    def test_send_data(self):
        mock_requests = mock.MagicMock()

        c = Client('server', 'user', 'pass')
        c.send_data({}, 'test', mock_requests)

        mock_requests.assert_called_once_with(
            'api/test',
            data='{}',
            headers={'content-type': 'application/json'},
            verify=True)
        mock_requests.return_value.raise_for_status.assert_called_once_with()
Ejemplo n.º 8
0
    def test_put(self, mock_requests):
        mock_response = mock.MagicMock()
        mock_requests.put.return_value = mock_response

        c = Client('server', 'user', 'pass')
        c.put({}, 'test')

        mock_requests.put.assert_called_once_with(
            'api/test',
            data='{}',
            headers={'content-type': 'application/json'},
            verify=True)
        mock_response.raise_for_status.assert_called_once_with()
Ejemplo n.º 9
0
    def test_build_payload(self):
        mock_response = mock.MagicMock()
        c = Client('server', 'user', 'pass')

        mock_response.content = None
        self.assertEqual(c.build_payload(mock_response), None)

        mock_response.content = '{}'
        mock_response.json.return_value = {}
        self.assertIsInstance(c.build_payload(mock_response), SwimlaneDict)

        mock_response.content = '[{}]'
        mock_response.json.return_value = [{}]
        payload = c.build_payload(mock_response)
        self.assertIsInstance(next(payload), SwimlaneDict)
Ejemplo n.º 10
0
    def test_init(self):
        c = Client('server', 'user', 'pass')

        self.assertEqual(c.username, 'user')
        self.assertEqual(c.session.verify, True)
        self.assertEqual(c.base_url, 'api/')
        self.assertIsInstance(c.provider, UserPassAuthProvider)
Ejemplo n.º 11
0
 def test_set_default(self, mock_provider):
     Client.set_default('server', 'user', 'pass')
     mock_provider.return_value.auth_header.assert_called_once_with()