Procházet zdrojové kódy

HUE-3287 [core] Django 1.11 upgrade
- adding Enum related fixes
fixing test

Prakash Ranade před 7 roky
rodič
revize
53129c9054

+ 1 - 1
apps/beeswax/src/beeswax/templates/list_history.mako

@@ -133,7 +133,7 @@ ${ layout.menubar(section='history') }
                     % endif
                   </td>
                   <td>${query.owner}</td>
-                  <td>${models.QueryHistory.STATE[query.last_state]}</td>
+                  <td>${query.last_state}</td>
                   <td>
                     % if query.last_state not in (models.QueryHistory.STATE.expired.value, models.QueryHistory.STATE.failed.value):
                       <a href="${ url(app_name + ':watch_query_history', query_history_id=query.id) }" data-row-selector="true">${_('Results')}</a>

+ 1 - 1
apps/beeswax/src/beeswax/templates/my_queries.mako

@@ -149,7 +149,7 @@ ${layout.menubar(section='my queries')}
               <code>${ collapse_whitespace(query.query) }</code>
               % endif
             </td>
-            <td width="9%">${models.QueryHistory.STATE[query.last_state]}</td>
+            <td width="9%">${query.last_state}</td>
           </tr>
         % endfor
         </tbody>

+ 2 - 2
apps/beeswax/src/beeswax/tests.py

@@ -138,7 +138,7 @@ class TestBeeswaxWithHadoop(BeeswaxSampleProvider):
     resp = self.client.get('/beeswax/query_history')
     history = resp.context[0]['page'].object_list[0]
     last_state = history.last_state
-    assert_true(beeswax.models.QueryHistory.STATE[last_state] in (state,) + extra_states)
+    assert_true(last_state in (state,) + extra_states)
     return history.id
 
 
@@ -209,7 +209,7 @@ for x in sys.stdin:
 
     resp = self.client.get('/beeswax/query_history')
     history = resp.context[0]['page'].object_list[0]
-    assert_equal(beeswax.models.QueryHistory.STATE[history.last_state], beeswax.models.QueryHistory.STATE.expired)
+    assert_equal(history.last_state, beeswax.models.QueryHistory.STATE.expired)
 
 
   def test_basic_flow(self):

+ 2 - 2
apps/useradmin/src/useradmin/middleware.py

@@ -54,7 +54,7 @@ class LdapSynchronizationMiddleware(object):
     if not user or not user.is_authenticated():
       return
 
