Skip to content

Commit

Permalink
APP-4522
Browse files Browse the repository at this point in the history
  • Loading branch information
bpurdy-tc committed Jun 27, 2024
1 parent 48a4b86 commit 821e83d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
7 changes: 1 addition & 6 deletions tcex/api/tc/v3/_gen/_gen_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,7 @@ def tap(self, type_: str):
]:
return 'tcex.api.tc.v3.security'

if type_.plural().lower() in [
'categories',
'results',
'subtypes',
'keyword_sections'
]:
if type_.plural().lower() in ['categories', 'results', 'subtypes', 'keyword_sections']:
return 'tcex.api.tc.v3.intel_requirements'

return 'tcex.api.tc.v3'
4 changes: 3 additions & 1 deletion tcex/api/tc/v3/_gen/_gen_object_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ def as_entity(self) -> dict:
)
return '\n'.join(as_entity_property_method)

def _gen_code_object_replace_type_method(self, type_: str, model_type: str | None = None) -> str:
def _gen_code_object_replace_type_method(
self, type_: str, model_type: str | None = None
) -> str:
"""Return the method code.
def replace_artifact(self, **kwargs):
Expand Down
7 changes: 3 additions & 4 deletions tcex/api/tc/v3/intel_requirements/intel_requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,16 @@ def replace_keyword_section(self, data: dict | list | ObjectABC | KeywordSection
if not isinstance(data, list):
data = [data]

if (
isinstance(data, list) and
all(isinstance(item, (ObjectABC, KeywordSectionModel)) for item in data)
if isinstance(data, list) and all(
isinstance(item, (ObjectABC, KeywordSectionModel)) for item in data
):
transformed_data = data
elif isinstance(data, list) and all(isinstance(item, dict) for item in data):
transformed_data = [KeywordSectionModel(**d) for d in data]
elif isinstance(data, dict):
transformed_data = KeywordSectionModel(**data)
else:
raise ValueError("Invalid data to replace_keyword_section")
raise ValueError('Invalid data to replace_keyword_section')

if isinstance(transformed_data, list):
for item in transformed_data:
Expand Down
7 changes: 4 additions & 3 deletions tcex/api/tc/v3/v3_model_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ def __init__(self, **kwargs):
# this rule.
# pylint: disable=no-member
if (
kwargs and hasattr(self, 'id') and
self.id is None and
self.__config__.title != 'Keyword Section Model'
kwargs
and hasattr(self, 'id')
and self.id is None
and self.__config__.title != 'Keyword Section Model'
):
self._staged = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
# third-party
import pytest

from tcex.api.tc.v3.intel_requirements.keyword_sections.keyword_section_model import \
KeywordSectionModel
# first-party
from tcex.api.tc.v3.intel_requirements.keyword_sections.keyword_section_model import (
KeywordSectionModel,
)
from tcex.api.tc.v3.tql.tql_operator import TqlOperator
from tests.api.tc.v3.v3_helpers import TestV3, V3Helper

Expand Down Expand Up @@ -90,15 +91,11 @@ def test_keywords_section(self):
ir = self.v3_helper.create_ir()
keyword_sections = [
KeywordSectionModel(
section_number=0,
compare_value='includes',
keywords=[{'value': 'keyword1'}]
section_number=0, compare_value='includes', keywords=[{'value': 'keyword1'}]
),
KeywordSectionModel(
section_number=1,
compare_value='includes',
keywords=[{'value': 'keyword2'}]
)
section_number=1, compare_value='includes', keywords=[{'value': 'keyword2'}]
),
]
ir.replace_keyword_section(keyword_sections)
ir.update()
Expand Down

0 comments on commit 821e83d

Please sign in to comment.