Skip to content

Commit

Permalink
[pre-commit pycln] Align the entire repo with pycln (demisto#29611)
Browse files Browse the repository at this point in the history
* Fix falls of the pycln hook

* pre-commit

* Fix unit test

* Add RN

* Fix validate in GetDomainDNSDetails

* fuff on GetDomainDNSDetails

* ignore mypy error in test_content.py:350
  • Loading branch information
mmhw authored and wolyslager committed Oct 2, 2023
1 parent 56e174f commit 5a3ed7c
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 113 deletions.
@@ -1,7 +1,9 @@
import requests_mock
from ACTIIndicatorQuery import IDEFENSE_URL_TEMPLATE, Client, domain_command, url_command, ip_command, uuid_command, _calculate_dbot_score, getThreatReport_command, fix_markdown, addBaseUrlToPartialPaths, convert_inline_image_to_encoded, fundamental_uuid_command # noqa: E501
from CommonServerPython import DemistoException, DBotScoreReliability
from test_data.response_constants import *
from test_data.response_constants import URL_RES_JSON, URL_INTEL_JSON, IP_RES_JSON, IP_INTEL_JSON, DOMAIN_RES_JSON, \
DOMAIN_INTEL_JSON, UUID_RES_JSON, RES_JSON_IA, RES_JSON_IR, expected_output_ia, expected_output_ir, MALWARE_FAMILY_RES_JSON, \
expected_output_malware_family, RAW_MALWARE_FAMILY_RES_JSON
import demistomock as demisto
import pytest

Expand Down Expand Up @@ -231,10 +233,7 @@ def _is_intelligence_data_present_in_command_result(context_result, test_intel_j
if url not in content[content.find(title):content.find('|', content.find(title))]:
return False

for title, url in reports.items():
if url not in content[content.find(title):content.find('|', content.find(title))]:
return False
return True
return all(url in content[content.find(title):content.find("|", content.find(title))] for title, url in reports.items())


def test_uuid_command():
Expand Down
@@ -1,7 +1,6 @@
import json
import io
from ACTIVulnerabilityQuery import Client, vuln_command
from test_data.response_constants import *
from test_data.response_constants import VULN_RES_JSON
from CommonServerPython import DBotScoreReliability
import requests_mock

Expand All @@ -10,7 +9,7 @@


def util_load_json(path):
with io.open(path, mode='r', encoding='utf-8') as f:
with open(path, encoding='utf-8') as f:
return json.loads(f.read())


Expand Down
6 changes: 6 additions & 0 deletions Packs/CommonScripts/ReleaseNotes/1_12_23.md
@@ -0,0 +1,6 @@

#### Scripts

##### GetDomainDNSDetails

- Updated the Docker image to: *demisto/dnspython:1.0.0.73453*.
Expand Up @@ -3,12 +3,10 @@
from CommonServerUserPython import * # noqa # pylint: disable=unused-wildcard-import

from typing import (
Dict, Any, Optional,
Union, List
Any
)
import traceback

import dns.message
import dns.resolver
import dns.rdatatype
import dns.rdataclass
Expand All @@ -22,7 +20,7 @@
''' STANDALONE FUNCTION '''


def make_query(resolver: dns.resolver.Resolver, qname: str, qtype: str, use_tcp: bool) -> Dict[str, Any]:
def make_query(resolver: dns.resolver.Resolver, qname: str, qtype: str, use_tcp: bool) -> dict[str, Any]:
q_rdtype = dns.rdatatype.from_text(qtype)
q_rdclass = dns.rdataclass.from_text("IN")

Expand All @@ -41,7 +39,7 @@ def make_query(resolver: dns.resolver.Resolver, qname: str, qtype: str, use_tcp:
if ans.rrset is None:
return {}

result: Dict[str, List[str]] = {}
result: dict[str, list[str]] = {}

result[qtype] = [
rr.to_text()
Expand All @@ -55,9 +53,9 @@ def make_query(resolver: dns.resolver.Resolver, qname: str, qtype: str, use_tcp:
''' COMMAND FUNCTION '''


def get_domain_dns_details_command(args: Dict[str, Any]) -> CommandResults:
outputs: Optional[Dict[str, Dict[str, Any]]]
answer: Union[str, Dict[str, Any]]
def get_domain_dns_details_command(args: dict[str, Any]) -> CommandResults:
outputs: dict[str, dict[str, Any]] | None
answer: str | dict[str, Any]

server = args.get('server')
use_tcp = argToBoolean(args.get('use_tcp', 'Yes'))
Expand Down Expand Up @@ -88,7 +86,7 @@ def get_domain_dns_details_command(args: Dict[str, Any]) -> CommandResults:
}

markdown = tableToMarkdown(
f' Domain DNS Details for {qname}',
f'Domain DNS Details for {qname}',
answer,
headers=["domain", "server"] + qtypes
)
Expand Down
@@ -1,20 +1,20 @@
args:
- description: The domain to query
- description: The domain to query.
name: domain
required: true
- description: "IP of the DNS Server to use (default: system settings)"
- description: "IP of the DNS Server to use (default: system settings)."
name: server
- description: "Use TCP for the query (default: false)"
- description: "Use TCP for the query (default: false)."
name: use_tcp
auto: PREDEFINED
predefined:
- 'true'
- 'false'
defaultValue: 'false'
- description: "Comma separated list of query types (default: CNAME,NS,A,AAAA)"
- description: "Comma separated list of query types (default: CNAME,NS,A,AAAA)."
name: qtype
defaultValue: CNAME,NS,A,AAAA
comment: Returns DNS details for a domain
comment: Returns DNS details for a domain.
commonfields:
id: GetDomainDNSDetails
version: -1
Expand Down Expand Up @@ -43,5 +43,7 @@ tags: []
timeout: '0'
type: python
subtype: python3
dockerimage: demisto/dnspython:1.0.0.12410
dockerimage: demisto/dnspython:1.0.0.73453
fromversion: 5.0.0
tests:
- No tests (auto formatted)
@@ -1,4 +1,4 @@
from __future__ import print_function
from typing import Any
import pytest
from PositiveDetectionsVSDetectionEngines import extract_engines_data_from_indicator

Expand Down Expand Up @@ -134,8 +134,8 @@
}
}

no_engines_data = {
'CustomFields': {}, # type: dict[any: any]
no_engines_data: dict[str, Any] = {
'CustomFields': {},
'ManuallyEditedFields': None,
'account': '',
'calculatedTime': '2019-11-11T14:25:28.922329+02:00',
Expand Down
2 changes: 1 addition & 1 deletion Packs/CommonScripts/pack_metadata.json
Expand Up @@ -2,7 +2,7 @@
"name": "Common Scripts",
"description": "Frequently used scripts pack.",
"support": "xsoar",
"currentVersion": "1.12.22",
"currentVersion": "1.12.23",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
Expand Up @@ -11,10 +11,8 @@
"""

import json
import io
import os
import pytest
from typing import Optional
from unittest.mock import MagicMock
from CommonServerPython import CommandResults, DemistoException
from DatadogCloudSIEM import (
Expand Down Expand Up @@ -55,13 +53,20 @@
MetricSearchResponseResults,
)
from datadog_api_client.v1.model.metric_metadata import MetricMetadata
from test_data.inputs import *
from test_data.inputs import TIME_SERIES_POINT_QUERY_RESPONSE, TIME_SERIES_POINT_QUERY_CONTEXT, CREATE_INCIDENT_RESPONSE, \
CREATE_INCIDENT_CONTEXT, UPDATE_INCIDENT_RESPONSE, UPDATE_INCIDENT_CONTEXT, GET_INCIDENT_RESPONSE, GET_INCIDENT_CONTEXT, \
INCIDENT_LOOKUP_DATA, INCIDENT_LOOKUP_DATA_EXPECTED, METRIC_COMMAND_RESULT_INPUT, METRIC_COMMAND_RESULT_OUTPUT, \
TAGS_CONTEXT_READABLE_OUTPUT, LIST_INCIDENT_RESPONSE, LIST_INCIDENT_CONTEXT, EVENT_CREATE_RESPONSE, TAGS_LIST_CONTEXT, \
EVENT_CREATE_CONTEXT, EVENT_LIST_RESPONSE, EVENT_LIST_CONTEXT, EVENT_GET_RESPONSE, EVENT_GET_CONTEXT, \
HOST_TAG_CREATE_CONTEXT, HOST_TAG_GET_CONTEXT, HOST_TAG_UPDATE_CONTEXT, ACTIVE_METRIC_LIST_RESPONSE, \
ACTIVE_METRIC_LIST_CONTEXT, METRIC_SEARCH_RESPONSE, METRIC_SEARCH_CONTEXT, METRIC_METADATA_GET_RESPONSE, \
METRIC_METADATA_GET_CONTEXT, METRIC_METADATA_UPDATE_RESPONSE, METRIC_METADATA_UPDATE_CONTEXT, EVENT_MOCK, EXPECTED_EVENT_MOCK
import datetime
import demistomock as demisto


def util_load_json(path):
with io.open(path, mode="r", encoding="utf-8") as f:
with open(path, encoding="utf-8") as f:
return json.loads(f.read())


Expand Down Expand Up @@ -146,7 +151,6 @@ def test_create_event_command(mocker, raw_resp, expected, configuration):
mocker.patch("DatadogCloudSIEM.EventsApi", return_value=DATADOG_API_CLIENT_MOCK)
with open(
os.path.join("test_data", "readable_outputs/create_event_command_readable.md"),
"r",
) as f:
readable_output = f.read()
result = create_event_command(configuration, args)
Expand Down Expand Up @@ -186,7 +190,6 @@ def test_list_events_command(mocker, raw_resp, expected, configuration):
result = get_events_command(configuration, args)
with open(
os.path.join("test_data", "readable_outputs/list_events_command_readable.md"),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -218,7 +221,6 @@ def test_get_events_command(mocker, raw_resp, expected, configuration):
result = get_events_command(configuration, args)
with open(
os.path.join("test_data", "readable_outputs/get_events_command_readable.md"),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -255,7 +257,6 @@ def test_add_tags_to_host_command(mocker, raw_resp, expected, configuration):
os.path.join(
"test_data", "readable_outputs/add_tags_to_host_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -287,7 +288,6 @@ def test_get_host_tags_command(mocker, raw_resp, expected, configuration):
result = get_host_tags_command(configuration, args)
with open(
os.path.join("test_data", "readable_outputs/get_host_tags_command_readable.md"),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -324,7 +324,6 @@ def test_update_host_tags_command(mocker, raw_resp, expected, configuration):
os.path.join(
"test_data", "readable_outputs/update_host_tags_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -360,7 +359,6 @@ def test_active_metrics_list_command(mocker, raw_resp, expected, configuration):
os.path.join(
"test_data", "readable_outputs/active_metrics_list_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -397,7 +395,6 @@ def test_metrics_search_command(mocker, raw_resp, expected, configuration):
os.path.join(
"test_data", "readable_outputs/metrics_search_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -432,7 +429,6 @@ def test_get_metric_metadata_command(mocker, raw_resp, expected, configuration):
os.path.join(
"test_data", "readable_outputs/get_metric_metadata_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -475,7 +471,6 @@ def test_update_metric_metadata_command(mocker, raw_resp, expected, configuratio
os.path.join(
"test_data", "readable_outputs/update_metric_metadata_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -510,7 +505,7 @@ def test_get_tags_command(mocker, raw_resp, expected, configuration):
mocker.patch("DatadogCloudSIEM.TagsApi", return_value=DATADOG_API_CLIENT_MOCK)
result = get_tags_command(configuration, args)
with open(
os.path.join("test_data", "readable_outputs/get_tags_command_readable.md"), "r"
os.path.join("test_data", "readable_outputs/get_tags_command_readable.md")
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -545,7 +540,6 @@ def test_query_timeseries_points_command(mocker, raw_resp, expected, configurati
os.path.join(
"test_data", "readable_outputs/query_timeseries_points_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result[0], CommandResults)
Expand Down Expand Up @@ -641,7 +635,6 @@ def test_create_incident_command(mocker, raw_resp, expected, configuration):
os.path.join(
"test_data", "readable_outputs/create_incident_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -689,7 +682,6 @@ def test_update_incident_command(mocker, raw_resp, expected, configuration):
os.path.join(
"test_data", "readable_outputs/update_incident_command_readable.md"
),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -721,7 +713,6 @@ def test_get_incident_command(mocker, raw_resp, expected, configuration):
result = get_incident_command(configuration, args)
with open(
os.path.join("test_data", "readable_outputs/get_incident_command_readable.md"),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -753,7 +744,6 @@ def test_list_incident_command(mocker, raw_resp, expected, configuration):
result = get_incident_command(configuration, args)
with open(
os.path.join("test_data", "readable_outputs/list_incident_command_readable.md"),
"r",
) as f:
readable_output = f.read()
assert isinstance(result, CommandResults)
Expand Down Expand Up @@ -959,7 +949,7 @@ def test_incident_for_lookup(raw, expected):
],
)
def test_pagination(
limit: Optional[int], page: Optional[int], page_size: Optional[int], expected
limit: int | None, page: int | None, page_size: int | None, expected
):
"""
Test function for the pagination function in DatadogCloudSIEM.
Expand Down
Expand Up @@ -3,7 +3,8 @@
import pytest

from LogsignSiem import *
from test_data.sample_data import *
from test_data.sample_data import DATE_FORMAT, CHECK_ARG_MOCK_DATA, PARAMS, ARGS_Q, MOCK_INCIDENTS, MOCK_INC, RESULT_COUNT_HR, \
RESULT_COLUMNS_HR

import demistomock

Expand Down

0 comments on commit 5a3ed7c

Please sign in to comment.