def test_saves_token_to_filesystem(self): directory = tempfile.mkdtemp() store = FileTokenStore(directory) token = YahooToken('some-token', 'some-secret') store.set('foo', token) with open(store.get_filepath('foo')) as stored_file: self.assertTrue('some-token' in stored_file.read())
def set(self, name, token): """Write a token to file""" if hasattr(token, 'key'): token = YahooToken.to_string(token) if token: filepath = self.get_filepath(name) f_handle = open(filepath, 'w') f_handle.write(token) f_handle.close()
def get(self, name): """Get a token from the filesystem""" filepath = self.get_filepath(name) if os.path.exists(filepath): f_handle = open(filepath, 'r') token = f_handle.read() f_handle.close() token = YahooToken.from_string(token) return token