-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: connector must know contribute a logo
BREAKING CHANGE: Each connector is now expected to have a logo in it's root directory
- Loading branch information
1 parent
bec76b4
commit c67aef4
Showing
8 changed files
with
365 additions
and
55 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,148 @@ | ||
import json | ||
import tempfile | ||
from pathlib import Path | ||
|
||
import pytest | ||
from PIL import Image | ||
|
||
from hrflow_connectors import hrflow_connectors_manifest | ||
from hrflow_connectors.core.connector import ( | ||
MAX_LOGO_PIXEL, | ||
MAX_LOGO_SIZE_BYTES, | ||
MIN_LOGO_PIXEL, | ||
) | ||
from tests.core.test_connector import SmartLeadsF | ||
|
||
|
||
@pytest.fixture | ||
def manifest_directory(): | ||
path = Path(__file__).parent | ||
yield path | ||
manifest = path / "manifest.json" | ||
try: | ||
manifest.unlink() | ||
except FileNotFoundError: | ||
pass | ||
|
||
|
||
def test_connector_manifest(test_connectors_directory): | ||
SmartLeadsF().manifest(test_connectors_directory) | ||
|
||
|
||
def test_hrflow_connectors_manifest(manifest_directory, test_connectors_directory): | ||
manifest = Path(__file__).parent / "manifest.json" | ||
assert manifest.exists() is False | ||
|
||
connectors = [SmartLeadsF(), SmartLeadsF()] | ||
hrflow_connectors_manifest( | ||
connectors=connectors, | ||
directory_path=manifest_directory, | ||
connectors_directory=test_connectors_directory, | ||
) | ||
|
||
assert manifest.exists() is True | ||
assert len(json.loads(manifest.read_text())["connectors"]) == len(connectors) | ||
|
||
|
||
def test_manifest_connector_directory_not_found(test_connectors_directory): | ||
SmartLeads = SmartLeadsF() | ||
SmartLeads.model.name = "SmartLeadsX" | ||
with pytest.raises(ValueError) as excinfo: | ||
SmartLeads.manifest(test_connectors_directory) | ||
|
||
assert "No directory found for connector SmartLeadsX" in excinfo.value.args[0] | ||
assert "/src/hrflow_connectors/connectors/smartleadsx" in excinfo.value.args[0] | ||
|
||
|
||
def test_manifest_logo_is_missing(test_connectors_directory): | ||
LocalUsers = SmartLeadsF() | ||
LocalUsers.model.name = "LocalUsers" | ||
with pytest.raises(ValueError) as excinfo: | ||
LocalUsers.manifest(test_connectors_directory) | ||
|
||
assert "Missing logo for connector LocalUsers" in excinfo.value.args[0] | ||
assert "/src/hrflow_connectors/connectors/localusers" in excinfo.value.args[0] | ||
|
||
|
||
def test_manifest_more_than_one_logo(test_connectors_directory): | ||
with tempfile.NamedTemporaryFile( | ||
dir=test_connectors_directory / "smartleads", | ||
prefix="logo.", | ||
): | ||
with pytest.raises(ValueError) as excinfo: | ||
SmartLeadsF().manifest(test_connectors_directory) | ||
|
||
assert "Found multiple logos for connector SmartLeads" in excinfo.value.args[0] | ||
|
||
|
||
def test_manifest_logo_above_size_limit(test_connectors_directory): | ||
above_limit_size = 2 * MAX_LOGO_SIZE_BYTES | ||
with tempfile.NamedTemporaryFile( | ||
"wb", | ||
buffering=0, | ||
dir=test_connectors_directory / "localusers", | ||
prefix="logo.", | ||
) as large_logo: | ||
large_logo.write(bytes([255] * above_limit_size)) | ||
LocalUsers = SmartLeadsF() | ||
LocalUsers.model.name = "LocalUsers" | ||
with pytest.raises(ValueError) as excinfo: | ||
LocalUsers.manifest(test_connectors_directory) | ||
|
||
assert ( | ||
f"Logo size {above_limit_size // 1024} KB for connector LocalUsers is" | ||
f" above maximum limit of {MAX_LOGO_SIZE_BYTES // 1024 } KB" | ||
in excinfo.value.args[0] | ||
) | ||
|
||
|
||
def test_manifest_logo_not_valid_image(test_connectors_directory): | ||
with tempfile.NamedTemporaryFile( | ||
"wb", | ||
buffering=0, | ||
dir=test_connectors_directory / "localusers", | ||
prefix="logo.", | ||
): | ||
LocalUsers = SmartLeadsF() | ||
LocalUsers.model.name = "LocalUsers" | ||
with pytest.raises(ValueError) as excinfo: | ||
LocalUsers.manifest(test_connectors_directory) | ||
|
||
assert "Logo file for connector LocalUsers" in excinfo.value.args[0] | ||
assert "doesn't seem to be a valid image" in excinfo.value.args[0] | ||
|
||
|
||
MIDDLE_SIZE = (MIN_LOGO_PIXEL + MAX_LOGO_PIXEL) // 2 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"shape", | ||
[ | ||
(MAX_LOGO_PIXEL + 1, MIDDLE_SIZE), | ||
(MIN_LOGO_PIXEL - 1, MIDDLE_SIZE), | ||
(MIDDLE_SIZE, MAX_LOGO_PIXEL + 1), | ||
(MIDDLE_SIZE, MIN_LOGO_PIXEL - 1), | ||
(MAX_LOGO_PIXEL + 1, MIN_LOGO_PIXEL - 1), | ||
(MIN_LOGO_PIXEL - 1, MAX_LOGO_PIXEL + 1), | ||
(MAX_LOGO_PIXEL + 1, MAX_LOGO_PIXEL + 1), | ||
(MIN_LOGO_PIXEL - 1, MIN_LOGO_PIXEL - 1), | ||
], | ||
) | ||
def test_manifest_logo_bad_dimension(test_connectors_directory, shape): | ||
original = Image.open(test_connectors_directory / "smartleads" / "logo.png") | ||
with tempfile.NamedTemporaryFile( | ||
"wb", | ||
buffering=0, | ||
dir=test_connectors_directory / "localusers", | ||
prefix="logo.", | ||
suffix=".png", | ||
) as bad_shape_logo: | ||
resized = original.resize(shape) | ||
resized.save(bad_shape_logo) | ||
|
||
LocalUsers = SmartLeadsF() | ||
LocalUsers.model.name = "LocalUsers" | ||
with pytest.raises(ValueError) as excinfo: | ||
LocalUsers.manifest(test_connectors_directory) | ||
|
||
assert "Bad logo dimensions" in excinfo.value.args[0] |
Oops, something went wrong.