Skip to content

Commit

Permalink
Merge pull request #205 from dyvenia/dev
Browse files Browse the repository at this point in the history
Release 0.2.12
  • Loading branch information
m-paz authored Nov 25, 2021
2 parents 36719f1 + db19f57 commit 7f1630f
Show file tree
Hide file tree
Showing 24 changed files with 1,088 additions and 401 deletions.
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,43 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased]

## [0.2.12]
### Added
- Added `Sharepoint` source
- Added `SharepointToDF` task
- Added `SharepointToADLS` flow
- Added `CloudForCustomers` source
- Added `c4c_report_to_df` taks
- Added `def c4c_to_df` task
- Added `CloudForCustomersReportToADLS` flow
- Added `df_to_csv` task to task_utils.py
- Added `df_to_parquet` task to task_utils.py
- Added `dtypes_to_json` task to task_utils.py
## [0.2.11]
### Fixed
- `ADLSToAzureSQL` - fixed path to csv issue.
- `SupermetricsToADLS` - fixed local json path issue.

## [0.2.10] - 2021-10-29
### Release due to CI/CD error

## [0.2.9] - 2021-10-29
### Release due to CI/CD error

## [0.2.8] - 2021-10-29
### Changed
- CI/CD: `dev` image is now only published on push to the `dev` branch
- Docker:
- updated registry links to use the new `ghcr.io` domain
- `run.sh` now also accepts the `-t` option. When run in standard mode, it will only spin up the `viadot_jupyter_lab` service.
When ran with `-t dev`, it will also spin up `viadot_testing` and `viadot_docs` containers.

### Fixed
- `ADLSToAzureSQL` - fixed path parameter issue.

## [0.2.11]
### Fixed
- ADLSToAzureSQL - fixed path to csv issue.
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ PyGithub==1.55
Shapely==1.8.0
imagehash==4.2.1
visions==0.7.4
sharepy==1.3.0
29 changes: 29 additions & 0 deletions tests/integration/flows/test_cloud_for_customers_report_to_adls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from viadot.flows import CloudForCustomersReportToADLS
from viadot.config import local_config


def test_cloud_for_customers_report_to_adls():
credentials = local_config.get("CLOUD_FOR_CUSTOMERS")
credentials_prod = credentials["Prod"]
channels = ["VEL_B_AFS", "VEL_B_ASA"]
month = ["01"]
year = ["2021"]
flow = CloudForCustomersReportToADLS(
direct_url=credentials_prod["server"],
source_type="Prod",
channels=channels,
months=month,
years=year,
name="test_c4c_report_to_adls",
local_file_path=f"test_c4c_report_to_adls.csv",
adls_sp_credentials_secret=credentials["adls_sp_credentials_secret"],
adls_dir_path=credentials["adls_dir_path"],
)
number_of_urls = len(month) * len(year) * len(channels)
assert len(flow.report_urls_with_filters) == number_of_urls

result = flow.run()
assert result.is_successful()

task_results = result.result.values()
assert all([task_result.is_successful() for task_result in task_results])
20 changes: 0 additions & 20 deletions tests/integration/flows/test_cloud_for_customers_to_adls.py

This file was deleted.

10 changes: 6 additions & 4 deletions tests/integration/test_cloud_for_customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
def cloud_for_customers():
url = "http://services.odata.org/V2/Northwind/Northwind.svc/"
endpoint = "Employees"
cloud_for_customers = CloudForCustomers(url=url, endpoint=endpoint)
cloud_for_customers = CloudForCustomers(
url=url, endpoint=endpoint, params={"$top": "2"}
)
yield cloud_for_customers
os.remove(TEST_FILE_1)

Expand All @@ -36,10 +38,10 @@ def test_csv(cloud_for_customers):


def test_credentials():
credentials = local_config.get("CLOUD_FOR_CUSTOMERS")
url = credentials["server"]
qa_credentials = local_config.get("CLOUD_FOR_CUSTOMERS")["QA"]
url = qa_credentials["server"]
endpoint = "ServiceRequestCollection"
c4c = CloudForCustomers(url=url, endpoint=endpoint)
c4c = CloudForCustomers(url=url, endpoint=endpoint, params={"$top": "2"})
df = c4c.to_df(
fields=["ProductRecipientPartyName", "CreationDateTime", "CreatedBy"]
)
Expand Down
61 changes: 61 additions & 0 deletions tests/integration/test_sharepoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pytest
import os
import pathlib
import pandas as pd
from typing import List

