Skip to content

Commit

Permalink
fix: made all properties of ExtractionPipelineContact optional
Browse files Browse the repository at this point in the history
  • Loading branch information
doctrino committed Dec 4, 2024
1 parent 126d0c9 commit ae8322b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
25 changes: 11 additions & 14 deletions cognite/client/data_classes/extractionpipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,24 @@ class ExtractionPipelineContact(CogniteObject):
"""A contact for an extraction pipeline
Args:
name (str): Name of contact
email (str): Email address of contact
role (str): Role of contact, such as Owner, Maintainer, etc.
send_notification (bool): Whether to send notifications to this contact or not
name (str | None): Name of contact
email (str | None): Email address of contact
role (str | None): Role of contact, such as Owner, Maintainer, etc.
send_notification (bool | None): Whether to send notifications to this contact or not
"""

def __init__(self, name: str, email: str, role: str, send_notification: bool) -> None:
def __init__(
self,
name: str | None = None,
email: str | None = None,
role: str | None = None,
send_notification: bool | None = None,
) -> None:
self.name = name
self.email = email
self.role = role
self.send_notification = send_notification

@classmethod
def _load(cls, resource: dict, cognite_client: CogniteClient | None = None) -> ExtractionPipelineContact:
return cls(
name=resource["name"],
email=resource["email"],
role=resource["role"],
send_notification=resource["sendNotification"],
)


@dataclass
class ExtractionPipelineNotificationConfiguration(CogniteObject):
Expand Down
29 changes: 29 additions & 0 deletions tests/tests_unit/test_data_classes/test_extraction_pipipelines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from typing import Any

import pytest

from cognite.client.data_classes.extractionpipelines import ExtractionPipelineContact


class TestExtractionPipeline:
@pytest.mark.parametrize(
"raw, expected",
[
pytest.param(
{"name": "Homer", "email": "[email protected]"},
ExtractionPipelineContact(name="Homer", email="[email protected]"),
id="Partial Contact",
),
pytest.param(
{"name": "Marge", "email": "[email protected]", "role": "Wife", "sendNotification": True},
ExtractionPipelineContact(
name="Marge", email="[email protected]", role="Wife", send_notification=True
),
id="Full Contact",
),
],
)
def test_load_dump_contracts(self, raw: dict[str, Any], expected: ExtractionPipelineContact) -> None:
loaded = ExtractionPipelineContact._load(raw)
assert loaded == expected
assert raw == loaded.dump()

0 comments on commit ae8322b

Please sign in to comment.