def get_user_profile(self): """Return the UserProfile instance for the given request, or create one if none is found. """ try: return UserProfile.load(self.request.cookies['profile']), False except KeyError: profile = UserProfile() self.response.set_cookie('profile', profile.profile_id) return profile, True
def test_load_profile(self): from gravita.user_profile import UserProfile ups = [UserProfile() for i in range(10)] for i, p in enumerate(up for up in ups): self.assertTrue(UserProfile.load(p.profile_id) is ups[i])