-
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.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 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 |
---|---|---|
|
@@ -3,7 +3,9 @@ | |
import pandas as pd | ||
import pytest | ||
import sharepy | ||
from viadot.exceptions import CredentialError | ||
from viadot.sources import Sharepoint | ||
from viadot.sources.sharepoint import SharepointCredentials | ||
|
||
DUMMY_CREDS = {"site": "test", "username": "test2", "password": "test"} | ||
SAMPLE_DF = pd.DataFrame( | ||
|
@@ -30,6 +32,27 @@ def sharepoint_mock(): | |
return SharepointMock(credentials=DUMMY_CREDS) | ||
|
||
|
||
def test_valid_credentials(): | ||
credentials = { | ||
"site": "tenant.sharepoint.com", | ||
"username": "[email protected]", | ||
"password": "password", | ||
} | ||
shrp_creds = SharepointCredentials(**credentials) | ||
assert shrp_creds.site == credentials["site"] | ||
assert shrp_creds.username == credentials["username"] | ||
assert shrp_creds.password == credentials["password"] | ||
|
||
|
||
def test_missing_username(): | ||
credentials = {"site": "example.sharepoint.com", "password": "password"} | ||
with pytest.raises( | ||
CredentialError, | ||
match="'site', 'username', and 'password' credentials are required.", | ||
): | ||
SharepointCredentials(**credentials) | ||
|
||
|
||
def test_sharepoint_default_na(sharepoint_mock): | ||
df = sharepoint_mock.to_df( | ||
url="test/file.xlsx", na_values=Sharepoint.DEFAULT_NA_VALUES | ||
|
@@ -90,3 +113,8 @@ def test__parse_excel_string_dtypes(sharepoint_mock): | |
|
||
for column in result_df.columns: | ||
assert result_df[column].dtype == object | ||
|
||
|
||
def test__load_and_parse_not_valid_extension(sharepoint_mock): | ||
with pytest.raises(ValueError): | ||
sharepoint_mock._load_and_parse(file_url="https://example.com/file.txt") |