Browse Source

HUE-9073 [fb] Enable unit tests for ADLS

Jean-Francois Desjeans Gauthier 6 years ago
parent
commit
9538e43ed7
2 changed files with 18 additions and 18 deletions
  1. 2 2
      desktop/libs/azure/src/azure/conf.py
  2. 16 16
      desktop/libs/azure/src/azure/tests.py

+ 2 - 2
desktop/libs/azure/src/azure/conf.py

@@ -145,10 +145,10 @@ ABFS_CLUSTERS = UnspecifiedConfigSection(
 )
 
 def is_adls_enabled():
-  return ('default' in list(AZURE_ACCOUNTS.keys() and AZURE_ACCOUNTS['default'].get_raw() and AZURE_ACCOUNTS['default'].CLIENT_ID.get()) or conf_idbroker.is_idbroker_enabled('azure')) and 'default' in list(ADLS_CLUSTERS.keys())
+  return ('default' in list(AZURE_ACCOUNTS.keys()) and AZURE_ACCOUNTS['default'].get_raw() and AZURE_ACCOUNTS['default'].CLIENT_ID.get() or conf_idbroker.is_idbroker_enabled('azure')) and 'default' in list(ADLS_CLUSTERS.keys())
 
 def is_abfs_enabled():
-  return ('default' in list(AZURE_ACCOUNTS.keys() and AZURE_ACCOUNTS['default'].get_raw() and AZURE_ACCOUNTS['default'].CLIENT_ID.get()) or conf_idbroker.is_idbroker_enabled('azure')) and 'default' in list(ABFS_CLUSTERS.keys())
+  return ('default' in list(AZURE_ACCOUNTS.keys()) and AZURE_ACCOUNTS['default'].get_raw() and AZURE_ACCOUNTS['default'].CLIENT_ID.get() or conf_idbroker.is_idbroker_enabled('azure')) and 'default' in list(ABFS_CLUSTERS.keys())
 
 def has_adls_access(user):
   from desktop.auth.backend import is_admin

+ 16 - 16
desktop/libs/azure/src/azure/tests.py

@@ -32,14 +32,11 @@ LOG = logging.getLogger(__name__)
 
 
 class TestAzureAdl(unittest.TestCase):
-  def setUp(self):
-    if not is_enabled('adl'):
-      raise SkipTest('adl not enabled')
-
 
   def test_with_credentials(self):
     try:
-      finish = conf.AZURE_ACCOUNTS.set_for_testing({'default': {'client_id':'client_id', 'client_secret': 'client_secret', 'tenant_id': 'tenant_id'}})
+      finish = (conf.AZURE_ACCOUNTS.set_for_testing({'default': {'client_id':'client_id', 'client_secret': 'client_secret', 'tenant_id': 'tenant_id'}}),
+                conf.ADLS_CLUSTERS.set_for_testing({'default': {'fs_defaultfs': 'fs_defaultfs', 'webhdfs_url': 'webhdfs_url'}}))
       with patch('azure.client.conf_idbroker.get_conf') as get_conf:
         with patch('azure.client.WebHdfs'):
           with patch('azure.client.ActiveDirectory.get_token') as get_token:
@@ -52,13 +49,15 @@ class TestAzureAdl(unittest.TestCase):
             assert_equal(provider.get_credentials().get('access_token'), 'access_token')
             assert_equal(client1, client2) # Should be the same as no support for user based client with credentials & no Expiration
     finally:
-      finish()
+      for f in finish:
+        f()
       clear_cache()
 
 
   def test_with_idbroker(self):
     try:
-      finish = conf.AZURE_ACCOUNTS.set_for_testing({}) # Set empty to test when no configs are set
+      finish = (conf.AZURE_ACCOUNTS.set_for_testing({}),
+                conf.ADLS_CLUSTERS.set_for_testing({'default': {'fs_defaultfs': 'fs_defaultfs', 'webhdfs_url': 'webhdfs_url'}}))
       with patch('azure.client.conf_idbroker.get_conf') as get_conf:
         with patch('azure.client.WebHdfs.get_client'):
           with patch('azure.client.IDBroker.get_cab') as get_cab:
@@ -81,19 +80,17 @@ class TestAzureAdl(unittest.TestCase):
             assert_equal(client3, client4) # Test that with 10 sec expiration, clients equal
             assert_not_equal(client4, client5) # Test different user have different clients
     finally:
-      finish()
+      for f in finish:
+        f()
       clear_cache()
 
 
 class TestAzureAbfs(unittest.TestCase):
-  def setUp(self):
-    if not is_enabled('abfs'):
-      raise SkipTest('abfs not enabled')
-
 
   def test_with_credentials(self):
     try:
-      finish = conf.AZURE_ACCOUNTS.set_for_testing({'default': {'client_id':'client_id', 'client_secret': 'client_secret', 'tenant_id': 'tenant_id'}})
+      finish = (conf.AZURE_ACCOUNTS.set_for_testing({'default': {'client_id':'client_id', 'client_secret': 'client_secret', 'tenant_id': 'tenant_id'}}),
+                conf.ABFS_CLUSTERS.set_for_testing({'default': {'fs_defaultfs': 'fs_defaultfs', 'webhdfs_url': 'webhdfs_url'}}))
       with patch('azure.client.conf_idbroker.get_conf') as get_conf:
         with patch('azure.client.ABFS'):
           with patch('azure.client.ActiveDirectory.get_token') as get_token:
@@ -106,13 +103,15 @@ class TestAzureAbfs(unittest.TestCase):
             assert_equal(provider.get_credentials().get('access_token'), 'access_token')
             assert_equal(client1, client2) # Should be the same as no support for user based client with credentials & no Expiration
     finally:
-      finish()
+      for f in finish:
+        f()
       clear_cache()
 
 
   def test_with_idbroker(self):
     try:
-      finish = conf.AZURE_ACCOUNTS.set_for_testing({}) # Set empty to test when no configs are set
+      finish = (conf.AZURE_ACCOUNTS.set_for_testing({}),
+                conf.ABFS_CLUSTERS.set_for_testing({'default': {'fs_defaultfs': 'fs_defaultfs', 'webhdfs_url': 'webhdfs_url'}}))
       with patch('azure.client.conf_idbroker.get_conf') as get_conf:
         with patch('azure.client.ABFS.get_client'):
           with patch('azure.client.IDBroker.get_cab') as get_cab:
@@ -135,5 +134,6 @@ class TestAzureAbfs(unittest.TestCase):
             assert_equal(client3, client4) # Test that with 10 sec expiration, clients equal
             assert_not_equal(client4, client5) # Test different user have different clients
     finally:
-      finish()
+      for f in finish:
+        f()
       clear_cache()