From 3913586e2d9b69fa067e361a79d1feb662f38321 Mon Sep 17 00:00:00 2001 From: Karl MacMillan Date: Sun, 10 Apr 2016 22:35:07 -0400 Subject: [PATCH] Make webapp2_extras/appengine/auth/models.User.validate_token return UserToken or None. Make the implementation of webapp2_extras/appengine/auth/models.User.validate_token match the documentation and return the UserToken instead of Bool. Also correct the unit tests. This fixes issue #102. --- tests/extras_appengine_auth_models_test.py | 8 ++++---- webapp2_extras/appengine/auth/models.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/extras_appengine_auth_models_test.py b/tests/extras_appengine_auth_models_test.py index 42a3649..f80790a 100644 --- a/tests/extras_appengine_auth_models_test.py +++ b/tests/extras_appengine_auth_models_test.py @@ -141,14 +141,14 @@ def test_user_token(self): auth_id = 'foo' token = m.create_auth_token(auth_id) - self.assertTrue(m.validate_auth_token(auth_id, token)) + self.assertTrue(m.validate_auth_token(auth_id, token) != None) m.delete_auth_token(auth_id, token) - self.assertFalse(m.validate_auth_token(auth_id, token)) + self.assertNone(m.validate_auth_token(auth_id, token)) token = m.create_signup_token(auth_id) - self.assertTrue(m.validate_signup_token(auth_id, token)) + self.assertTrue(m.validate_signup_token(auth_id, token) != None) m.delete_signup_token(auth_id, token) - self.assertFalse(m.validate_signup_token(auth_id, token)) + self.assertNone(m.validate_signup_token(auth_id, token)) class TestUniqueModel(test_base.BaseTestCase): diff --git a/webapp2_extras/appengine/auth/models.py b/webapp2_extras/appengine/auth/models.py index 21dd9a1..4992b72 100644 --- a/webapp2_extras/appengine/auth/models.py +++ b/webapp2_extras/appengine/auth/models.py @@ -330,7 +330,7 @@ def validate_token(cls, user_id, subject, token): A :class:`UserToken` or None if the token does not exist. """ return cls.token_model.get(user=user_id, subject=subject, - token=token) is not None + token=token) @classmethod def create_auth_token(cls, user_id):