HEX
HEX
Server: Apache/2.4.29 (Ubuntu)
System: Linux 2amigos-php74 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64
User: squarehillcompany.com (1002)
PHP: 7.4.25
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhosts/dial-copper-dev.2amigos.us/dialpad-copper-crm/api/tests/testbase.py
"""Module with basic funcionality common for all tests
"""

import json

from os import path
from typing import List


def read_mock_file(file_name: str) -> str:
    """Reads and returns the content of a mock file

    Args:
        file_name (str): Mock folder file name with extension

    Returns:
        str: the file contents
    """
    file_path = path.join(path.dirname(__file__), 'mocks', file_name)
    if not path.exists(file_path):
        raise ValueError(f'The path {file_path} is not valid')

    with open(file_path, 'r') as f:
        return f.read()


def call_event_mocks(unrelated_events: bool = False) -> List[dict]:
    """Mock of a sequence of call events
    
    Args:
        unrelated_events (bool): Get a mock with all call events unrelated to each other

    Returns:
        List[dict]: JSON Parsed events
    """
    if unrelated_events:
        return json.loads(read_mock_file('dialpad-full-call-events.json'))
    return json.loads(read_mock_file('dialpad-call-events.json'))


def call_event_mock_by_state(state: str) -> dict:
    """Call event mock by a desired state

    Args:
        state (str): desired mock state

    Returns:
        dict: JSON Parsed event
    """
    return next(iter(filter(lambda e: e['state'] == state, call_event_mocks())))