Exemple #1
0
    def test_returns_multiple_pages_if_get_all_pages_true(self, _):
        zendesk_hook = ZendeskHook("conn_id")
        mock_connection = mock.Mock()
        mock_connection.host = "some_host"
        zendesk_hook.get_connection = mock.Mock(return_value=mock_connection)
        zendesk_hook.get_conn()

        mock_conn = mock.Mock()
        mock_call = mock.Mock(
            return_value={'next_page': 'https://some_host/something',
                          'path': []})
        mock_conn.call = mock_call
        zendesk_hook.get_conn = mock.Mock(return_value=mock_conn)
        zendesk_hook.call("path", get_all_pages=True)
        assert mock_call.call_count == 2
Exemple #2
0
    def test_returns_single_page_if_get_all_pages_false(self, _):
        zendesk_hook = ZendeskHook("conn_id")
        mock_connection = mock.Mock()
        mock_connection.host = "some_host"
        zendesk_hook.get_connection = mock.Mock(return_value=mock_connection)
        zendesk_hook.get_conn()

        mock_conn = mock.Mock()
        mock_call = mock.Mock(
            return_value={'next_page': 'https://some_host/something',
                          'path': []})
        mock_conn.call = mock_call
        zendesk_hook.get_conn = mock.Mock(return_value=mock_conn)
        zendesk_hook.call("path", get_all_pages=False)
        mock_call.assert_called_once_with("path", None)
Exemple #3
0
    def test_sleeps_for_correct_interval(self, mocked_time):
        sleep_time = 10
        # To break out of the otherwise infinite tries
        mocked_time.sleep = mock.Mock(side_effect=ValueError, return_value=3)
        conn_mock = mock.Mock()
        mock_response = mock.Mock()
        mock_response.headers.get.return_value = sleep_time
        conn_mock.call = mock.Mock(side_effect=RateLimitError(
            msg="some message", code="some code", response=mock_response))

        zendesk_hook = ZendeskHook("conn_id")
        zendesk_hook.get_conn = mock.Mock(return_value=conn_mock)

        with pytest.raises(ValueError):
            zendesk_hook.call("some_path", get_all_pages=False)
            mocked_time.sleep.assert_called_once_with(sleep_time)
Exemple #4
0
    def test_zdesk_sideloading_works_correctly(self, mock_zendesk):
        zendesk_hook = ZendeskHook("conn_id")
        mock_connection = mock.Mock()
        mock_connection.host = "some_host"
        zendesk_hook.get_connection = mock.Mock(return_value=mock_connection)
        zendesk_hook.get_conn()

        mock_conn = mock.Mock()
        mock_call = mock.Mock(
            return_value={'next_page': 'https://some_host/something',
                          'tickets': [],
                          'users': [],
                          'groups': []})
        mock_conn.call = mock_call
        zendesk_hook.get_conn = mock.Mock(return_value=mock_conn)
        results = zendesk_hook.call(".../tickets.json",
                                    query={"include": "users,groups"},
                                    get_all_pages=False,
                                    side_loading=True)
        assert results == {'groups': [], 'users': [], 'tickets': []}