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

[pre-commit pycln] Align the entire repo with pycln #29611

Merged
merged 10 commits into from
Sep 12, 2023
Original file line number Diff line number Diff line change
@@ -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())
mmhw marked this conversation as resolved.
Show resolved Hide resolved


def test_uuid_command():
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
)
import traceback

import dns.message
import dns.resolver
import dns.rdatatype
import dns.rdataclass
Expand Down Expand Up @@ -88,7 +87,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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import io

from pytest import raises, fixture
import pytest

from CommonServerPython import *

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


@fixture
@pytest.fixture
def client():
from MobileIronCLOUD import MobileIronCloudClient

Expand All @@ -22,13 +21,12 @@


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())


class TestGetPartitionId:
from MobileIronCLOUD import get_partition_id

Check failure on line 29 in Packs/MobileIronUEM/Integrations/MobileIronCLOUD/MobileIronCLOUD_test.py

View workflow job for this annotation

GitHub Actions / pre-commit

Packs/MobileIronUEM/Integrations/MobileIronCLOUD/MobileIronCLOUD_test.py.test_get_partition_id_return_param

AttributeError: type object 'TestGetPartitionId' has no attribute 'get_partition_id'
@staticmethod
def test_get_partition_id_return_param(mocker, client):
"""It returns the value of partition id from params"""
Expand All @@ -37,7 +35,7 @@
result = TestGetPartitionId.get_partition_id(client)

assert result == '12345'

Check failure on line 38 in Packs/MobileIronUEM/Integrations/MobileIronCLOUD/MobileIronCLOUD_test.py

View workflow job for this annotation

GitHub Actions / pre-commit

Packs/MobileIronUEM/Integrations/MobileIronCLOUD/MobileIronCLOUD_test.py.test_get_partition_id_return_api

AttributeError: type object 'TestGetPartitionId' has no attribute 'get_partition_id'
@staticmethod
def test_get_partition_id_return_api(mocker, requests_mock, client):
"""It returns the value from API, in case param is not defined"""
Expand All @@ -55,7 +53,7 @@
result = TestGetPartitionId.get_partition_id(client)

assert result == '100001'

Check failure on line 56 in Packs/MobileIronUEM/Integrations/MobileIronCLOUD/MobileIronCLOUD_test.py

View workflow job for this annotation

GitHub Actions / pre-commit

Packs/MobileIronUEM/Integrations/MobileIronCLOUD/MobileIronCLOUD_test.py.test_get_partition_id_return_stored

AttributeError: type object 'TestGetPartitionId' has no attribute 'get_partition_id'
@staticmethod
def test_get_partition_id_return_stored(mocker, client):
"""
Expand All @@ -72,7 +70,7 @@
})
result = TestGetPartitionId.get_partition_id(client)
assert result == '10101'

Check failure on line 73 in Packs/MobileIronUEM/Integrations/MobileIronCLOUD/MobileIronCLOUD_test.py

View workflow job for this annotation

GitHub Actions / pre-commit

Packs/MobileIronUEM/Integrations/MobileIronCLOUD/MobileIronCLOUD_test.py.test_get_partition_id_change_user

AttributeError: type object 'TestGetPartitionId' has no attribute 'get_partition_id'
@staticmethod
def test_get_partition_id_change_user(mocker, client, requests_mock):
"""
Expand All @@ -96,7 +94,7 @@

class TestClientGetDevicesData:

@fixture
@pytest.fixture
def prepare_mock(self, requests_mock):
mock_response_page_one = util_load_json('test_data/get_devices_response_page.json')
mock_response_page_two = util_load_json('test_data/get_devices_response_page2.json')
Expand Down Expand Up @@ -184,7 +182,7 @@

requests_mock.put('/api/v1/device/unlock', json={'errors': None, 'result': 0})

with raises(ValueError):
with pytest.raises(ValueError):
execute_device_action_command(client, 'unlock')


Expand All @@ -206,7 +204,7 @@

requests_mock.put('/api/v1/device/message', json={'errors': None, 'result': 0})

with raises(ValueError):
with pytest.raises(ValueError):
execute_send_message_command(client)


Expand Down
4 changes: 2 additions & 2 deletions Packs/PAN-OS/Integrations/Panorama/Panorama.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import re
import requests
import urllib3
from urllib.parse import urlparse, quote
from urllib.parse import urlparse

# disable insecure warnings
urllib3.disable_warnings()
Expand Down Expand Up @@ -5289,7 +5289,7 @@ def build_logs_query(address_src: Optional[str], address_dst: Optional[str], ip_

@logger
def panorama_query_logs(log_type: str, number_of_logs: str, query: str, address_src: str, address_dst: str, ip_: str,
zone_src: str, zone_dst: str, time_generated: str, time_generated_after: str, action: str,
zone_src: str, zone_dst: str, time_generated: str, time_generated_after: str, action: str,
port_dst: str, rule: str, url: str, filedigest: str):
params = {
'type': 'log',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from CommonServerPython import CommandResults
import knowbe4Phisher as phisher
import pytest
from test_data.mock_tests import *
from test_data.mock_tests import create_request_test, pagination_response, response_fetch, expected_fetch, events_example, \
expected_time
import json


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


Expand Down Expand Up @@ -50,7 +52,7 @@ def test_caclulate_event(mocker, query, expected, return_value):
mocker.patch.object(client, "phisher_gql_request", return_value=return_value)
result = phisher.calculate_number_of_events(client, query)
assert result == expected
assert "X-KB4-Integration" in client._headers.keys()
assert "X-KB4-Integration" in client._headers
assert client._headers["X-KB4-Integration"] == "Cortex XSOAR PhishER"


Expand Down
1 change: 1 addition & 0 deletions Tests/scripts/utils/logging_wrapper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging

Check failure on line 1 in Tests/scripts/utils/logging_wrapper/__init__.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (N999)

Tests/scripts/utils/logging_wrapper/__init__.py:1:1: N999 Invalid module name: 'Tests'
from logging import *

# add success level in addition to levels imported from logging
SUCCESS = 25
__all__ = ['SUCCESS', 'success']

root = logging.root
addLevelName(SUCCESS, 'SUCCESS')
Expand Down
Loading
Loading