Initial unit test

master
Drew Bednar 2 years ago
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

@ -12,10 +12,18 @@ def start_app(docs=False, extra=""):
print(f"Building docs. Docs value: {extra}")
@task
def run_unit_tests(c):
"""Triggers a local unittest run for the app."""
# Pytest will hide color output when it thinks it's running
# outside of a terminal therefore pty=True is used.
c.run("python3 -m pytest -vvv tests/unit", pty=True)
@task
def fix_eof(c):
"""Fixes any missing newlines for end of files."""
c.run("pre-commit run end-of-file-fixer --all-files")
c.run("pre-commit run end-of-file-fixer --all-files", pty=True)
@task

@ -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…
Cancel
Save