<commit_before>import unittest
from mock import patch, Mock, call
from sandbox_scripts.environment.setup.setup_resources import EnvironmentSetupResources
import json
import os


resContext = '''{"id":"5487c6ce-d0b3-43e9-8ee7-e27af8406905",
 "ownerUser":"bob",
 "ownerPass":"<PASSWORD>=",
 "domain":"Global",
 "environmentName":"My environment",
 "description":"New demo environment",
 "parameters":
   { "globalInputs": [],
     "resourceRequirements":[],
     "resourceAdditionalInfo":[]}}'''

conContext = '''{"serverAddress": "localhost",
"adminAuthToken": "<PASSWORD>"}'''

class SetupResourcesTests(unittest.TestCase):

    @patch('sandbox_scripts.environment.setup.setup_resources.get_qs_logger')
    def setUp(self, mock_logger):
        os.environ['reservationContext'] = resContext
        os.environ['qualiConnectivityContext'] = conContext
        self.setup_script = EnvironmentSetupResources()

    def tearDown(self):
        pass

    @patch('cloudshell.helpers.scripts.cloudshell_scripts_helpers.get_api_session')
    @patch('sandbox_scripts.environment.setup.setup_resources.SandboxBase')
    @patch('sandbox_scripts.environment.setup.setup_resources.NetworkingSaveRestore')
    def test_flow_ok_with_snapshots(self, mock_save, mock_sandboxbase, mock_api_session):

        mock_save.return_value.is_snapshot.return_value = True
        self.setup_script.execute()
        mock_sandboxbase.return_value.clear_all_resources_live_status.assert_called_with()
        mock_save.return_value.load_config.assert_called_with(config_stage='Snapshots', config_type='Running', ignore_models=['Generic TFTP server', 'Config Set Pool', 'Generic FTP server', 'netscout switch 3912'])
        mock_sandboxbase.return_value.power_on_vms.assert_called_with()
        mock_sandboxbase.return_value.activate_all_routes_and_connectors.assert_called_with()
        report_info_calls = [call('Beginning load configuration for resources'),
                             call('Sandbox setup finished successfully')]
        mock_sandboxbase.return_value.report_info.assert_has_calls(report_info_calls)


    @patch('cloudshell.helpers.scripts.cloudshell_scripts_helpers.get_api_session')
    @patch('sandbox_scripts.environment.setup.setup_resources.SandboxBase')
    @patch('sandbox_scripts.environment.setup.setup_resources.NetworkingSaveRestore')
    def test_flow_ok_with_gold(self, mock_save, mock_sandboxbase, mock_api_session):

        mock_save.return_value.is_snapshot.return_value = False
        self.setup_script.execute()
        mock_sandboxbase.return_value.clear_all_resources_live_status.assert_called_with()
        mock_save.return_value.load_config.assert_called_with(config_set_name='', config_stage='Gold', config_type='Running', ignore_models=['Generic TFTP server', 'Config Set Pool', 'Generic FTP server', 'netscout switch 3912'])
        mock_sandboxbase.return_value.power_on_vms.assert_called_with()
        mock_sandboxbase.return_value.activate_all_routes_and_connectors.assert_called_with()
        report_info_calls = [call('Beginning load configuration for resources'),
                             call('Sandbox setup finished successfully')]
        mock_sandboxbase.return_value.report_info.assert_has_calls(report_info_calls)



if __name__ == '__main__':
    unittest.main()<commit_msg>added another test for no storage device<commit_after>import unittest
from mock import patch, Mock, call
from sandbox_scripts.environment.setup.setup_resources import EnvironmentSetupResources
import json
import os


resContext = '''{"id":"5487c6ce-d0b3-43e9-8ee7-e27af8406905",
 "ownerUser":"bob",
 "ownerPass":"<PASSWORD>=",
 "domain":"Global",
 "environmentName":"My environment",
 "description":"New demo environment",
 "parameters":
   { "globalInputs": [],
     "resourceRequirements":[],
     "resourceAdditionalInfo":[]}}'''

