示例#1
0
def test_upload_pack(demisto_client_configure, mocker):
    """
    Given
        - A pack called DummyPack

    When
        - Uploading pack

    Then
        - Ensure pack is uploaded successfully
        - Ensure status code is as expected
        - Check that all expected content entities that appear in the pack are reported as uploaded.
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    pack_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack"
    uploader = Uploader(input=pack_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    status_code = uploader.upload()
    expected_entities = [
        'DummyIntegration.yml', 'UploadTest.yml', 'DummyScriptUnified.yml',
        'DummyScript.yml', 'DummyPlaybook.yml', 'DummyTestPlaybook.yml',
        'incidenttype-Hello_World_Alert.json',
        'incidentfield-Hello_World_ID.json',
        'incidentfield-Hello_World_Type.json',
        'incidentfield-Hello_World_Status.json',
        'classifier-aws_sns_test_classifier.json',
        'widget-ActiveIncidentsByRole.json', 'layout-details-test_bla-V2.json',
        'upload_test_dashboard.json'
    ]
    assert status_code == 0
    uploaded_objects = [
        obj_pair[0] for obj_pair in uploader.successfully_uploaded_files
    ]
    for entity in expected_entities:
        assert entity in uploaded_objects
示例#2
0
def test_upload_script_positive(demisto_client_configure, mocker):
    """
    Given
        - A script named EntryWidgetNumberHostsXDR to upload

    When
        - Uploading a script

    Then
        - Ensure script is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    script_name = "DummyScriptUnified.yml"
    script_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/Scripts/{script_name}"
    uploader = Uploader(input=script_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [(script_name, FileType.SCRIPT.value)
            ] == uploader.successfully_uploaded_files
示例#3
0
def test_upload_classifier_positive(demisto_client_configure, mocker):
    """
    Given
        - A classifier type named XDR_Alert_Count to upload

    When
        - Uploading classifier

    Then
        - Ensure classifier is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    classifier_name = "classifier-aws_sns_test_classifier.json"
    classifier_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/Classifiers/{classifier_name}"
    uploader = Uploader(input=classifier_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [(classifier_name, FileType.OLD_CLASSIFIER.value)
            ] == uploader.successfully_uploaded_files
示例#4
0
def test_upload_indicator_field_positive(demisto_client_configure, mocker):
    """
    Given
        - An indicator field named DNS to upload
    When
        - Uploading indicator field
    Then
        - Ensure indicator field is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value='object')
    indicator_field_name = 'dns.json'
    indicator_field_path = f'{git_path()}/demisto_sdk/tests/test_files/Packs/CortexXDR/IndicatorFields/{indicator_field_name}'
    uploader = Uploader(input=indicator_field_path,
                        insecure=False,
                        verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [(indicator_field_name, FileType.INDICATOR_FIELD.value)
            ] == uploader.successfully_uploaded_files
示例#5
0
def test_upload_layout_positive(demisto_client_configure, mocker):
    """
    Given
        - A layout named layout-details-test_bla-V2 to upload

    When
        - Uploading a layout

    Then
        - Ensure layout is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    layout_name = "layout-details-test_bla-V2.json"
    layout_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/Layouts/{layout_name}"
    uploader = Uploader(input=layout_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [(layout_name, FileType.LAYOUT.value)
            ] == uploader.successfully_uploaded_files
示例#6
0
def test_upload_playbook_positive(demisto_client_configure, mocker):
    """
    Given
        - A playbook named Cortex_XDR_Incident_Handling to upload

    When
        - Uploading a playbook

    Then
        - Ensure playbook is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")

    playbook_name = "Cortex_XDR_Incident_Handling.yml"
    playbook_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/CortexXDR/Playbooks/{playbook_name}"
    uploader = Uploader(input=playbook_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [(playbook_name, FileType.PLAYBOOK.value)
            ] == uploader.successfully_uploaded_files
示例#7
0
def test_upload_incident_type_correct_file_change(demisto_client_configure,
                                                  mocker):
    """
    Given
        - An incident type named incidenttype-Hello_World_Alert to upload

    When
        - Uploading incident type

    Then
        - Ensure incident type is in the correct format for upload
    """
    def save_file(file):
        global DATA
        with open(file, 'r') as f:
            DATA = f.read()
        return

    class demisto_client_mocker():
        def import_incident_fields(self, file):
            pass

    mocker.patch.object(demisto_client,
                        'configure',
                        return_value=demisto_client_mocker)

    incident_type_name = "incidenttype-Hello_World_Alert.json"
    incident_type_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/IncidentTypes/{incident_type_name}"
    uploader = Uploader(input=incident_type_path,
                        insecure=False,
                        verbose=False)
    uploader.client.import_incident_types_handler = MagicMock(
        side_effect=save_file)
    uploader.upload()

    with open(incident_type_path) as json_file:
        incident_type_data = json.load(json_file)

    assert json.loads(DATA)[0] == incident_type_data
示例#8
0
def test_upload_report_positive(demisto_client_configure, mocker, repo):
    """
    Given
        - A report to upload

    When
        - Uploading a report

    Then
        - Ensure report is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    pack = repo.create_pack('pack')
    report = pack.create_report('test-report')
    report.write_json({"id": "dummy-report", "orientation": "portrait"})
    with ChangeCWD(repo.path):
        uploader = Uploader(input=report.path, insecure=False, verbose=False)
        mocker.patch.object(uploader, 'client')
        uploader.upload()
    assert [(report.name, FileType.REPORT.value)
            ] == uploader.successfully_uploaded_files
示例#9
0
def test_upload_dashboard_positive(demisto_client_configure, mocker):
    """
    Given
        - A dashboard named upload_test_dashboard.json to upload

    When
        - Uploading a dashboard

    Then
        - Ensure dashboard is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")

    dashboard_name = "upload_test_dashboard.json"
    dashboard_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/Dashboards/{dashboard_name}"
    uploader = Uploader(input=dashboard_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [('upload_test_dashboard.json', FileType.DASHBOARD.value)
            ] == uploader.successfully_uploaded_files
示例#10
0
def test_upload_widget_positive(demisto_client_configure, mocker):
    """
    Given
        - A widget named ActiveIncidentsByRole to upload

    When
        - Uploading a widget

    Then
        - Ensure widget is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")

    widget_name = "widget-ActiveIncidentsByRole.json"
    widget_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/Widgets/{widget_name}"
    uploader = Uploader(input=widget_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [(widget_name, FileType.WIDGET.value)
            ] == uploader.successfully_uploaded_files
示例#11
0
def test_upload_a_script_directory(demisto_client_configure, mocker):
    """
    Given
        - A script directory called DummyScript

    When
        - Uploading an script

    Then
        - Ensure script is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    script_dir_name = "DummyScript"
    scripts_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/Scripts/{script_dir_name}"
    uploader = Uploader(input=scripts_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()
    _, script_yml_name = get_yml_paths_in_dir(scripts_path)
    uploaded_file_name = script_yml_name.split('/')[-1]

    assert [(uploaded_file_name, FileType.SCRIPT.value)
            ] == uploader.successfully_uploaded_files
示例#12
0
def test_upload_an_integration_directory(demisto_client_configure, mocker):
    """
    Given
        - An integration directory called UploadTest

    When
        - Uploading an integration

    Then
        - Ensure integration is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    integration_dir_name = "UploadTest"
    integration_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/Integrations/{integration_dir_name}"
    uploader = Uploader(input=integration_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()
    _, integration_yml_name = get_yml_paths_in_dir(integration_path)
    integration_yml_name = integration_yml_name.split('/')[-1]

    assert [(integration_yml_name, FileType.INTEGRATION.value)
            ] == uploader.successfully_uploaded_files
示例#13
0
def test_upload_incident_field_positive(demisto_client_configure, mocker):
    """
    Given
        - An incident field named XDR_Alert_Count to upload

    When
        - Uploading incident field

    Then
        - Ensure incident field is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    incident_field_name = "XDR_Alert_Count.json"
    incident_field_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/CortexXDR/IncidentFields/{incident_field_name}"
    uploader = Uploader(input=incident_field_path,
                        insecure=False,
                        verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [(incident_field_name, FileType.INCIDENT_FIELD.value)
            ] == uploader.successfully_uploaded_files
示例#14
0
def test_upload_incident_type_positive(demisto_client_configure, mocker):
    """
    Given
        - An incident type named Hello_World_Alert to upload

    When
        - Uploading incident type

    Then
        - Ensure incident type is uploaded successfully
        - Ensure success upload message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    incident_type_name = "incidenttype-Hello_World_Alert.json"
    incident_type_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/IncidentTypes/{incident_type_name}"
    uploader = Uploader(input=incident_type_path,
                        insecure=False,
                        verbose=False)
    mocker.patch.object(uploader, 'client')
    uploader.upload()

    assert [(incident_type_name, FileType.INCIDENT_TYPE.value)
            ] == uploader.successfully_uploaded_files
示例#15
0
def test_file_not_supported(demisto_client_configure, mocker):
    """
    Given
        - A not supported (.py) file

    When
        - Uploading a file

    Then
        - Ensure uploaded failure message is printed as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    file_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/Scripts/DummyScript/DummyScript.py"
    uploader = Uploader(input=file_path, insecure=False, verbose=False)
    mocker.patch.object(uploader, 'client')
    status_code = uploader.upload()
    assert status_code == 1
    assert uploader.failed_uploaded_files[0][0] == 'DummyScript.py'
示例#16
0
def test_upload_incident_fields_directory(demisto_client_configure, mocker):
    """
    Given
        - An incident fields directory called DummyScript

    When
        - Uploading incident fields

    Then
        - Ensure incident fields are uploaded successfully
        - Ensure status code is as expected
        - Ensure amount of messages is as expected
    """
    mocker.patch.object(demisto_client, 'configure', return_value="object")
    mocker.patch("click.secho")
    dir_name = "IncidentFields"
    incident_fields_path = f"{git_path()}/demisto_sdk/tests/test_files/Packs/DummyPack/{dir_name}/"
    uploader = Uploader(input=incident_fields_path,
                        insecure=False,
                        verbose=False)
    mocker.patch.object(uploader, 'client')
    assert uploader.upload() == 0
    assert len(uploader.successfully_uploaded_files) == 3