def test_sync_all(self): """Test sync all imports users by checking the test user.""" with self.app.test_request_context(): # No users in db self.assertEqual(self.db['users'].count_documents({}), 0) ldap.sync_all() # Some users in db self.assertNotEqual(self.db['users'].count_documents({}), 0)
def test_sync_all(self): """Test sync all imports users by checking the test user.""" with self.app.test_request_context(): # No users in db self.assertEqual(self.db['users'].find().count(), 0) ldap.sync_all() # Some users in db self.assertNotEqual(self.db['users'].find().count(), 0)
def test_sync_all(self): """Test if sync_all builds the query correctly and creates users.""" # Shorten ou list self.app.config['LDAP_DEPARTMENT_MAP'] = {'a': 'itet'} expected_query = '(& (ou=VSETH Mitglied) (| (departmentNumber=*a*)) )' search_results = (i for i in [1, 2]) search = 'amivapi.ldap._search' create = 'amivapi.ldap._create_or_update_user' with patch(search, return_value=search_results) as mock_search: with patch(create, return_value=3) as mock_create: with self.app.app_context(): result = ldap.sync_all() mock_search.assert_called_with(expected_query) mock_create.assert_has_calls([call(1), call(2)]) self.assertEqual(result, [3, 3])
def ldap_sync(config, sync_all, nethz): """Synchronize users with eth ldap. Examples: amivapi ldap_sync --all amivapi ldap_sync adietmue bconrad blumh """ app = create_app(config_file=config) if not app.config['ldap_connector']: echo("LDAP is not enabled, can't proceed!") else: with app.test_request_context(): if sync_all: res = ldap.sync_all() echo("Synchronized %i users." % len(res)) else: for user in nethz: if ldap.sync_one(user) is not None: echo("Successfully synchronized '%s'." % user) else: echo("Could not synchronize '%s'." % user)