Esempio n. 1
0
 def test_in_memory(self):
     from happy.login import RandomUUIDCredentialBroker
     broker = RandomUUIDCredentialBroker()
     credential = broker.login('fumanchu')
     self.assertEqual(broker.get_login(credential), 'fumanchu')
     broker.logout(credential)
     self.assertEqual(broker.get_login(credential), None)
Esempio n. 2
0
    def test_persistent(self):
        import os
        import tempfile
        tmpdir = tempfile.mkdtemp('_happy_test')
        db_file = os.path.join(tmpdir, 'credentials.db')

        try:
            from happy.login import RandomUUIDCredentialBroker
            broker = RandomUUIDCredentialBroker(db_file)
            credential = broker.login('fumanchu')
            self.assertEqual(broker.get_login(credential), 'fumanchu')

            broker = RandomUUIDCredentialBroker(db_file)
            self.assertEqual(broker.get_login(credential), 'fumanchu')

            broker.logout(credential)
            self.assertEqual(broker.get_login(credential), None)

            broker = RandomUUIDCredentialBroker(db_file)
            self.assertEqual(broker.get_login(credential), None)

        finally:
            import shutil
            shutil.rmtree(tmpdir)