conContext = '''{"serverAddress": "localhost",
"adminAuthToken": "<PASSWORD>"}'''

class SetupResourcesTests(unittest.TestCase):

    @patch('sandbox_scripts.environment.setup.setup_resources.get_qs_logger')
    def setUp(self, mock_logger):
        os.environ['reservationContext'] = resContext
        os.environ['qualiConnectivityContext'] = conContext
        self.setup_script = EnvironmentSetupResources()

    def tearDown(self):
        pass

    @patch('cloudshell.helpers.scripts.cloudshell_scripts_helpers.get_api_session')
    @patch('sandbox_scripts.environment.setup.setup_resources.SandboxBase')
    @patch('sandbox_scripts.environment.setup.setup_resources.NetworkingSaveRestore')
    def test_flow_ok_with_snapshots(self, mock_save, mock_sandboxbase, mock_api_session):

        mock_save.return_value.is_snapshot.return_value = True
        self.setup_script.execute()
        mock_sandboxbase.return_value.clear_all_resources_live_status.assert_called_with()
        mock_save.return_value.load_config.assert_called_with(config_stage='Snapshots', config_type='Running', ignore_models=['Generic TFTP server', 'Config Set Pool', 'Generic FTP server', 'netscout switch 3912'])
        mock_sandboxbase.return_value.power_on_vms.assert_called_with()
        mock_sandboxbase.return_value.activate_all_routes_and_connectors.assert_called_with()
        report_info_calls = [call('Beginning load configuration for resources'),
                             call('Sandbox setup finished successfully')]
        mock_sandboxbase.return_value.report_info.assert_has_calls(report_info_calls)


    @patch('cloudshell.helpers.scripts.cloudshell_scripts_helpers.get_api_session')
    @patch('sandbox_scripts.environment.setup.setup_resources.SandboxBase')
    @patch('sandbox_scripts.environment.setup.setup_resources.NetworkingSaveRestore')
    def test_flow_ok_with_gold(self, mock_save, mock_sandboxbase, mock_api_session):
        mock_save.return_value.is_snapshot.return_value = False
        mock_sandboxbase.return_value.get_storage_server_resource.return_value = True
        self.setup_script.execute()
        mock_sandboxbase.return_value.clear_all_resources_live_status.assert_called_with()
        mock_save.return_value.load_config.assert_called_with(config_set_name='', config_stage='Gold', config_type='Running', ignore_models=['Generic TFTP server', 'Config Set Pool', 'Generic FTP server', 'netscout switch 3912'])
        mock_sandboxbase.return_value.power_on_vms.assert_called_with()
        mock_sandboxbase.return_value.activate_all_routes_and_connectors.assert_called_with()
        report_info_calls = [call('Beginning load configuration for resources'),
                             call('Sandbox setup finished successfully')]
        mock_sandboxbase.return_value.report_info.assert_has_calls(report_info_calls)

    @patch('cloudshell.helpers.scripts.cloudshell_scripts_helpers.get_api_session')
    @patch('sandbox_scripts.environment.setup.setup_resources.SandboxBase')
    @patch('sandbox_scripts.environment.setup.setup_resources.NetworkingSaveRestore')
    def test_flow_ok_with_no_storage_device(self, mock_save, mock_sandboxbase, mock_api_session):
        mock_sandboxbase.return_value.get_storage_server_resource.return_value = False
        self.setup_script.execute()
        mock_sandboxbase.return_value.clear_all_resources_live_status.assert_called_with()
        report_info_calls = [call('Beginning load configuration for resources'),
                             call('Skipping load configuration. No storage resource associated with the blueprint ', write_to_output_window=True),
                             call('Sandbox setup finished successfully')]
        mock_sandboxbase.return_value.report_info.assert_has_calls(report_info_calls)


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.10124772550038992, 'fraction_numerical': 0.007538341564855732, 'mean_word_length': 5.2006446414182115, 'pattern_counts': {'":': 24, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5562723', 'n_tokens_mistral': 2316, 'n_tokens_neox': 2269, 'n_words': 307}