Skip to content

Commit

Permalink
Merge pull request #2
Browse files Browse the repository at this point in the history
adiciona teste unitario
  • Loading branch information
italojohnny authored Nov 18, 2024
2 parents 05f6df4 + 40e849d commit 9c47942
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.coverage
coverage/
13 changes: 2 additions & 11 deletions dados_publicos_cnpj/__main__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import aiohttp
import asyncio
import click


URL = "https://arquivos.receitafederal.gov.br/dados/cnpj/dados_abertos_cnpj/"
from dados_publicos_cnpj.extract.util import check_url_availability


async def check_url_availability(url):
async with aiohttp.ClientSession() as session:
try:
async with session.get(url) as response:
return 200 <= response.status < 300

except aiohttp.ClientError:
return False
URL = "https://arquivos.receitafederal.gov.br/dados/cnpj/dados_abertos_cnpj/"


@click.group()
Expand Down
11 changes: 11 additions & 0 deletions dados_publicos_cnpj/extract/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import aiohttp


async def check_url_availability(url):
async with aiohttp.ClientSession() as session:
try:
async with session.get(url) as response:
return 200 <= response.status < 300

except aiohttp.ClientError:
return False
4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

verifica:
@poetry run python -m dados_publicos_cnpj verifica

unit_tests:
@poetry run pytest
@poetry run coverage html
169 changes: 168 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ aiohttp = "^3.11.2"
click = "^8.1.7"


[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
pytest-cov = "^6.0.0"
pytest-asyncio = "^0.24.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
pythonpath = "."
addopts = [
"-s",
"-x",
"-vv",
"--doctest-modules",
"--cov=dados_publicos_cnpj",
"--cov-report=term",
]

[tool.coverage.html]
directory = "coverage"
10 changes: 10 additions & 0 deletions tests/unit/extract/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest

from dados_publicos_cnpj.extract.util import check_url_availability


@pytest.mark.asyncio
async def test_check_url_availability():
url = "https://google.com"
result = await check_url_availability(url)
assert result

0 comments on commit 9c47942

Please sign in to comment.