Esempio n. 1
0
    def test_import_indicator_with_approval__fail_import(self, mocker):
        """
        Given:
            - Import response returned with field indicating that the import fail

        When:
            - Call the import with approval command

        Then:
            - Validate DemistoException was raised
        """

        # prepare
        mocker.patch.object(Client,
                            'http_request',
                            return_value={'success': False})

        # run & validate
        msg = 'The data was not imported. Check if valid arguments were passed'
        with pytest.raises(DemistoException, match=msg):
            import_ioc_with_approval(mock_client(), 'test_import_type',
                                     'test_value')
Esempio n. 2
0
    def test_import_indicator_with_approval__happy_path(
            self, mocker, import_type):
        """
        Given:
            - Indicator to import with approval

        When:
            - Call the import with approval command

        Then:
            - Validate the request and response are as expected
        """

        # prepare
        mocked_file_path = util_tmp_json_file()
        mocker.patch.object(demisto,
                            'getFilePath',
                            return_value=mocked_file_path)
        mocker.patch.object(Client,
                            'http_request',
                            return_value={
                                'success': True,
                                'import_session_id': 'test_session_id'
                            })

        # run
        result = import_ioc_with_approval(mock_client(), import_type,
                                          'test_value')

        # validate

        files = Client.http_request.call_args[1]['files']
        data = Client.http_request.call_args[1]['data']

        if files:  # in case of import_type=file-id
            assert files['file'][0] == 'test_file.txt'
        else:
            assert data[import_type] == 'test_value'

        assert all(key in data for key in
                   ['classification', 'confidence', 'threat_type', 'severity'])

        assert result.outputs == 'test_session_id'