def test_returning_user_with_remember_me(self, mocked):

        # get a valid login link/provider
        providers = OAuthProvider()
        valid_providers = providers.get_slugs()
        self.assertTrue(valid_providers)

        # create a mock object for Authomatic.login()
        mocked.return_value = MockAuthomatic()

        # create user and token
        user = User(email='*****@*****.**')
        user.remember_me_token = user.get_token()
        db.session.add(user)
        db.session.commit()

        # create cookies
        self.app.set_cookie('localhost', 'user_id', '1')
        self.app.set_cookie('localhost', 'remember_me', user.get_hash())

        # assert user is logged in
        resp = self.app.get('/')
        self.assertIn('href="/logout"', resp.data)
        self.assertNotIn('href="/login', resp.data)

        # clean cookis for next sessions
        self.app.delete_cookie('localhost', 'user_id')
        self.app.delete_cookie('localhost', 'remember_me')
 def test_token_and_hash(self):
     user = User()
     user.remember_me_token = user.get_token()
     self.assertTrue(user.check_hash(user.get_hash()))
     self.assertFalse(user.check_hash(''))
Exemple #3
0
 def test_token_and_hash(self):
     user = User()
     user.remember_me_token = user.get_token()
     self.assertTrue(user.check_hash(user.get_hash()))
     self.assertFalse(user.check_hash(''))