from viadot.sources import Sharepoint
from viadot.flows import SharepointToADLS as s_flow
from viadot.config import local_config
from viadot.task_utils import df_get_data_types_task

s = Sharepoint()

FILE_NAME = "EUL Data.xlsm"
s.download_file(download_to_path=FILE_NAME)
DF = pd.read_excel(FILE_NAME, sheet_name=0)


def test_credentials():
credentials = {"site": "tenant.sharepoint.com", "username": "User"}
s = Sharepoint(credentials=credentials)
with pytest.raises(ValueError, match="Missing credentials."):
s.get_connection()


def test_connection():
credentials = local_config.get("SHAREPOINT")
site = f'https://{credentials["site"]}'
conn = s.get_connection()
response = conn.get(site)
assert response.status_code == 200


def test_file_extension():
file_ext = [".xlsm", ".xlsx"]
assert pathlib.Path(s.download_from_path).suffix in file_ext


def test_file_name():
assert os.path.basename(s.download_from_path) == FILE_NAME


def test_file_download():
s.download_file(download_to_path=FILE_NAME)
files = []
for file in os.listdir():
if os.path.isfile(os.path.join(file)):
files.append(file)
assert FILE_NAME in files
os.remove(FILE_NAME)


def test_file_to_df():
df_test = pd.DataFrame(data={"col1": [1, 2]})
assert type(DF) == type(df_test)


def test_get_data_types():
dtypes_map = df_get_data_types_task.run(DF)
dtypes = [v for k, v in dtypes_map.items()]
assert "String" in dtypes
2 changes: 1 addition & 1 deletion tests/test_viadot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_version():
assert __version__ == "0.2.11"
assert __version__ == "0.2.12"
34 changes: 34 additions & 0 deletions tests/unit/test_task_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
import pandas as pd
from typing import List

from viadot.task_utils import df_get_data_types_task, df_map_mixed_dtypes_for_parquet


def count_dtypes(dtypes_dict: dict = None, dtypes_to_count: List[str] = None) -> int:
dtypes_counter = 0
for v in dtypes_dict.values():
if v in dtypes_to_count:
dtypes_counter += 1
return dtypes_counter


def test_map_dtypes_for_parquet():
df = pd.DataFrame(
{
"a": {0: 55.7, 1: "Hello", 2: "Hello"},
"b": {0: "Start", 1: "Hello", 2: "Hello"},
"w": {0: 679, 1: "Hello", 2: "Hello"},
"x": {0: 1, 1: 2, 2: 444},
"y": {0: 1.5, 1: 11.97, 2: 56.999},
"z": {0: "Start", 1: 1, 2: "2021-01-01"},
}
)
dtyps_dict = df_get_data_types_task.run(df)
sum_of_dtypes = count_dtypes(dtyps_dict, ["Object", "String"])

df_map = df_map_mixed_dtypes_for_parquet.run(df, dtyps_dict)
dtyps_dict_mapped = df_get_data_types_task.run(df_map)
sum_of_mapped_dtypes = count_dtypes(dtyps_dict_mapped, ["String"])

assert sum_of_dtypes == sum_of_mapped_dtypes
2 changes: 1 addition & 1 deletion viadot/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.11"
__version__ = "0.2.12"
6 changes: 6 additions & 0 deletions viadot/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ValidationError(Exception):
pass


class APIError(Exception):
pass
3 changes: 2 additions & 1 deletion viadot/flows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
from .supermetrics_to_adls import SupermetricsToADLS
from .supermetrics_to_azure_sql import SupermetricsToAzureSQL
from .adls_container_to_container import ADLSContainerToContainer
from .cloud_for_customers_to_adls import CloudForCustomersToADLS
from .sharepoint_to_adls import SharepointToADLS
from .cloud_for_customers_report_to_adls import CloudForCustomersReportToADLS
Loading

0 comments on commit 7f1630f

Please sign in to comment.