"""
Test cases for location voicemail settings
"""
import random
from concurrent.futures import ThreadPoolExecutor

from .base import TestWithLocations

from wxc_sdk.common import AuthCode
from wxc_sdk.telephony.location_vm import LocationVoiceMailSettings


class Test(TestWithLocations):

    def test_001_read_all(self):
        with ThreadPoolExecutor() as pool:
            details = list(pool.map(
                lambda location: self.api.telephony.location_voicemail.read(location_id=location.location_id),
                self.locations))
        print(f'Got voicemail settings for {len(details)} locations')

    def test_002_update(self):
        """
        Update VM settings for one locations
        """
        target_location = random.choice(self.locations)
        lvm = self.api.telephony.location_voicemail
        before = lvm.read(location_id=target_location.location_id)
        try:
            new_settings = LocationVoiceMailSettings(
                voicemail_transcription_enabled=not before.voicemail_transcription_enabled)
            lvm.update(location_id=target_location.location_id, settings=new_settings)
            after = lvm.read(location_id=target_location.location_id)
            self.assertEqual(new_settings, after)
        finally:
            # restore old settings
            lvm.update(location_id=target_location.location_id, settings=before)
            after = lvm.read(location_id=target_location.location_id)
            self.assertEqual(before, after)

"""
Test cases for location voicemail settings
"""
import random
from concurrent.futures import ThreadPoolExecutor

from .base import TestWithLocations

from wxc_sdk.common import AuthCode
from wxc_sdk.telephony.location_vm import LocationVoiceMailSettings


class Test(TestWithLocations):

    def test_001_read_all(self):
        with ThreadPoolExecutor() as pool:
            details = list(pool.map(
                lambda location: self.api.telephony.location_voicemail.read(location_id=location.location_id),
                self.locations))
        print(f'Got voicemail settings for {len(details)} locations')

    def test_002_update(self):
        """
        Update VM settings for one locations
        """
        target_location = random.choice(self.locations)
        lvm = self.api.telephony.location_voicemail
        before = lvm.read(location_id=target_location.location_id)
        try:
            new_settings = LocationVoiceMailSettings(
                voicemail_transcription_enabled=not before.voicemail_transcription_enabled)
            lvm.update(location_id=target_location.location_id, settings=new_settings)
            after = lvm.read(location_id=target_location.location_id)
            self.assertEqual(new_settings, after)
        finally:
            # restore old settings
            lvm.update(location_id=target_location.location_id, settings=before)
            after = lvm.read(location_id=target_location.location_id)
            self.assertEqual(before, after)

Test cases for location voicemail settings Update VM settings for one locations # restore old settings