Skip to content

Commit

Permalink
Merge pull request #15 from Honestpuck/Honestpuck-documentation_Categ…
Browse files Browse the repository at this point in the history
…ories

Honestpuck documentation categories
  • Loading branch information
brysontyrrell committed Oct 14, 2023
2 parents f3dd57f + 5dbbe55 commit edc89e3
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/reference/models_classic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ Shared Models
ClassicDevicePurchasing
ClassicSite

Categories
----------

.. currentmodule:: jamf_pro_sdk.models.classic.categories

.. autosummary::
:toctree: _autosummary

ClassicCategory
ClassicCategoriesItem

Computers
---------

Expand Down
37 changes: 37 additions & 0 deletions src/jamf_pro_sdk/models/classic/categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Optional

from pydantic import Extra

from .. import BaseModel
from . import ClassicApiModel

_XML_ARRAY_ITEM_NAMES = {}


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

id: Optional[int]
name: Optional[str]
priority: Optional[int]


class ClassicCategory(ClassicApiModel):
"""Represents a category record returned by the
:meth:`~jamf_pro_sdk.clients.classic_api.ClassicApi.get_category_by_id` operation.
When exporting to XML for a ``POST``/``PUT`` operation, the SDK by default will only
include ``name``, and ``priority. To bypass this
behavior export the model using :meth:`~jamf_pro_sdk.models.classic.ClassicApiModel.xml` before
pasting to the API operation.
"""

_xml_root_name = "category"
_xml_array_item_names = _XML_ARRAY_ITEM_NAMES
_xml_write_fields = {"name", "priority"}

id: Optional[int]
name: Optional[str]
priority: Optional[int]
25 changes: 25 additions & 0 deletions tests/models/test_models_classic_categories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import json

from deepdiff import DeepDiff
from src.jamf_pro_sdk.models.classic.categories import ClassicCategory

CATEGORY_JSON = {"category": {"id": 1, "name": "Test Category", "priority": 1}}


def test_category_model_parsings():
"""Verify select attributes across the ComputerGroup model."""
category = ClassicCategory(**CATEGORY_JSON["category"])

assert category is not None # mypy
assert category.name == "Test Category"
assert category.priority == 1
assert category.id == 1


def test_category_model_json_output_matches_input():
category = ClassicCategory(**CATEGORY_JSON["category"])
serialized_output = json.loads(category.json(exclude_none=True))

diff = DeepDiff(CATEGORY_JSON["category"], serialized_output, ignore_order=True)

assert not diff

0 comments on commit edc89e3

Please sign in to comment.