def test_discovery_handles_403__raise_tap_zendesk_forbidden_error( self, mock_get, mock_resolve_schema_references, mock_load_metadata, mock_load_schema, mock_load_shared_schema_refs, mocked_sla_policies, mocked_ticket_forms, mock_users, mock_organizations, mock_logger): ''' Test that we handle forbidden error for child streams. discover_streams calls check_access for each stream to check the read perission. discover_streams call many other methods including load_shared_schema_refs, load_metadata, load_schema, resolve_schema_references also which we mock to test forbidden error. We mock check_access method of some of stream method which call request of zenpy module and also mock get method of requests module with 200, 403 error. ''' discover.discover_streams( 'dummy_client', { 'subdomain': 'arp', 'access_token': 'dummy_token', 'start_date': START_DATE }) expected_call_count = 10 actual_call_count = mock_get.call_count self.assertEqual(expected_call_count, actual_call_count) # Verifying the logger message mock_logger.assert_called_with("The account credentials supplied do not have 'read' access to the following stream(s): "\ "groups, users, organizations, ticket_audits, ticket_comments, ticket_fields, ticket_forms, group_memberships, macros, "\ "satisfaction_ratings, tags, ticket_metrics. The data for these streams would not be collected due to lack of required "\ "permission.")
def test_discovery_handles_except_403_error_zenpy_module( self, mock_get, mock_resolve_schema_references, mock_load_metadata, mock_load_schema, mock_load_shared_schema_refs, mocked_sla_policies, mocked_ticket_forms, mock_users, mock_organizations): ''' Test that discovery mode raise error direclty if it is rather than 403 for request zenpy module. discover_streams call many other methods including load_shared_schema_refs, load_metadata, load_schema, resolve_schema_references also which we mock to test forbidden error. We mock check_access method of some of stream method which call request of zenpy module and also mock get method of requests module with 400, 403 error. ''' try: responses = discover.discover_streams( 'dummy_client', { 'subdomain': 'arp', 'access_token': 'dummy_token', 'start_date': START_DATE }) except zenpy.lib.exception.APIException as e: expected_error_message = AUTH_ERROR # Verifying the message formed for the custom exception self.assertEqual(str(e), expected_error_message) expected_call_count = 2 actual_call_count = mock_get.call_count self.assertEqual(expected_call_count, actual_call_count)
def test_discovery_handles_except_403_error_requests_module( self, mock_get, mock_resolve_schema_references, mock_load_metadata, mock_load_schema, mock_load_shared_schema_refs, mocked_sla_policies, mocked_ticket_forms, mock_users, mock_organizations): ''' Test that function raises error directly if error code is other than 403. discover_streams calls check_access for each stream to check the read perission. discover_streams call many other methods including load_shared_schema_refs, load_metadata, load_schema, resolve_schema_references also which we mock to test forbidden error. We mock check_access method of some of stream method which call request of zenpy module and also mock get method of requests module with 200, 403 error. ''' try: responses = discover.discover_streams( 'dummy_client', { 'subdomain': 'arp', 'access_token': 'dummy_token', 'start_date': START_DATE }) except http.ZendeskBadRequestError as e: expected_error_message = "HTTP-error-code: 400, Error: A validation exception has occurred." # Verifying the message formed for the custom exception self.assertEqual(str(e), expected_error_message) expected_call_count = 4 actual_call_count = mock_get.call_count self.assertEqual(expected_call_count, actual_call_count)
def test_discovery_handles_200_response( self, mock_get, mock_resolve_schema_references, mock_load_metadata, mock_load_schema, mock_load_shared_schema_refs, mocked_sla_policies, mocked_ticket_forms, mock_users, mock_organizations): ''' Test that discovery mode does not raise any error in case of all streams have read permission ''' discover.discover_streams( 'dummy_client', { 'subdomain': 'arp', 'access_token': 'dummy_token', 'start_date': START_DATE }) expected_call_count = 10 actual_call_count = mock_get.call_count self.assertEqual(expected_call_count, actual_call_count)
def test_discovery_handles_403_for_all_streams_api_token( self, mock_get, mock_resolve_schema_references, mock_load_metadata, mock_load_schema, mock_load_shared_schema_refs, mocked_sla_policies, mocked_ticket_forms, mock_users, mock_organizations, mock_logger): ''' Test that we handle forbidden error received from all streams and raise the ZendeskForbiddenError with proper error message. discover_streams calls check_access for each stream to check the read perission. discover_streams call many other methods including load_shared_schema_refs, load_metadata, load_schema, resolve_schema_references also which we mock to test forbidden error. We mock check_access method of some of stream method which call request of zenpy module and also mock get method of requests module with 200, 403 error. ''' try: responses = discover.discover_streams( 'dummy_client', { 'subdomain': 'arp', 'access_token': 'dummy_token', 'start_date': START_DATE }) except http.ZendeskForbiddenError as e: expected_message = "HTTP-error-code: 403, Error: The account credentials supplied do not have 'read' access to any "\ "of streams supported by the tap. Data collection cannot be initiated due to lack of permissions." # # Verifying the message formed for the custom exception self.assertEqual(str(e), expected_message)
def do_discover(client): LOGGER.info("Starting discover") catalog = {"streams": discover_streams(client)} json.dump(catalog, sys.stdout, indent=2) LOGGER.info("Finished discover")