コード例 #1
0
class TestTeamsPostMessage:
    """ Tests for the teams_post_message function"""

    # Read the default configuration-data section from the package
    config_data = get_config_data(PACKAGE_NAME)

    def test_function_definition(self):
        """ Test that the package provides customization_data that defines the function """
        func = get_function_definition(PACKAGE_NAME, FUNCTION_NAME)
        assert func is not None

    @pytest.mark.livetest
    @pytest.mark.parametrize("incident_id, task_id, teams_channel, teams_payload, teams_mrkdown, expected_results", [
        (123, None, "selftest", '{"title": "titleЀЄЏ"}', False, None),
        (123, None, "selftest", '{"title": "title", "summary": "summaryЀЄЏ"}', False, None),
        (123, None, "selftest", '{"title": "title", "summary": "summaryЀЄЏ", "sections": [{"title": "sectionЀЄЏ"}]}', False, None),
        (123, None, "selftest", '{"title": "title", "summary": "summaryЀЄЏ", "sections": [{"title": "section1", "text": "section textЀЄЏ"}]}', False, None),
        (123, None, "selftest", '{"title": "title", "summary": "summaryЀЄЏ", "sections": [{"title": "section1", "text": "section text", "facts":[{"name": "fact1", "value": "valueЀЄЏ"}]}]}', False, None),
        (123, None, "selftest", '{"title": "title", "summary": "summaryЀЄЏ", "sections": [{"title": "section1", "text": "section text", "facts":[{"name": "fact1", "value": "value1"}, {"name": "fact2", "value": "value2"}]}]}', False, None),
        (123, None, "selftest", '{"title": "title", "summary": "<u>summaryЀЄЏ</u>", "sections": [{"title": "section1", "text": "section text", "facts":[{"name": "fact1", "value": "value1"}, {"name": "fact2", "value": "value2"}]},{"title": "section2", "text": "section text", "facts":[{"name": "fact1", "value": "value1"}, {"name": "fact2", "value": "value2"}]}]}', True, None)
    ])
    def test_success(self, circuits_app, incident_id, task_id, teams_channel, teams_payload, teams_mrkdown, expected_results):
        """ Test calling with sample values for the parameters """
        function_params = { 
            "incident_id": incident_id,
            "task_id": task_id,
            "teams_channel": teams_channel,
            "teams_payload": teams_payload,
            "teams_mrkdown": teams_mrkdown
        }

        results = call_teams_post_message_function(circuits_app, function_params)
        assert results['success']
from resilient_circuits.util import get_config_data, get_function_definition
from resilient_circuits import SubmitTestFunction, FunctionResult
from mock_umbrella import mocked_response

PACKAGE_NAME = "fn_cisco_umbrella_inv"
FUNCTION_NAME = "umbrella_domain_whois_info"


def assert_keys_in(json_obj, *keys):
    for key in keys:
        assert key in json_obj


# Read the default configuration-data section from the package
config_data = get_config_data(PACKAGE_NAME)

# Provide a simulation of the Resilient REST API (uncomment to connect to a real appliance)
resilient_mock = "pytest_resilient_circuits.BasicResilientMock"


def call_umbrella_domain_whois_info_function(circuits,
                                             function_params,
                                             timeout=10):
    # Fire a message to the function
    evt = SubmitTestFunction("umbrella_domain_whois_info", function_params)
    circuits.manager.fire(evt)
    event = circuits.watcher.wait("umbrella_domain_whois_info_result",
                                  parent=evt,
                                  timeout=timeout)
    assert event