Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network_segments first commit - passes lint and test #22

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/reference/models_classic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ Computer Groups
ClassicComputerGroupMember
ClassicComputerGroupCriterion
ClassicComputerGroupCriterionSearchType

Network Segments
----------------

.. currentmodule:: jamf_pro_sdk.models.classic.network_segments

.. autosummary::
:toctree: _autosummary
:nosignatures:

ClassicNetworkSegment
ClassicNetworkSegmentsItem
54 changes: 54 additions & 0 deletions src/jamf_pro_sdk/models/classic/network_segments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from typing import Optional

from pydantic import Extra

from .. import BaseModel
from . import ClassicApiModel

_XML_ARRAY_ITEM_NAMES = {}


class ClassicNetworkSegmentItem(BaseModel, extra=Extra.allow):
"""Represents a network_segment record returned by the
:meth:`~jamf_pro_sdk.clients.classic_api.ClassicApi.list_network_segments` operation.
"""

id: Optional[int]
name: Optional[str]
starting_address: Optional[str]
ending_address: Optional[str]


class ClassicNetworkSegment(ClassicApiModel):
"""Represents a network_segment record returned by the
:meth:`~jamf_pro_sdk.clients.classic_api.ClassicApi.get_network_segment_by_id` operation.
"""

_xml_root_name = "network_segment"
_xml_array_item_names = _XML_ARRAY_ITEM_NAMES
_xml_write_fields = {
"name",
"starting_address",
"ending_address",
"distribution_server",
"distribution_point",
"url",
"swu_server",
"building",
"department",
"override_buildings",
"override_departments",
}

id: Optional[int]
name: Optional[str]
starting_address: Optional[str]
ending_address: Optional[str]
distribution_server: Optional[str]
distribution_point: Optional[str]
url: Optional[str]
swu_server: Optional[str]
building: Optional[str]
department: Optional[str]
override_buildings: Optional[bool]
override_departments: Optional[bool]
44 changes: 44 additions & 0 deletions tests/models/test_models_classic_network_segments
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import json

from deepdiff import DeepDiff
from src.jamf_pro_sdk.models.classic.network_segments import ClassicNetworkSegment

NETWORK_SEGMENT_JSON = {
"network_segment": {
"id": 1,
"name": "Test Network",
"starting_address": "192.168.1.31",
"ending_address": "192.168.7.255",
"distribution_point": "Cloud Distribution Point",
"url": "https://use1-jcds.services.jamfcloud.com/download/66d8960449b44a668c38e4dddbe094d7",
"building": "Test Building",
"department": "Test Department",
}
}


def test_network_segment_model_parsings():
"""Verify select attributes across the NetworkSegment model."""
network_segment = ClassicNetworkSegment(**NETWORK_SEGMENT_JSON["network_segment"])

assert network_segment is not None # mypy
assert network_segment.name == "Test Network"
assert network_segment.starting_address == "192.168.1.31"
assert network_segment.ending_address == "192.168.7.255"
assert network_segment.id == 1
assert network_segment.distribution_point == "Cloud Distribution Point"
assert (
network_segment.url
== "https://use1-jcds.services.jamfcloud.com/download/66d8960449b44a668c38e4dddbe094d7"
)
assert network_segment.building == "Test Building"
assert network_segment.department == "Test Department"


def test_network_segment_model_json_output_matches_input():
network_segment = ClassicNetworkSegment(**NETWORK_SEGMENT_JSON["network_segment"])
serialized_output = json.loads(network_segment.json(exclude_none=True))

diff = DeepDiff(NETWORK_SEGMENT_JSON["network_segment"], serialized_output, ignore_order=True)

assert not diff