浏览代码

[core] Fix LDAP tests

Abraham Elmahrek 11 年之前
父节点
当前提交
2dc9729
共有 2 个文件被更改,包括 48 次插入41 次删除
  1. 10 7
      apps/useradmin/src/useradmin/test_ldap.py
  2. 38 34
      apps/useradmin/src/useradmin/test_ldap_deprecated.py

+ 10 - 7
apps/useradmin/src/useradmin/test_ldap.py

@@ -683,20 +683,23 @@ def test_ensure_home_directory_add_ldap_users():
     assert_false(cluster.fs.exists('/user/moe'))
 
     # Try wild card now
-    response = c.post(URL, dict(server='nonsense', username_pattern='*r*', password1='test', password2='test', ensure_home_directory=True))
+    response = c.post(URL, dict(server='nonsense', username_pattern='*rr*', password1='test', password2='test', ensure_home_directory=True))
     assert_true('/useradmin/users' in response['Location'])
     assert_true(cluster.fs.exists('/user/curly'))
     assert_true(cluster.fs.exists(u'/user/lårry'))
-    assert_true(cluster.fs.exists('/user/otherguy'))
-
-    # Clean up
-    cluster.fs.rmtree('/user/curly')
-    cluster.fs.rmtree(u'/user/lårry')
-    cluster.fs.rmtree('/user/otherguy')
+    assert_false(cluster.fs.exists('/user/otherguy'))
   finally:
+    # Clean up
     for finish in reset:
       finish()
 
+    if cluster.fs.exists('/user/curly'):
+      cluster.fs.rmtree('/user/curly')
+    if cluster.fs.exists(u'/user/lårry'):
+      cluster.fs.rmtree(u'/user/lårry')
+    if cluster.fs.exists('/user/otherguy'):
+      cluster.fs.rmtree('/user/otherguy')
+
 @attr('requires_hadoop')
 def test_ensure_home_directory_sync_ldap_users_groups():
   URL = reverse(sync_ldap_users_groups)

+ 38 - 34
apps/useradmin/src/useradmin/test_ldap_deprecated.py

@@ -572,47 +572,51 @@ def test_ldap_exception_handling():
 
 @attr('requires_hadoop')
 def test_ensure_home_directory_add_ldap_users():
-  URL = reverse(add_ldap_users)
-
-  reset_all_users()
-  reset_all_groups()
-
-  # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
-  ldap_access.CACHED_LDAP_CONN = LdapTestConnection()
-
-  cluster = pseudo_hdfs4.shared_cluster()
-  c = make_logged_in_client(cluster.superuser, is_superuser=True)
-  cluster.fs.setuser(cluster.superuser)
+  try:
+    URL = reverse(add_ldap_users)
 
-  assert_true(c.get(URL))
+    reset_all_users()
+    reset_all_groups()
 
-  response = c.post(URL, dict(username_pattern='moe', password1='test', password2='test'))
-  assert_true('/useradmin/users' in response['Location'])
-  assert_false(cluster.fs.exists('/user/moe'))
+    # Set up LDAP tests to use a LdapTestConnection instead of an actual LDAP connection
+    ldap_access.CACHED_LDAP_CONN = LdapTestConnection()
 
-  # Try same thing with home directory creation.
-  response = c.post(URL, dict(username_pattern='curly', password1='test', password2='test', ensure_home_directory=True))
-  assert_true('/useradmin/users' in response['Location'])
-  assert_true(cluster.fs.exists('/user/curly'))
+    cluster = pseudo_hdfs4.shared_cluster()
+    c = make_logged_in_client(cluster.superuser, is_superuser=True)
+    cluster.fs.setuser(cluster.superuser)
 
-  response = c.post(URL, dict(username_pattern='bad_name', password1='test', password2='test'))
-  assert_true('Could not' in response.context['form'].errors['username_pattern'][0])
-  assert_false(cluster.fs.exists('/user/bad_name'))
+    assert_true(c.get(URL))
 
-  # See if moe, who did not ask for his home directory, has a home directory.
-  assert_false(cluster.fs.exists('/user/moe'))
+    response = c.post(URL, dict(username_pattern='moe', password1='test', password2='test'))
+    assert_true('/useradmin/users' in response['Location'])
+    assert_false(cluster.fs.exists('/user/moe'))
 
-  # Try wild card now
-  response = c.post(URL, dict(username_pattern='*r*', password1='test', password2='test', ensure_home_directory=True))
-  assert_true('/useradmin/users' in response['Location'])
-  assert_true(cluster.fs.exists('/user/curly'))
-  assert_true(cluster.fs.exists(u'/user/lårry'))
-  assert_true(cluster.fs.exists('/user/otherguy'))
+    # Try same thing with home directory creation.
+    response = c.post(URL, dict(username_pattern='curly', password1='test', password2='test', ensure_home_directory=True))
+    assert_true('/useradmin/users' in response['Location'])
+    assert_true(cluster.fs.exists('/user/curly'))
 
-  # Clean up
-  cluster.fs.rmtree('/user/curly')
-  cluster.fs.rmtree(u'/user/lårry')
-  cluster.fs.rmtree('/user/otherguy')
+    response = c.post(URL, dict(username_pattern='bad_name', password1='test', password2='test'))
+    assert_true('Could not' in response.context['form'].errors['username_pattern'][0])
+    assert_false(cluster.fs.exists('/user/bad_name'))
+
+    # See if moe, who did not ask for his home directory, has a home directory.
+    assert_false(cluster.fs.exists('/user/moe'))
+
+    # Try wild card now
+    response = c.post(URL, dict(username_pattern='*rr*', password1='test', password2='test', ensure_home_directory=True))
+    assert_true('/useradmin/users' in response['Location'])
+    assert_true(cluster.fs.exists('/user/curly'))
+    assert_true(cluster.fs.exists(u'/user/lårry'))
+    assert_false(cluster.fs.exists('/user/otherguy'))
+  finally:
+    # Clean up
+    if cluster.fs.exists('/user/curly'):
+      cluster.fs.rmtree('/user/curly')
+    if cluster.fs.exists(u'/user/lårry'):
+      cluster.fs.rmtree(u'/user/lårry')
+    if cluster.fs.exists('/user/otherguy'):
+      cluster.fs.rmtree('/user/otherguy')
 
 @attr('requires_hadoop')
 def test_ensure_home_directory_sync_ldap_users_groups():