-    if not User.objects.filter(username=user.username, userprofile__creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists():
+    if not User.objects.filter(username=user.username, userprofile__creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists():
       LOG.warn("User %s is not an Ldap user" % user.username)
       return
 
@@ -132,4 +132,4 @@ class ConcurrentUserSessionMiddleware(object):
               session.save()
             else:
               count += 1
-    return response
+    return response

+ 1 - 1
apps/useradmin/src/useradmin/old_migrations/0002_add_ldap_support.py

@@ -27,7 +27,7 @@ class Migration(DataMigration):
 
         # Adding field 'UserProfile.creation_method'
         try:
-          db.add_column('useradmin_userprofile', 'creation_method', self.gf('django.db.models.fields.CharField')(max_length=64, default=str(UserProfile.CreationMethod.HUE)), keep_default=False)
+          db.add_column('useradmin_userprofile', 'creation_method', self.gf('django.db.models.fields.CharField')(max_length=64, default=UserProfile.CreationMethod.HUE.name), keep_default=False)
         except Exception:
           # It's possible that we could run into an error here, because this
           # table may have been migrated from Cloudera Enterprise, in which case

+ 3 - 3
apps/useradmin/src/useradmin/test_ldap.py

@@ -420,7 +420,7 @@ class TestUserAdminLdap(BaseUserAdminTests):
       assert_true(larry.first_name == 'Larry')
       assert_true(larry.last_name == 'Stooge')
       assert_true(larry.email == 'larry@stooges.com')
-      assert_true(get_profile(larry).creation_method == str(UserProfile.CreationMethod.EXTERNAL))
+      assert_true(get_profile(larry).creation_method == UserProfile.CreationMethod.EXTERNAL.name)
 
       # Should be a noop
       sync_ldap_users(ldap_access.CACHED_LDAP_CONN)
@@ -433,7 +433,7 @@ class TestUserAdminLdap(BaseUserAdminTests):
       hue_user = User.objects.create(username='otherguy', first_name='Different', last_name='Guy')
       import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'otherguy', sync_groups=False, import_by_dn=False)
       hue_user = User.objects.get(username='otherguy')
-      assert_equal(get_profile(hue_user).creation_method, str(UserProfile.CreationMethod.HUE))
+      assert_equal(get_profile(hue_user).creation_method, UserProfile.CreationMethod.HUE.name)
       assert_equal(hue_user.first_name, 'Different')
 
       # Make sure LDAP groups exist or they won't sync
@@ -445,7 +445,7 @@ class TestUserAdminLdap(BaseUserAdminTests):
       assert_equal(curly.first_name, 'Curly')
       assert_equal(curly.last_name, 'Stooge')
       assert_equal(curly.email, 'curly@stooges.com')
-      assert_equal(get_profile(curly).creation_method, str(UserProfile.CreationMethod.EXTERNAL))
+      assert_equal(get_profile(curly).creation_method, UserProfile.CreationMethod.EXTERNAL.name)
       assert_equal(2, curly.groups.all().count(), curly.groups.all())
 
       reset_all_users()

+ 3 - 3
apps/useradmin/src/useradmin/test_ldap_deprecated.py

@@ -377,7 +377,7 @@ class TestUserAdminLdapDeprecated(BaseUserAdminTests):
       assert_true(larry.first_name == 'Larry')
       assert_true(larry.last_name == 'Stooge')
       assert_true(larry.email == 'larry@stooges.com')
-      assert_true(get_profile(larry).creation_method == str(UserProfile.CreationMethod.EXTERNAL))
+      assert_true(get_profile(larry).creation_method == UserProfile.CreationMethod.EXTERNAL.name)
 
       # Should be a noop
       sync_ldap_users(ldap_access.CACHED_LDAP_CONN)
@@ -390,7 +390,7 @@ class TestUserAdminLdapDeprecated(BaseUserAdminTests):
       hue_user = User.objects.create(username='otherguy', first_name='Different', last_name='Guy')
       import_ldap_users(ldap_access.CACHED_LDAP_CONN, 'otherguy', sync_groups=False, import_by_dn=False)
       hue_user = User.objects.get(username='otherguy')
-      assert_equal(get_profile(hue_user).creation_method, str(UserProfile.CreationMethod.HUE))
+      assert_equal(get_profile(hue_user).creation_method, UserProfile.CreationMethod.HUE.name)
       assert_equal(hue_user.first_name, 'Different')
 
       # Make sure LDAP groups exist or they won't sync
@@ -402,7 +402,7 @@ class TestUserAdminLdapDeprecated(BaseUserAdminTests):
       assert_equal(curly.first_name, 'Curly')
       assert_equal(curly.last_name, 'Stooge')
       assert_equal(curly.email, 'curly@stooges.com')
-      assert_equal(get_profile(curly).creation_method, str(UserProfile.CreationMethod.EXTERNAL))
+      assert_equal(get_profile(curly).creation_method, UserProfile.CreationMethod.EXTERNAL.name)
       assert_equal(2, curly.groups.all().count(), curly.groups.all())
 
       reset_all_users()

+ 3 - 3
apps/useradmin/src/useradmin/views.py

@@ -766,7 +766,7 @@ def sync_ldap_users(connection, failed_users=None):
   group at the same time. Each must be a separate operation. If neither a user,
   nor a group is provided, all users and groups will be synced.
   """
-  users = User.objects.filter(userprofile__creation_method=str(UserProfile.CreationMethod.EXTERNAL)).all()
+  users = User.objects.filter(userprofile__creation_method=UserProfile.CreationMethod.EXTERNAL.name).all()
   for user in users:
     _import_ldap_users(connection, user.username, failed_users=failed_users)
   return users
@@ -912,7 +912,7 @@ def _import_ldap_users_info(connection, user_info, sync_groups=False, import_by_
 
       user, created = ldap_access.get_or_create_ldap_user(username=ldap_info['username'])
       profile = get_profile(user)
-      if not created and profile.creation_method == str(UserProfile.CreationMethod.HUE):
+      if not created and profile.creation_method == UserProfile.CreationMethod.HUE.name:
         # This is a Hue user, and shouldn't be overwritten
         LOG.warn(_('There was a naming conflict while importing user %(username)s') % {
           'username': ldap_info['username']
@@ -932,7 +932,7 @@ def _import_ldap_users_info(connection, user_info, sync_groups=False, import_by_
       if 'email' in ldap_info:
         user.email = ldap_info['email']
 
-      profile.creation_method = UserProfile.CreationMethod.EXTERNAL
+      profile.creation_method = UserProfile.CreationMethod.EXTERNAL.name
       profile.save()
       user.save()
       imported_users.append(user)

+ 2 - 2
desktop/core/src/desktop/auth/backend.py

@@ -443,7 +443,7 @@ class LdapBackend(object):
 
     # Do this check up here, because the auth call creates a django user upon first login per user
     is_super = False
-    if not UserProfile.objects.filter(creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists():
+    if not UserProfile.objects.filter(creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists():
       # If there are no LDAP users already in the system, the first one will
       # become a superuser
       is_super = True
@@ -453,7 +453,7 @@ class LdapBackend(object):
       # user, we should do the safe thing and turn off superuser privs.
       existing_user = User.objects.get(**username_filter_kwargs)
       existing_profile = get_profile(existing_user)
-      if existing_profile.creation_method == str(UserProfile.CreationMethod.EXTERNAL):
+      if existing_profile.creation_method == UserProfile.CreationMethod.EXTERNAL.name:
         is_super = User.objects.get(**username_filter_kwargs).is_superuser
     elif not desktop.conf.LDAP.CREATE_USERS_ON_LOGIN.get():
       LOG.warn("Create users when they login with their LDAP credentials is turned off")

+ 2 - 2
desktop/libs/liboauth/src/liboauth/backend.py

@@ -58,7 +58,7 @@ class OAuthBackend(DesktopBackendBase):
         user = User.objects.get(username=username)
     except User.DoesNotExist:
 
-      if not UserProfile.objects.filter(creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists():
+      if not UserProfile.objects.filter(creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists():
         is_super = True
       else:
         is_super = False
@@ -87,7 +87,7 @@ class OAuthBackend(DesktopBackendBase):
   @classmethod
   def is_first_login_ever(cls):
     """ Return true if no external user has ever logged in to Desktop yet. """
-    return not UserProfile.objects.filter(creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists()
+    return not UserProfile.objects.filter(creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists()
   
 
   @classmethod

+ 3 - 3
desktop/libs/libopenid/src/libopenid/backend.py

@@ -48,7 +48,7 @@ class OpenIDBackend(_OpenIDBackend):
     # Do this check up here, because the auth call creates a django user upon first login per user
     is_super = False
 
-    if not UserProfile.objects.filter(creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists():
+    if not UserProfile.objects.filter(creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists():
       # If there are no external users already in the system, the first one will
       # become a superuser
       is_super = True
@@ -58,7 +58,7 @@ class OpenIDBackend(_OpenIDBackend):
       # user, we should do the safe thing and turn off superuser privs.
       user = User.objects.get(username=user.username)
       existing_profile = get_profile(user)
-      if existing_profile.creation_method == str(UserProfile.CreationMethod.EXTERNAL):
+      if existing_profile.creation_method == UserProfile.CreationMethod.EXTERNAL.name:
         is_super = user.is_superuser
 
 
@@ -90,4 +90,4 @@ class OpenIDBackend(_OpenIDBackend):
   @classmethod
   def is_first_login_ever(cls):
     """ Return true if no external user has ever logged in to Desktop yet. """
-    return not UserProfile.objects.filter(creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists()
+    return not UserProfile.objects.filter(creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists()

+ 2 - 2
desktop/libs/libsaml/src/libsaml/backend.py

@@ -71,7 +71,7 @@ class SAML2Backend(_Saml2Backend):
   def update_user(self, user, attributes, attribute_mapping, force_save=False):
     # Do this check up here, because the auth call creates a django user upon first login per user
     is_super = False
-    if not UserProfile.objects.filter(creation_method=str(UserProfile.CreationMethod.EXTERNAL)).exists():
+    if not UserProfile.objects.filter(creation_method=UserProfile.CreationMethod.EXTERNAL.name).exists():
       # If there are no LDAP users already in the system, the first one will
       # become a superuser
       is_super = True
@@ -82,7 +82,7 @@ class SAML2Backend(_Saml2Backend):
         # privileges. However, if there's a naming conflict with a non-external
         # user, we should do the safe thing and turn off superuser privs.
         existing_profile = get_profile(user)
-        if existing_profile.creation_method == str(UserProfile.CreationMethod.EXTERNAL):
+        if existing_profile.creation_method == UserProfile.CreationMethod.EXTERNAL.name:
           is_super = user.is_superuser
 
     user = super(SAML2Backend, self).update_user(user, attributes, attribute_mapping, force_save)