Initial unit test
							parent
							
								
									34264f6ca5
								
							
						
					
					
						commit
						078695889b
					
				@ -1 +0,0 @@
 | 
			
		||||
import dramatiq
 | 
			
		||||
@ -0,0 +1,8 @@
 | 
			
		||||
import requests
 | 
			
		||||
 | 
			
		||||
# TODO add error handling logic for request
 | 
			
		||||
def count_words(url):
 | 
			
		||||
    response = requests.get(url, timeout=5)
 | 
			
		||||
    word_count = len(response.text.split(" "))
 | 
			
		||||
    print(f"There are {word_count} words in {url}")
 | 
			
		||||
    return word_count
 | 
			
		||||
@ -0,0 +1,16 @@
 | 
			
		||||
from unittest.mock import MagicMock, patch
 | 
			
		||||
 | 
			
		||||
from app.app import count_words
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@patch("app.app.requests")
 | 
			
		||||
def test_count_words(mock_requests):
 | 
			
		||||
    mock_response = MagicMock()
 | 
			
		||||
    mock_response.text = "example word count split"
 | 
			
		||||
    mock_requests.get.return_value = mock_response
 | 
			
		||||
 | 
			
		||||
    wc = count_words("http://anyurl.com")
 | 
			
		||||
    assert wc == 4
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# TODO add test coverage for failure
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue