Commits

Marcin Lulek  committed a46c4ea Merge
  • Participants
  • Parent commits d5d1089, 65a9f9a

Comments (0)

Files changed (2)

File ziggurat_foundations/models.py

         """ fetch user by user name """
         db_session = get_db_session(db_session)
         q = db_session.query(cls)
-        q = q.filter(sa.func.lower(cls.user_name) == user_name.lower())
+        q = q.filter(sa.func.lower(cls.user_name) == (user_name or '').lower())
         q = q.options(sa.orm.eagerload('groups'))
         if invalidate:
             return True
         """ fetch user objects by user name and security code"""
         db_session = get_db_session(db_session)
         q = db_session.query(cls)
-        q = q.filter(sa.func.lower(cls.user_name) == user_name.lower())
+        q = q.filter(sa.func.lower(cls.user_name) == (user_name or '').lower())
         q = q.filter(cls.security_code == security_code)
         return q.first()
 
     def by_user_names(cls, user_names, cache='default',
                     invalidate=False, db_session=None):
         """ fetch user objects by user names """
-        user_names = [name.lower() for name in user_names]
+        user_names = [(name or '').lower() for name in user_names]
         db_session = get_db_session(db_session)
         q = db_session.query(cls)
         q = q.filter(sa.func.lower(cls.user_name).in_(user_names))
         """
         db_session = get_db_session(db_session)
         q = db_session.query(cls)
-        q = q.filter(sa.func.lower(cls.user_name).like(user_name.lower()))
+        q = q.filter(sa.func.lower(cls.user_name).like((user_name or '').lower()))
         q = q.order_by(cls.user_name)
         #q = q.options(sa.orm.eagerload('groups'))
         if invalidate:
         """ fetch user objects by email and username """
         db_session = get_db_session(db_session)
         q = db_session.query(cls).filter(cls.email == email)
-        q = q.filter(sa.func.lower(cls.user_name) == user_name.lower())
+        q = q.filter(sa.func.lower(cls.user_name) == (user_name or '').lower())
         q = q.options(sa.orm.eagerload('groups'))
         if invalidate:
             return True
         return sa.Column(sa.String(255), default=u'')
 
     @declared_attr
-    def access_token(cls):
-        return sa.Column(sa.String(255), default=u'')
-
-    @declared_attr
     def alt_token(cls):
         return sa.Column(sa.String(255), default=u'')
 

File ziggurat_foundations/tests.py

 
         self.assertEqual(queried_user, None)
 
+    def test_by_user_name_none(self):
+        queried_user = User.by_user_name(None, db_session=self.session)
+
+        self.assertEqual(None, queried_user)
+
     def test_by_username_andsecurity_code_existing(self):
         created_user = self._addUser()
         security_code = created_user.security_code
 
         self.assertEqual(queried_user, None)
 
+    def test_by_username_andsecurity_code_none(self):
+        created_user = self._addUser()
+        security_code = created_user.security_code
+        queried_user = User.by_user_name_and_security_code(
+            user_name=None,
+            security_code=security_code,
+            db_session=self.session
+        )
+
+        self.assertEqual(None, None)
+
     def test_by_user_names(self):
         user1 = self._addUser(u'user1', u'email1')
         self._addUser(u'user2', u'email2')
         self.assertEqual(user1, queried_users[0])
         self.assertEqual(user3, queried_users[1])
 
+    def test_by_user_names_one_none(self):
+        user1 = self._addUser(u'user1', u'email1')
+        self._addUser(u'user2', u'email2')
+        user3 = self._addUser(u'user3', u'email3')
+
+        queried_users = User.by_user_names([u'user1', None, u'user3'],
+                                           db_session=self.session).all()
+
+        self.assertEqual(len(queried_users), 2)
+        self.assertEqual(user1, queried_users[0])
+        self.assertEqual(user3, queried_users[1])
+
     def test_by_user_names_like(self):
         user1 = self._addUser(u'user1', u'email1')
         self._addUser(u'luser2', u'email2')
         self.assertEqual(len(queried_users), 1)
         self.assertEqual(user1, queried_users[0])
 
+    def test_by_user_names_like_none(self):
+
+        queried_users = User.user_names_like(None,
+                                             db_session=self.session).all()
+        self.assertEqual([], queried_users)
+
     def test_by_email(self):
         created_user = self._addUser()
         queried_user = User.by_email(u'email',db_session=self.session)
 
         self.assertEqual(created_user, queried_user)
 
+    def test_by_email_none(self):
+        created_user = self._addUser()
+        queried_user = User.by_email(None, db_session=self.session)
+
+        self.assertEqual(None, queried_user)
+
     def test_by_email_wrong_email(self):
         self._addUser()
         queried_user = User.by_email(u'wrong_email',db_session=self.session)
 
         self.assertEqual(queried_user, None)
 
+    def test_by_mail_and_username_none(self):
+        queried_user = User.by_email_and_username(u'email', None,
+                                                  db_session=self.session)
+
+        self.assertEqual(None, None)
+
     def test_gravatar_url(self):
         user = self._addUser()
         self.assertEqual(user.gravatar_url(),