示例#1
0
    def test_no_request_timeout_in_config(self, mocked_prepare, mocked_send):
        """
            Verify that if request_timeout is not provided in config then default value is used
        """
        jira_client = Client({"base_url": "https://your-jira-domain"}) # No request_timeout in config
        jira_client.refresh_token = "test"

        # Call request method which call Session.send with timeout
        jira_client.request("test", method="GET", path="http://test")

        # Verify Session.send is called with expected timeout
        args, kwargs = mocked_send.call_args
        self.assertEqual(kwargs.get('timeout'), 300) # Verify timeout argument
示例#2
0
    def test_request_timeout_backoff(
        self, mocked_prepare, mocked_send, mocked_sleep, mocked_test):
        """
            Verify request function is backoff for 6 times on Timeout exception
        """
        jira_client = Client({"base_url": "https://your-jira-domain"})
        jira_client.refresh_token = "test"

        try:
            jira_client.request("test", method="GET", path="http://test")
        except requests.exceptions.Timeout:
            pass

        # Verify that Session.send is called 6 times
        self.assertEqual(mocked_send.call_count, 6)
示例#3
0
    def test_string_request_timeout_in_config(self, mocked_prepare, mocked_send):
        """
            Verify that if request_timeout is provided in config (string value) then it should be use
        """
        jira_client = Client({
            "base_url": "https://your-jira-domain",
            "request_timeout": "100" # string format timeout in config
            })
        jira_client.refresh_token = "test"

        # Call request method which call Session.send with timeout
        jira_client.request("test", method="GET", path="http://test")

        # Verify requests.request and Session.send is called with expected timeout
        args, kwargs = mocked_send.call_args
        self.assertEqual(kwargs.get('timeout'), 100) # Verify timeout argument
示例#4
0
    def test_pk_for_on_prem_jira(self, mocked_send):
        '''
            Verify is_on_prem_instance property of Client changed True when `deploymentType`
            is `Server` in the response
        '''
        mocked_send.return_value = get_mock_http_response(
            200, {"deploymentType": "Server"})

        jira_client = Client(JIRA_CONFIG)

        self.assertEqual(jira_client.is_on_prem_instance, True)
示例#5
0
    def test_pk_for_cloud_jira(self, mocked_send):
        '''
            Verify is_on_prem_instance property of Client remain False when `deploymentType`
            is `Cloud` in the response
        '''
        mocked_send.return_value = get_mock_http_response(
            200, {"deploymentType": "Cloud"})

        jira_client = Client(JIRA_CONFIG)

        self.assertEqual(jira_client.is_on_prem_instance, False)
示例#6
0
    def test_pk_update_for_on_prem_jira(self, mocked_metadata, mocked_send):
        '''
            Verify primary key of users stream is updated to `key` when is_on_prem_instance property
            of Client is True(on prem jira account)
        '''
        mocked_send.return_value = get_mock_http_response(200, {})

        jira_client = Client(JIRA_CONFIG)
        jira_client.is_on_prem_instance = True
        Context.client = jira_client
        # `users` stream
        users_stream = ALL_STREAMS[7]

        # mock schema and it's properties
        schema = Mock()
        schema.properties = {}

        tap_jira.generate_metadata(users_stream, schema)

        # Verify primary key of stream
        self.assertEqual(users_stream.pk_fields, ["key"])
示例#7
0
    def test_pk_update_for_non_users_stream(self, mocked_metadata,
                                            mocked_send):
        '''
            Verify primary key of all other streams remain unchanged.
        '''
        mocked_send.return_value = get_mock_http_response(200, {})

        jira_client = Client(JIRA_CONFIG)

        # `resolutions` stream(other than users stream)
        users_stream = ALL_STREAMS[5]

        # mock schema and it's properties
        schema = Mock()
        schema.properties = {}

        tap_jira.generate_metadata(users_stream, schema)

        # Verify primary key of stream
        self.assertEqual(users_stream.pk_fields, ["id"])
示例#8
0
    def test_timeout_backoff_for_refresh_credentials(
        self, mocked_post, mocked_test, mocked_timer, mocked_sleep):
        """
            Verify refresh_credentials method backoff's for 3 times on Timeout exception
        """
        config = {
            "base_url": "https://your-jira-domain",
            "oauth_client_id": "test",
            "oauth_client_secret": "test",
            "refresh_token": "test"
            }

        try:
            # init Client with `oauth_client_id` in config calls refresh_credentials
            Client(config)
        except Exception:
            pass

        # Verify that Response.raise_for_status is called 3 times
        self.assertEqual(mocked_post.call_count, 3)