# Path: yql/storage.py
# class FileTokenStore(BaseTokenStore):
#     """A simple filesystem based token store
# 
#     Note: this is more intended as an example rather than
#     something for heavy duty production usage.
# 
#     """
# 
#     def __init__(self, dir_path, secret=None):
#         """Initialize token storage"""
# 
#         if not os.path.exists(dir_path):
#             raise TokenStoreError("Path is not valid")
# 
#         self.base_dir = dir_path
#         self.secret = secret or SECRET
# 
#     def get_filepath(self, name):
#         """Build filepath"""
# 
#         filename = md5("%s%s" % (name, self.secret)).hexdigest()
#         filepath = os.path.join(self.base_dir, filename)
# 
#         return filepath
# 
#     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


import os
import sys
import yql
from time import time
from unittest import TestCase
from nose.plugins.skip import SkipTest
from yql.storage import FileTokenStore
    from secrets import *
        res = y.execute(query)
        assert res.one()["data"]["url"] == "http://yhoo.it/9PPTOr"

    def test_public_request(self):
        """Test public two-legged request to flickr"""
        query = """select * from flickr.photos.search where
                   text="panda" and api_key='%s' LIMIT 3""" % FLICKR_API_KEY
        y = yql.TwoLegged(YQL_API_KEY, YQL_SHARED_SECRET)
        res = y.execute(query)
        assert len(res.rows) == 3

    def test_two_legged_weather_select(self):
        """Tests the weather tables using two-legged"""
        query = """select * from weather.forecast where location in
                (select id from xml where
                url='http://xoap.weather.com/search/search?where=london'
                and itemPath='search.loc')"""
        y = yql.TwoLegged(YQL_API_KEY, YQL_SHARED_SECRET)
        res = y.execute(query)
        assert len(res.rows) > 1

    def test_update_social_status(self):
        """Updates status"""
        y = yql.ThreeLegged(YQL_API_KEY, YQL_SHARED_SECRET)

        timestamp = time()
        query = """UPDATE social.profile.status
                   SET status='Using YQL. %s Update'
                   WHERE guid=me"""  % timestamp


# Path: yql/storage.py
# class FileTokenStore(BaseTokenStore):
#     """A simple filesystem based token store
# 
#     Note: this is more intended as an example rather than
#     something for heavy duty production usage.
# 
#     """
# 
#     def __init__(self, dir_path, secret=None):
#         """Initialize token storage"""
# 
#         if not os.path.exists(dir_path):
#             raise TokenStoreError("Path is not valid")
# 
#         self.base_dir = dir_path
#         self.secret = secret or SECRET
# 
#     def get_filepath(self, name):
#         """Build filepath"""
# 
#         filename = md5("%s%s" % (name, self.secret)).hexdigest()
#         filepath = os.path.join(self.base_dir, filename)
# 
#         return filepath
# 
#     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


# Path: yql/tests/test_live_services.py
import os
import sys
import yql
from time import time
from unittest import TestCase
from nose.plugins.skip import SkipTest
from yql.storage import FileTokenStore
    from secrets import *

        res = y.execute(query)
        assert res.one()["data"]["url"] == "http://yhoo.it/9PPTOr"

    def test_public_request(self):
        """Test public two-legged request to flickr"""
        query = """select * from flickr.photos.search where
                   text="panda" and api_key='%s' LIMIT 3""" % FLICKR_API_KEY
        y = yql.TwoLegged(YQL_API_KEY, YQL_SHARED_SECRET)
        res = y.execute(query)
        assert len(res.rows) == 3

    def test_two_legged_weather_select(self):
        """Tests the weather tables using two-legged"""
        query = """select * from weather.forecast where location in
                (select id from xml where
                url='http://xoap.weather.com/search/search?where=london'
                and itemPath='search.loc')"""
        y = yql.TwoLegged(YQL_API_KEY, YQL_SHARED_SECRET)
        res = y.execute(query)
        assert len(res.rows) > 1

    def test_update_social_status(self):
        """Updates status"""
        y = yql.ThreeLegged(YQL_API_KEY, YQL_SHARED_SECRET)

        timestamp = time()
        query = """UPDATE social.profile.status
                   SET status='Using YQL. %s Update'
                   WHERE guid=me"""  % timestamp


        token_store = FileTokenStore(CACHE_DIR, secret='gsfdsfdsfdsfs')