- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5
GL-Work #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Open
      
      
            romilqlik
  wants to merge
  8
  commits into
  master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
gl-master
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    GL-Work #21
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            8 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      988ced4
              
                Addressed PR feddback: setup.py schema path fix, disabled retry on in…
              
              
                gl-romil f2fc392
              
                Added:circle ci, unittests, removed redundant comment from http.py
              
              
                gl-romil ca8de33
              
                Add unit test for InvalidLogonAttempt Fault not being retried
              
              
                gl-romil fbaa6e9
              
                Removed Lib.
              
              
                 23e493f
              
                code changes done for ppositional argument: 'lists' issue.
              
              
                 13fb499
              
                Code chnage done as per comment.
              
              
                 0da1dfc
              
                Removed unwanted lines and print statment.
              
              
                 1a733f4
              
                Delete catalog.json
              
              
                Rahulgogawale25 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| version: 2.1 | ||
|  | ||
| jobs: | ||
| build: | ||
| docker: | ||
| - image: 218546966473.dkr.ecr.us-east-1.amazonaws.com/circle-ci:stitch-tap-tester | ||
|  | ||
| steps: | ||
| - checkout | ||
|  | ||
| - run: | ||
| name: "Setup virtual env and install tap-listrak" | ||
| command: | | ||
| python3 -m venv /usr/local/share/virtualenvs/tap-listrak | ||
| source /usr/local/share/virtualenvs/tap-listrak/bin/activate | ||
| pip install -U "pip==22.2.2" "setuptools==65.3.0" | ||
| pip install -e .[dev] | ||
|  | ||
| - run: | ||
| name: "JSON Validator" | ||
| command: | | ||
| stitch-validate-json tap_listrak/schemas/*.json | ||
|  | ||
| - run: | ||
| name: "Run Pylint" | ||
| command: | | ||
| source /usr/local/share/virtualenvs/tap-listrak/bin/activate | ||
| pip install pylint | ||
| pylint tap_listrak -d C,R,W | ||
|  | ||
| - run: | ||
| name: "Run Unit Tests with Pytest" | ||
| command: | | ||
| source /usr/local/share/virtualenvs/tap-listrak/bin/activate | ||
| pip install pytest coverage pytest-cov | ||
| pip install opentelemetry-api opentelemetry-sdk | ||
| mkdir -p test_output | ||
| pytest --cov=tap_listrak --cov-report html:htmlcov --junitxml=test_output/report.xml tests/unittests/ | ||
|  | ||
| - store_test_results: | ||
| path: test_output | ||
|  | ||
| - store_artifacts: | ||
| path: htmlcov | ||
|  | ||
| workflows: | ||
| version: 2 | ||
|  | ||
| commit: | ||
| jobs: | ||
| - build: | ||
| context: circleci-user | ||
|  | ||
| build_daily: | ||
| triggers: | ||
| - schedule: | ||
| cron: "0 0 * * *" | ||
| filters: | ||
| branches: | ||
| only: | ||
| - master | ||
| jobs: | ||
| - build: | ||
| context: circleci-user | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import pytest | ||
| from unittest.mock import MagicMock, patch | ||
| from zeep.exceptions import XMLSyntaxError, Fault, TransportError | ||
| from tap_listrak.http import request | ||
|  | ||
| MAX_RETRIES = 5 | ||
|  | ||
|  | ||
| @pytest.fixture | ||
| def mock_http_timer(): | ||
| """Patch the http_request_timer context manager.""" | ||
| with patch("tap_listrak.http.metrics.http_request_timer") as mock_timer: | ||
| mock_context = MagicMock() | ||
| mock_timer.return_value.__enter__.return_value = mock_context | ||
| yield mock_timer | ||
|  | ||
|  | ||
| def test_successful_request(mock_http_timer): | ||
| """Test a successful SOAP request returns the expected result.""" | ||
| def service_fn(**kwargs): | ||
| return "Success" | ||
|  | ||
| result = request("test_stream", service_fn) | ||
| assert result == "Success" | ||
| assert mock_http_timer.call_count == 1 | ||
|  | ||
|  | ||
| def test_xml_syntax_error_retry(mock_http_timer): | ||
| """Test that XMLSyntaxError triggers retries up to MAX_RETRIES.""" | ||
| failing_mock = MagicMock(side_effect=XMLSyntaxError("Simulated XML error")) | ||
|  | ||
| with pytest.raises(XMLSyntaxError): | ||
| request("test_stream", failing_mock) | ||
|  | ||
| assert failing_mock.call_count == MAX_RETRIES | ||
| assert mock_http_timer.call_count == MAX_RETRIES | ||
|  | ||
|  | ||
| def test_fault_error_retry(mock_http_timer): | ||
| """Test that Fault exception triggers retries up to MAX_RETRIES.""" | ||
| failing_mock = MagicMock(side_effect=Fault("Simulated Fault")) | ||
|  | ||
| with pytest.raises(Fault): | ||
| request("test_stream", failing_mock) | ||
|  | ||
| assert failing_mock.call_count == MAX_RETRIES | ||
| assert mock_http_timer.call_count == MAX_RETRIES | ||
|  | ||
|  | ||
| def test_transport_error_retry(mock_http_timer): | ||
| """Test that TransportError triggers retries up to MAX_RETRIES.""" | ||
| failing_mock = MagicMock(side_effect=TransportError(502, "Bad Gateway")) | ||
|  | ||
| with pytest.raises(TransportError): | ||
| request("test_stream", failing_mock) | ||
|  | ||
| assert failing_mock.call_count == MAX_RETRIES | ||
| assert mock_http_timer.call_count == MAX_RETRIES | ||
|  | ||
|  | ||
| def test_retry_recovers_before_max_attempts(mock_http_timer): | ||
| """Test that a request recovers after a few retries before reaching max.""" | ||
| service_mock = MagicMock() | ||
| service_mock.side_effect = [XMLSyntaxError("fail"), "Recovered"] | ||
|  | ||
| result = request("test_stream", service_mock) | ||
|  | ||
| assert result == "Recovered" | ||
| assert service_mock.call_count == 2 | ||
| assert mock_http_timer.call_count == 2 | ||
|  | ||
|  | ||
| def test_unhandled_exception_not_retried(mock_http_timer): | ||
| """Test that unexpected exceptions are not retried.""" | ||
| service_mock = MagicMock(side_effect=ValueError("unexpected")) | ||
|  | ||
| with pytest.raises(ValueError): | ||
| request("test_stream", service_mock) | ||
|  | ||
| assert service_mock.call_count == 1 | ||
| assert mock_http_timer.call_count == 1 | ||
|  | ||
|  | ||
| def test_none_as_service_fn(mock_http_timer): | ||
| """Test that passing None instead of a function raises TypeError.""" | ||
| with pytest.raises(TypeError): | ||
| request("test_stream", None) | ||
|  | ||
|  | ||
| def test_service_fn_returns_none(mock_http_timer): | ||
| """Test that a service function returning None is handled properly.""" | ||
| def service_fn(**kwargs): | ||
| return None | ||
|  | ||
| result = request("test_stream", service_fn) | ||
| assert result is None | ||
| assert mock_http_timer.call_count == 1 | ||
|  | ||
|  | ||
| def test_invalid_logon_attempt_not_retried(mock_http_timer): | ||
| """Ensure InvalidLogonAttempt Fault is not retried and raised immediately.""" | ||
| failing_mock = MagicMock(side_effect=Fault("InvalidLogonAttempt")) | ||
|  | ||
| with pytest.raises(Fault) as exc_info: | ||
| request("test_stream", failing_mock) | ||
|  | ||
| assert "InvalidLogonAttempt" in str(exc_info.value) | ||
| assert failing_mock.call_count == 1 | ||
| assert mock_http_timer.call_count == 1 | 
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make below changes,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done.