Пример #1
0
    def test_workflow_upload_update(self, *args):
        module_mock = MagicMock()
        with patch.dict('sys.modules', **{
            'vdirect_client': module_mock,
            'vdirect_client.rest_client': module_mock,
        }):
            from ansible.modules.network.radware import vdirect_file
            vdirect_file.rest_client.RESP_STATUS = 0
            vdirect_file.rest_client.WorkflowTemplate = WorkflowTemplate

            file = vdirect_file.VdirectFile(NONE_PARAMS)
            path = os.path.dirname(os.path.abspath(__file__))

            WorkflowTemplate.set_create_template_from_archive_result([409])
            WorkflowTemplate.set_update_archive_result([201])
            result = file.upload(os.path.join(path, "wt.zip"))
            self.assertEqual(result, vdirect_file.WORKFLOW_TEMPLATE_UPDATED_SUCCESS,
                             'Unexpected result received:' + repr(result))

            WorkflowTemplate.set_update_archive_result([400, "", "Parsing error", ""])
            try:
                result = file.upload(os.path.join(path, "wt.zip"))
                self.fail("InvalidSourceException was not thrown")
            except vdirect_file.InvalidSourceException:
                assert True
Пример #2
0
    def test_wrong_file_extension(self, *args):
        module_mock = MagicMock()
        with patch.dict('sys.modules', **{
            'vdirect_client': module_mock,
            'vdirect_client.rest_client': module_mock,
        }):
            from ansible.modules.network.radware import vdirect_file

            module_mock.RESP_STATUS = 0
            file = vdirect_file.VdirectFile(NONE_PARAMS)
            result = file.upload("file.??")
            assert result == vdirect_file.WRONG_EXTENSION_ERROR
Пример #3
0
    def test_missing_file(self, *args):
        module_mock = MagicMock()
        with patch.dict('sys.modules', **{
            'vdirect_client': module_mock,
            'vdirect_client.rest_client': module_mock,
        }):
            from ansible.modules.network.radware import vdirect_file

            file = vdirect_file.VdirectFile(NONE_PARAMS)
            try:
                file.upload("missing_file.vm")
                self.assertFalse("IOException was not thrown for missing file")
            except IOError:
                assert True
Пример #4
0
    def test_missing_parameter(self, *args):
        module_mock = MagicMock()
        with patch.dict('sys.modules', **{
            'vdirect_client': module_mock,
            'vdirect_client.rest_client': module_mock,
        }):
            from ansible.modules.network.radware import vdirect_file

            try:
                params = NONE_PARAMS.copy()
                del params['vdirect_ip']
                vdirect_file.VdirectFile(params)
                self.assertFalse("KeyError was not thrown for missing parameter")
            except KeyError:
                assert True
Пример #5
0
    def test_workflow_upload_create_success(self, *args):
        module_mock = MagicMock()
        with patch.dict('sys.modules', **{
            'vdirect_client': module_mock,
            'vdirect_client.rest_client': module_mock,
        }):
            from ansible.modules.network.radware import vdirect_file
            vdirect_file.rest_client.RESP_STATUS = 0
            vdirect_file.rest_client.WorkflowTemplate = WorkflowTemplate

            WorkflowTemplate.set_create_template_from_archive_result([400])
            file = vdirect_file.VdirectFile(NONE_PARAMS)
            path = os.path.dirname(os.path.abspath(__file__))
            result = file.upload(os.path.join(path, "wt.zip"))
            self.assertEqual(result, vdirect_file.WORKFLOW_TEMPLATE_CREATED_SUCCESS,
                             'Unexpected result received:' + repr(result))
Пример #6
0
    def test_template_upload_update_success(self, *args):
        module_mock = MagicMock()
        with patch.dict('sys.modules', **{
            'vdirect_client': module_mock,
            'vdirect_client.rest_client': module_mock,
        }):
            from ansible.modules.network.radware import vdirect_file
            vdirect_file.rest_client.RESP_STATUS = 0
            vdirect_file.rest_client.Template = Template

            Template.set_create_from_source_result([409])
            Template.set_upload_source_result([400])
            file = vdirect_file.VdirectFile(NONE_PARAMS)
            path = os.path.dirname(os.path.abspath(__file__))
            result = file.upload(os.path.join(path, "ct.vm"))
            self.assertEqual(result, vdirect_file.CONFIGURATION_TEMPLATE_UPDATED_SUCCESS,
                             'Unexpected result received:' + repr(result))