def test_user_can_login(self): response = self.client.post('/login', data={ 'email': self.user.email, 'password': '******', }) self.assertEquals(response.status_code, 302) session = Session.select().where(Session.user == self.user).first() self.assertTrue(self.feature.is_logged(session.token))
def get_current_user(self, token): session = Session.select().where(Session.token == token).first() if session: return User.get(User.id == session.user_id) return None
def is_logged(self, token): return Session.select().where(Session.token == token).exists()
def test_user_can_logout(self): response = self.client.post("/login", data={"email": self.user.email, "password": "******"}) self.assertEquals(response.status_code, 302) session = Session.select().where(Session.user == self.user).first() self.feature.logout(session.token) self.assertFalse(self.feature.is_logged(session.token))