Skip to content

Commit ff88f57

Browse files
tests: remove src from imports for tests
1 parent fbbf03b commit ff88f57

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

.idea/api-to-dataframe.iml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api_to_dataframe/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from src.api_to_dataframe.main import ClientBuilder
1+
from api_to_dataframe.main import ClientBuilder

src/api_to_dataframe/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __init__(self, endpoint: str):
1010
self.endpoint = endpoint
1111

1212
def _response_to_json(self):
13-
response = requests.get(self.url)
13+
response = requests.get(self.endpoint)
1414

1515
if response.ok:
1616
return response.json()
@@ -19,4 +19,4 @@ def _response_to_json(self):
1919

2020
def to_dataframe(self):
2121
df = pd.DataFrame([self._response_to_json()])
22-
return df
22+
return df

tests/test_run.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
import pytest
2-
import src.api_to_dataframe as apitodf
2+
import pandas as pd
3+
import api_to_dataframe as api_to_dataframe
4+
5+
6+
@pytest.fixture()
7+
def setup():
8+
new_client = api_to_dataframe.ClientBuilder(endpoint="https://economia.awesomeapi.com.br/last/USD-BRL")
9+
return new_client
310

411

512
def test_constructor_without_param():
613
with pytest.raises(ValueError):
7-
new_client = apitodf.ClientBuilder(endpoint="")
14+
new_client = api_to_dataframe.ClientBuilder(endpoint="")
815

916

10-
@pytest.fixture()
11-
def test_constructor_with_param():
12-
expected_result = "param1"
13-
new_client = apitodf.ClientBuilder(endpoint=expected_result)
17+
def test_constructor_with_param(setup):
18+
expected_result = "https://economia.awesomeapi.com.br/last/USD-BRL"
19+
new_client = setup
1420
assert new_client.endpoint == expected_result
15-
return new_client
1621

1722

18-
def test_response_to_json_with_valid_endpoint(test_constructor_with_param):
19-
pass
23+
def test_response_to_json(setup):
24+
new_client = setup
25+
response = new_client._response_to_json()
26+
assert isinstance(response, dict)
27+
28+
29+
def test_to_dataframe(setup):
30+
new_client = setup
31+
df = new_client.to_dataframe()
32+
assert isinstance(df, pd.DataFrame)

0 commit comments

Comments
 (0)