def test_close_ticket_command_negative(self, requests_mock): from CaseManagement import close_ticket_command ticket = copy.deepcopy(TestInputs.TICKET_MOCK) ticket['ticket'][0]['isOpen'] = False requests_mock.post(urljoin(url, 'ticket/close'), json={}) with raises(DemistoException, match='Could not close ticket'): close_ticket_command(client, {'ticket_id': '111'})
def test_fetch_incidents(self, requests_mock, req_input, last_run, fetch_time, incidents): from CaseManagement import fetch_incidents_command requests_mock.get(urljoin(url, 'ticket'), json=req_input) incidents_res, timestamp = fetch_incidents_command(client, last_run, fetch_time) if incidents: assert incidents_res[0].get('name') == incidents[0].get('name') else: assert not incidents and not incidents_res
def test_create_ticket(self, requests_mock, req_input, expected_md, expected_context): from CaseManagement import create_ticket_command requests_mock.post(urljoin(url, 'ticket'), json=req_input) human_readable, context, _ = create_ticket_command( client, self.create_ticket_args) assert expected_md in human_readable assert expected_context == context
def test_list_tickets(self, requests_mock, req_input, expected_md, expected_context): from CaseManagement import list_tickets_command requests_mock.get(urljoin(url, 'ticket'), json=req_input) human_readable, context, _ = list_tickets_command( client, {'ticket_id': '111'}) assert expected_md in human_readable assert expected_context == context
def test_assign_users(self, requests_mock, req_input, expected_md, expected_context): from CaseManagement import assign_users_command requests_mock.post(urljoin(url, 'ticket/assign'), json=req_input) human_readable, context, _ = assign_users_command( client, { 'ticket_id': '111', 'users': ['user1, user2'] }) assert expected_md in human_readable assert expected_context == context
def test_url_fails_unknown_error_code(mocker, requests_mock): """url""" import Zscaler Zscaler.BASE_URL = 'http://cloud/api/v1' requests_mock.post(urljoin(Zscaler.BASE_URL, 'urlLookup'), status_code=501) args = { 'url': 'https://www.demisto-news.com,https://www.demisto-search.com' } try: Zscaler.url_lookup(args) except Exception as ex: assert 'following error: 501' in str(ex)
import pytest from CommonServerPython import (CommandResults, DemistoException, tableToMarkdown, urljoin) from YodaSpeak import TRANSLATE_OUTPUT_PREFIX def util_load_json(path: str): with io.open(path, mode='r', encoding='utf-8') as f: return json.loads(f.read()) BASE_URL = 'https://yoda.example.com' YODA_ENDPOINT = 'yoda' ENDPOINT_URL = urljoin(BASE_URL, YODA_ENDPOINT) def test_translate(requests_mock): """ Given An API key, and text to translate When Calling translate Then Test the command result structure """ from YodaSpeak import Client, translate_command client = Client(base_url=BASE_URL, verify=False, api_key='foo',
def test_module_negative(self, requests_mock): from CaseManagement import test_module_command requests_mock.get(urljoin(url, self.suffix), json={}) with raises(DemistoException, match='Unexpected response'): test_module_command(client)
def test_module_positive(self, requests_mock): from CaseManagement import test_module_command requests_mock.get(urljoin(url, self.suffix), json=self.response) assert 'ok' == test_module_command(client)
def test_close_ticket_command(self, requests_mock): from CaseManagement import close_ticket_command ticket = copy.deepcopy(TestInputs.TICKET_MOCK) ticket['ticket'][0]['isOpen'] = False requests_mock.post(urljoin(url, 'ticket/close'), json=ticket) close_ticket_command(client, {'ticket_id': '111'})
def test_create_ticket_negative(self, requests_mock): from CaseManagement import create_ticket_command requests_mock.post(urljoin(url, 'ticket'), json={}) with raises(DemistoException, match='Could not create new ticket'): create_ticket_command(client, self.create_ticket_args)
"""Imports""" # STD packages import time import json # 3-rd party packages import pytest from freezegun import freeze_time # Local imports from CommonServerPython import urljoin """Helper functions and fixrtures""" BASE_URL = urljoin('https://akab-hnanog6ge5or6biz-ukavvo4zvqliqhlw.cloudsecurity.akamaiapis.net', '/siem/v1/configs') def load_params_from_json(json_path, type=''): with open(json_path) as f: file = json.load(f) if type == "incidents": for incident in file: incident['rawJSON'] = json.dumps(incident.get('rawJSON', {})) return file @pytest.fixture(scope='module') def client(): from Akamai_SIEM import Client return Client(base_url=BASE_URL)