def test__do_connect(self):
     connect_parameters = dict(domain='example.com',
                               username='******',
                               password='******')
     directory_services = ctera_filer_directory_services.CteraFilerDirectoryServices(
     )
     directory_services.parameters = copy.deepcopy(connect_parameters)
     directory_services.parameters['unused_param'] = True
     directory_services._do_connect()
     directory_services._ctera_filer.directoryservice.connect.assert_called_once_with(
         **connect_parameters)
     self.assertEqual(directory_services.ansible_return_value.param.msg,
                      'Connected to Active Directory')
     self.assertTrue(directory_services.ansible_return_value.param.changed)
 def _test__ensure_connected(is_connected):
     domain_dict = dict(domain='example.com' if is_connected else '')
     directory_services = ctera_filer_directory_services.CteraFilerDirectoryServices(
     )
     directory_services._handle_modify = mock.MagicMock()
     directory_services._do_connect = mock.MagicMock()
     directory_services._ensure_connected(domain_dict)
     if is_connected:
         directory_services._handle_modify.assert_called_once_with(
             domain_dict)
         directory_services._do_connect.assert_not_called()
     else:
         directory_services._handle_modify.assert_not_called()
         directory_services._do_connect.assert_called_once_with()
 def _test__execute(is_connected, desired):
     domain_dict = dict(domain='example.com' if is_connected else '')
     directory_services = ctera_filer_directory_services.CteraFilerDirectoryServices(
     )
     directory_services._ctera_filer.directoryservice.get_connected_domain.return_value = munch.Munch(
         domain_dict)
     directory_services.parameters = dict(
         state='connected' if desired else 'disconnected')
     directory_services._ensure_connected = mock.MagicMock()
     directory_services._ensure_disconnected = mock.MagicMock()
     directory_services._execute()
     if desired:
         directory_services._ensure_connected.assert_called_once_with(
             domain_dict)
         directory_services._ensure_disconnected.assert_not_called()
     else:
         directory_services._ensure_connected.assert_not_called()
         directory_services._ensure_disconnected.assert_called_once_with(
             domain_dict)
 def _test__ensure_disconnected(self, is_connected):
     domain_dict = dict(domain='example.com' if is_connected else '')
     directory_services = ctera_filer_directory_services.CteraFilerDirectoryServices(
     )
     directory_services._ensure_disconnected(domain_dict)
     if is_connected:
         directory_services._ctera_filer.directoryservice.disconnect.assert_called_once_with(
         )
         self.assertEqual(
             directory_services.ansible_return_value.param.msg,
             'Successfully disconnected the Filer from the Active Directory'
         )
         self.assertTrue(
             directory_services.ansible_return_value.param.changed)
     else:
         directory_services._ctera_filer.directoryservice.disconnect.assert_not_called(
         )
         self.assertEqual(
             directory_services.ansible_return_value.param.msg,
             'The Filer is already not connected to any Active Directory')
 def _test__handle_modify(self, change_domain, force_reconnect):
     current_domain_name = 'example.com'
     new_domain_name = 'new.com'
     directory_services = ctera_filer_directory_services.CteraFilerDirectoryServices(
     )
     directory_services.parameters = dict(
         domain=new_domain_name if change_domain else current_domain_name,
         force_reconnect=force_reconnect)
     directory_services._do_connect = mock.MagicMock()
     directory_services._handle_modify(dict(domain=current_domain_name))
     if (not change_domain) and (not force_reconnect):
         directory_services._ctera_filer.directoryservice.disconnect.assert_not_called(
         )
         directory_services._do_connect.assert_not_called()
         self.assertEqual(
             directory_services.ansible_return_value.param.msg,
             'The Filer is already connected to the Active Directory')
     else:
         directory_services._ctera_filer.directoryservice.disconnect.assert_called_once_with(
         )
         directory_services._do_connect.assert_called_once_with()