-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from dyvenia/dev
Release 0.4.9 PR
- Loading branch information
Showing
26 changed files
with
1,479 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -156,4 +156,6 @@ desktop.ini | |
sap_netweaver_rfc | ||
|
||
# Databricks-connect | ||
|
||
.databricks-connect | ||
|
This file contains 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 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 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 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,27 @@ | ||
import os | ||
import pytest | ||
from unittest import mock | ||
from viadot.tasks import MindfulToCSV | ||
|
||
|
||
class MockClass: | ||
status_code = 200 | ||
content = b'[{"id":7277599,"survey_id":505,"phone_number":"","survey_type":"inbound"},{"id":7277294,"survey_id":504,"phone_number":"","survey_type":"web"}]' | ||
|
||
|
||
@pytest.mark.init | ||
def test_instance_mindful(): | ||
mf = MindfulToCSV() | ||
assert isinstance(mf, MindfulToCSV) | ||
|
||
|
||
@mock.patch("viadot.sources.mindful.handle_api_response", return_value=MockClass) | ||
@pytest.mark.run | ||
def test_mindful_run(mock_interactions): | ||
mf = MindfulToCSV() | ||
mf.run() | ||
mock_interactions.call_count == 2 | ||
assert os.path.exists("interactions.csv") | ||
os.remove("interactions.csv") | ||
assert os.path.exists("responses.csv") | ||
os.remove("responses.csv") |
This file contains 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,85 @@ | ||
import os | ||
import pytest | ||
from unittest import mock | ||
from viadot.sources import Mindful | ||
from viadot.config import local_config | ||
|
||
credentials_mindful = local_config["MINDFUL"] | ||
|
||
|
||
class MockClass: | ||
status_code = 200 | ||
content = b'[{"id":7277599,"survey_id":505,"phone_number":"","survey_type":"inbound"},{"id":7277294,"survey_id":504,"phone_number":"","survey_type":"web"}]' | ||
|
||
def json(): | ||
test = [ | ||
{ | ||
"id": 7277599, | ||
"survey_id": 505, | ||
"phone_number": "", | ||
"survey_type": "inbound", | ||
}, | ||
{"id": 7277294, "survey_id": 504, "phone_number": "", "survey_type": "web"}, | ||
] | ||
return test | ||
|
||
|
||
@pytest.mark.init | ||
def test_instance_mindful(): | ||
mf = Mindful(credentials_mindful=credentials_mindful) | ||
assert isinstance(mf, Mindful) | ||
|
||
|
||
@pytest.mark.init | ||
def test_credentials_instance(): | ||
mf = Mindful(credentials_mindful=credentials_mindful) | ||
assert mf.credentials_mindful != None and isinstance(mf.credentials_mindful, dict) | ||
|
||
|
||
@mock.patch("viadot.sources.mindful.handle_api_response", return_value=MockClass) | ||
@pytest.mark.connect | ||
def test_mindful_api_response(mock_connection): | ||
mf = Mindful(credentials_mindful=credentials_mindful) | ||
mf.get_interactions_list() | ||
mf.get_responses_list() | ||
mock_connection.call_count == 2 | ||
|
||
|
||
@mock.patch("viadot.sources.mindful.handle_api_response", return_value=MockClass) | ||
@pytest.mark.connect | ||
def test_mindful_api_response2(mock_api_response): | ||
mf = Mindful(credentials_mindful=credentials_mindful) | ||
response = mf.get_interactions_list() | ||
|
||
assert response.status_code == 200 and isinstance(response.json(), list) | ||
assert mf.endpoint == "interactions" | ||
|
||
|
||
@mock.patch("viadot.sources.mindful.handle_api_response", return_value=MockClass) | ||
@pytest.mark.connect | ||
def test_mindful_api_response3(mock_api_response): | ||
mf = Mindful(credentials_mindful=credentials_mindful) | ||
response = mf.get_responses_list() | ||
|
||
assert response.status_code == 200 and isinstance(response.json(), list) | ||
assert mf.endpoint == "responses" | ||
|
||
|
||
@mock.patch("viadot.sources.Mindful._mindful_api_response", return_value=MockClass) | ||
@pytest.mark.save | ||
def test_mindful_interactions(mock_connection): | ||
mf = Mindful(credentials_mindful=credentials_mindful) | ||
response = mf.get_interactions_list() | ||
mf.response_to_file(response) | ||
assert os.path.exists("interactions.csv") | ||
os.remove("interactions.csv") | ||
|
||
|
||
@mock.patch("viadot.sources.Mindful._mindful_api_response", return_value=MockClass) | ||
@pytest.mark.save | ||
def test_mindful_responses(mock_connection): | ||
mf = Mindful(credentials_mindful=credentials_mindful) | ||
response = mf.get_responses_list() | ||
mf.response_to_file(response) | ||
assert os.path.exists("responses.csv") | ||
os.remove("responses.csv") |
This file contains 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 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,123 @@ | ||
from viadot.sources.sftp import SftpConnector | ||
from viadot.tasks.sftp import SftpToDF, SftpList | ||
import pytest | ||
import pandas as pd | ||
from unittest import mock | ||
from pytest import fixture, raises | ||
import io | ||
|
||
|
||
@pytest.fixture | ||
def tmp_df(): | ||
data = {"country": [1, 2], "sales": [3, 4]} | ||
df = pd.DataFrame(data=data) | ||
return df | ||
|
||
|
||
@pytest.fixture | ||
def list_of_paths(): | ||
|
||
list_of_paths = [ | ||
"Country__Context30##exported.tsv", | ||
"Country__Context31##exported.tsv", | ||
"Country__Context32##exported.tsv", | ||
"Country__Context33##exported.tsv", | ||
"Country__Context4##exported.tsv", | ||
"Country__Context6##exported.tsv", | ||
"Country__Context7##exported.tsv", | ||
"Country__Context8##exported.tsv", | ||
"Local_Products.csv", | ||
"Products Checkup.tsv", | ||
"Products.tsv", | ||
"RewardTest.csv", | ||
] | ||
return list_of_paths | ||
|
||
|
||
@pytest.fixture | ||
def df_buf(): | ||
s_buf = io.StringIO() | ||
|
||
data = {"country": [1, 2], "sales": [3, 4]} | ||
df = pd.DataFrame(data=data) | ||
df.to_csv(s_buf) | ||
return s_buf | ||
|
||
|
||
def test_create_sftp_instance(): | ||
s = SftpConnector( | ||
credentials_sftp={"HOSTNAME": 1, "USERNAME": 2, "PASSWORD": 3, "PORT": 4} | ||
) | ||
assert s | ||
|
||
|
||
def test_connection_sftp(tmp_df): | ||
with mock.patch("viadot.sources.sftp.SftpConnector.to_df") as mock_method: | ||
mock_method.return_value = tmp_df | ||
s = SftpConnector( | ||
credentials_sftp={"HOSTNAME": 1, "USERNAME": 2, "PASSWORD": 3, "PORT": 4} | ||
) | ||
|
||
final_df = s.to_df() | ||
assert isinstance(final_df, pd.DataFrame) | ||
|
||
|
||
def test_getfo_file(df_buf): | ||
with mock.patch("viadot.sources.sftp.SftpConnector.getfo_file") as mock_method: | ||
mock_method.return_value = df_buf | ||
s = SftpConnector( | ||
credentials_sftp={"HOSTNAME": 1, "USERNAME": 2, "PASSWORD": 3, "PORT": 4} | ||
) | ||
|
||
buffer_df = s.getfo_file() | ||
buffer_df.seek(0) | ||
df = pd.read_csv(buffer_df) | ||
assert isinstance(df, pd.DataFrame) | ||
|
||
|
||
def test_ls_sftp(list_of_paths): | ||
with mock.patch("viadot.sources.sftp.SftpConnector.list_directory") as mock_method: | ||
mock_method.return_value = list_of_paths | ||
s = SftpConnector( | ||
credentials_sftp={"HOSTNAME": 1, "USERNAME": 2, "PASSWORD": 3, "PORT": 4} | ||
) | ||
|
||
paths = s.list_directory() | ||
|
||
assert isinstance(paths, list) | ||
|
||
|
||
def test_get_exported_files(list_of_paths): | ||
with mock.patch.object( | ||
SftpConnector, "get_exported_files", return_value=list_of_paths | ||
) as mock_method: | ||
|
||
s = SftpConnector( | ||
credentials_sftp={"HOSTNAME": 1, "USERNAME": 2, "PASSWORD": 3, "PORT": 4} | ||
) | ||
filtered_paths = s.get_exported_files() | ||
|
||
assert isinstance(filtered_paths, list) | ||
|
||
|
||
def test_task_sftptodf(tmp_df): | ||
task = SftpToDF() | ||
with mock.patch.object(SftpToDF, "run", return_value=tmp_df) as mock_method: | ||
df = task.run() | ||
|
||
assert isinstance(df, pd.DataFrame) | ||
|
||
|
||
def test_task_sftplist(list_of_paths): | ||
task = SftpList() | ||
with mock.patch.object(SftpList, "run", return_value=list_of_paths) as mock_method: | ||
list_directory = task.run() | ||
|
||
assert isinstance(list_directory, list) | ||
|
||
|
||
def test_example(): | ||
with mock.patch("viadot.sources.sftp.SftpConnector.to_df") as mock_method: | ||
mock_method.return_value = tmp_df | ||
t = SftpToDF() | ||
t.run() |
This file contains 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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
def test_version(): | ||
assert __version__ == "0.4.8" | ||
assert __version__ == "0.4.9" |
This file contains 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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.4.8" | ||
__version__ = "0.4.9" |
This file contains 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 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
Oops, something went wrong.