def test_fetch_latest_onpoints(self):
     basedir = self.standardpath
     downloader = Downloader()
     downloader.fs = FileSystem()
     subs = Subscriptions(downloader, self.standardpath)
     asub = subs.find("wbur")
     self.assertNotEqual(None,asub)
Exemple #2
0
 def __init__(self,
              name="",
              client_id=None,
              client_secret=None,
              emulator=False,
              debug=True,
              template_folder='templates'):
     self.name = name
     self.emulator = emulator
     self.debug = debug
     self.web = flask.Flask(self.name,
                            static_folder=os.path.join(
                                os.path.dirname(os.path.abspath(__file__)),
                                'emulator'),
                            static_url_path='/emulator')
     self.template_folder = template_folder
     self.logger = self.web.logger
     self.emulator_service = Emulator(app=self)
     self.subscriptions = Subscriptions(app=self)
     self.oauth = rauth.OAuth2Service(
         name=self.name,
         client_id=client_id,
         client_secret=client_secret,
         access_token_url=self.OAUTH_ACCESS_TOKEN_URL,
         authorize_url=self.OAUTH_AUTHORIZE_URL,
         base_url=self.OAUTH_API_BASE_URL)
Exemple #3
0
 def __init__(self, 
             name="",
             client_id=None,
             client_secret=None,
             scopes=OAUTH_SCOPES,
             debug=False,
             template_folder='templates',
             **flaskargs):
     self.name = name
     self.debug = debug
     self.web = flask.Flask(self.name, **flaskargs)
     self.template_folder = template_folder
     self.logger = self.web.logger
     self.scopes = scopes
     self.subscriptions = Subscriptions(app=self)
     self.oauth = rauth.OAuth2Service(name=self.name,
                               client_id=client_id,
                               client_secret=client_secret,
                               access_token_url=OAUTH_ACCESS_TOKEN_URL,
                               authorize_url=OAUTH_AUTHORIZE_URL,
                               base_url=OAUTH_API_BASE_URL)
def get_subscription_dsentry_matched_to_subscription(fullSubscriptionToMatch):
    all = Subscriptions.getSubscriptions()
    for subsDS in all:
        ds_topic_project = subsDS.topic_project
        ds_subscription_project = getOwningProject()
        ds_topic = subsDS.topic_to_subscribe
        subscriptionName = buildSubscriptionName(ds_topic_project, ds_topic)
        fullName = buildFullSubscriptionName(ds_subscription_project, subscriptionName)        
        if fullName == fullSubscriptionToMatch:
            #match
            return subsDS

    return None
def check_and_create_subscriptions():

    if Subscriptions.IsSubscriptionNameFullySet() == True:
        all = Subscriptions.getSubscriptions()

        for subs_to_create in all:
            topic_project = subs_to_create.topic_project
            subscription_project = getOwningProject()
            topic = subs_to_create.topic_to_subscribe
            subscriptionName = buildSubscriptionName(topic_project, topic)
                
            if not check_subscription_exists(subscription_project, subscriptionName):
                
                create_subscription(subscription_project, topic_project, topic, subscriptionName)


    else:
        logging.info('no subscriptions to set as names not set in Subscriptions datastore')
Exemple #6
0
    def test_pay_order_with_subscription(self):
        expected_mail = Mail(
            address='*****@*****.**',
            subject='24/7 sl terminal show subscription',
            body=
            ('Hello Ofelia\n'
             'You have been subscribed to "24/7 sl terminal show" for 12 months\n'
             ))
        customer = Customer('Ofelia', '*****@*****.**')
        credit_card = CreditCard.fetch_by_hashed('01234-4321')
        order = Order(customer, Address('42100'))
        order.add_product(Product('24/7 sl terminal show',
                                  ProductType.MEMBERSHIP,
                                  price=20),
                          quantity=12)

        order_service.pay(order, credit_card)

        assert expected_mail in EmailClient.queue
        assert '24/7 sl terminal show' in Subscriptions.by_customer(customer)
Exemple #7
0
 def __init__(self, 
             name="",
             client_id=None,
             client_secret=None,
             scopes=OAUTH_SCOPES,
             debug=True,
             template_folder='templates',
             **flaskargs):
     self.name = name
     self.debug = debug
     self.web = flask.Flask(self.name, **flaskargs)
     self.template_folder = template_folder
     self.logger = self.web.logger
     self.scopes = scopes
     self.subscriptions = Subscriptions(app=self)
     self.oauth = rauth.OAuth2Service(name=self.name,
                               client_id=client_id,
                               client_secret=client_secret,
                               access_token_url=OAUTH_ACCESS_TOKEN_URL,
                               authorize_url=OAUTH_AUTHORIZE_URL,
                               base_url=OAUTH_API_BASE_URL)
Exemple #8
0
 def __init__(self, 
             name="",
             client_id=None,
             client_secret=None,
             emulator=False,
             debug=True,
             template_folder='templates'):
     self.name = name
     self.emulator = emulator
     self.debug = debug
     self.web = flask.Flask(self.name,
         static_folder=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'emulator'),
         static_url_path='/emulator')
     self.template_folder = template_folder
     self.logger = self.web.logger
     self.emulator_service = Emulator(app=self)
     self.subscriptions = Subscriptions(app=self)
     self.oauth = rauth.OAuth2Service(name=self.name,
                               client_id=client_id,
                               client_secret=client_secret,
                               access_token_url=self.OAUTH_ACCESS_TOKEN_URL,
                               authorize_url=self.OAUTH_AUTHORIZE_URL,
                               base_url=self.OAUTH_API_BASE_URL)
Exemple #9
0
    def test_it_orders_a_service_subscription_item(self):
        expected_mail = Mail(
            address='*****@*****.**',
            subject='Netflix subscription',
            body=(
                'Hello Cuenta Puertas\n'
                'You have been subscribed to "Netflix" for 2 months\n'
            )
        )
        customer = Customer('Cuenta Puertas', email='*****@*****.**')
        credit_card = CreditCard.fetch_by_hashed('43567890-987654367')
        item = Product(name='Netflix', type=ProductType.MEMBERSHIP, price=15.0)
        order = Order(customer, Address('46100'))
        order.add_product(item, 2)

        order_service.pay(order, payment_method=credit_card)

        assert order.is_paid
        assert order.customer == customer
        assert order.items[0].product == item
        assert order.payment.amount == 30.0
        assert expected_mail in EmailClient.queue
        assert 'Netflix' in Subscriptions.by_customer(customer)
 def test_dirs_exist(self):
     subs = Subscriptions(FakeDownloader(), self.standardpath )
     asub = subs.find("genes")
     self.assertTrue(os.path.exists(asub.subscriptions._podcasts_basedir()))
Exemple #11
0
from books import Books
from users import Users
from subscriptions import Subscriptions

# Flask application
application = Flask(__name__)
application.debug = True

# Initialise the books data (from books.json)
books = Books()

# Initialise the list of users
users = Users()

# Initialise the list of subscriptions
subscriptions = Subscriptions()


# Route for api 'request' GET
@application.route("/request", methods=["GET"])
def request_get():
    id = request.args.get("id")

    if id is not None:
        id = int(id)
        user = users.find_by_id(id)
        if not user:
            abort(404, "user id '%d' not found" % (id))

        subs = subscriptions.find_by_user(id)
          logging.info('CronPullFromTopicHandler invoked pull from subscription %s' % subscription)

          #find the subscription details for this subscription in the DS
          subsDS = get_subscription_dsentry_matched_to_subscription(subscription)
          
          exclude_filters = ''
          if subsDS !=None:
            #get any exclude filters
            exclude_filters = subsDS.exclude_filters.encode('utf8').split(",")
            #get destination topic
            destination_topic = buildDestinationTopic(subsDS.destination_project, subsDS.destination_topic)
            #process messages for this subscription
            subscription_pull_messages(subscription, exclude_filters, destination_topic)  
          else:
            logging.info('Could not find entry in DS matching subscription %s' % subscription)
      

Subscriptions.init()

check_and_create_subscriptions()

logging.getLogger().setLevel(logging.DEBUG)

app = webapp2.WSGIApplication([
    ('/cron_pullfromtopic', CronPullFromTopicHandler),
    ('/.*', PubSubHandler)    
    
], debug=True)


Exemple #13
0
class Application(object):
    def __init__(self, 
                name="",
                client_id=None,
                client_secret=None,
                scopes=OAUTH_SCOPES,
                debug=True,
                template_folder='templates',
                **flaskargs):
        self.name = name
        self.debug = debug
        self.web = flask.Flask(self.name, **flaskargs)
        self.template_folder = template_folder
        self.logger = self.web.logger
        self.scopes = scopes
        self.subscriptions = Subscriptions(app=self)
        self.oauth = rauth.OAuth2Service(name=self.name,
                                  client_id=client_id,
                                  client_secret=client_secret,
                                  access_token_url=OAUTH_ACCESS_TOKEN_URL,
                                  authorize_url=OAUTH_AUTHORIZE_URL,
                                  base_url=OAUTH_API_BASE_URL)

    @property
    def oauth_redirect_uri(self):
        return "%s://%s/glass/oauth/callback" % ("https" if self.secure else "http", self.host)

    def _oauth_authorize(self):
        """
        (view) Display the authorization window for Google Glass
        """
        params = {
            'approval_prompt': 'force',
            'scope': " ".join(self.scopes),
            'state': '/profile',
            'redirect_uri': self.oauth_redirect_uri,
            'response_type': 'code'
        }
        url = self.oauth.get_authorize_url(**params)
        return flask.redirect(url)

    def _oauth_callback(self):
        """
        (view) Callback for the oauth
        """
        token = self.oauth.get_access_token(data={
            'code': flask.request.args.get('code', ''),
            'redirect_uri': self.oauth_redirect_uri,
            'grant_type': 'authorization_code'
        }, decoder=json.loads)
        user = User(token=token, app=self)

        # Add subscriptions
        self.subscriptions.init_user(user)

        # Call endpoint for user login
        return self.subscriptions.call_endpoint("login", user) or ""

    def prepare(self, host="localhost", port=8080, debug=None, secure=False, public=False):
        """
        Prepare the application server
        """
        self.port = port
        self.host = host
        self.secure = secure
        self.public = public

        if port != 80:
            self.host = "%s:%i" % (self.host, self.port)

        # OAUTH
        self.web.add_url_rule('/glass/oauth/authorize', 'oauth_authorize', self._oauth_authorize)
        self.web.add_url_rule('/glass/oauth/callback', 'oauth_callback', self._oauth_callback)

        self.web.debug = debug or self.debug

        # SSL
        self.ssl_context = None
        if self.secure:
            from OpenSSL import SSL
            self.ssl_context = SSL.Context(SSL.TLSv1_METHOD)
            dir = os.path.dirname(sys.argv[0])
            if dir == '':
                dir = os.curdir
            self.ssl_context.use_privatekey_file(os.path.join(dir, SSL_KEY_FILE))
            self.ssl_context.use_certificate_file(os.path.join(dir, SSL_CRT_FILE))

    def run(self, **kwargs):
        self.prepare(**kwargs)
        self.web.run(port=self.port, host=("0.0.0.0" if self.public else "127.0.0.1"),
            ssl_context = self.ssl_context)
Exemple #14
0
class Application(object):
    def __init__(self,
                 name="",
                 client_id=None,
                 client_secret=None,
                 scopes=OAUTH_SCOPES,
                 debug=True,
                 template_folder='templates',
                 **flaskargs):
        self.name = name
        self.debug = debug
        self.web = flask.Flask(self.name, **flaskargs)
        self.template_folder = template_folder
        self.logger = self.web.logger
        self.scopes = scopes
        self.subscriptions = Subscriptions(app=self)
        self.oauth = rauth.OAuth2Service(
            name=self.name,
            client_id=client_id,
            client_secret=client_secret,
            access_token_url=OAUTH_ACCESS_TOKEN_URL,
            authorize_url=OAUTH_AUTHORIZE_URL,
            base_url=OAUTH_API_BASE_URL)

    @property
    def oauth_redirect_uri(self):
        return "%s://%s/glass/oauth/callback" % ("https" if self.secure else
                                                 "http", self.host)

    def _oauth_authorize(self):
        """
        (view) Display the authorization window for Google Glass
        """
        params = {
            'scope': " ".join(self.scopes),
            'state': '/profile',
            'redirect_uri': self.oauth_redirect_uri,
            'response_type': 'code',
            'access_type': 'offline',
            'approval_prompt': 'force'
        }
        url = self.oauth.get_authorize_url(**params)
        return flask.redirect(url)

    def _oauth_callback(self):
        """
        (view) Callback for the oauth
        """
        tokens = self.oauth.get_raw_access_token(
            data={
                'code': flask.request.args.get('code', ''),
                'redirect_uri': self.oauth_redirect_uri,
                'grant_type': 'authorization_code'
            }).json()
        user = User(tokens=tokens, app=self)

        # Add subscriptions
        self.subscriptions.init_user(user)

        # Call endpoint for user login
        return self.subscriptions.call_endpoint("login", user) or ""

    def prepare(self,
                host="localhost",
                port=8080,
                debug=None,
                secure=False,
                public=False):
        """
        Prepare the application server
        """
        self.port = port
        self.host = host
        self.secure = secure
        self.public = public

        if port != 80:
            self.host = "%s:%i" % (self.host, self.port)

        # OAUTH
        self.web.add_url_rule('/glass/oauth/authorize', 'oauth_authorize',
                              self._oauth_authorize)
        self.web.add_url_rule('/glass/oauth/callback', 'oauth_callback',
                              self._oauth_callback)

        self.web.debug = debug or self.debug

    def run(self, **kwargs):
        self.prepare(**kwargs)
        self.web.run(port=self.port,
                     host=("0.0.0.0" if self.public else "127.0.0.1"))
Exemple #15
0
 def __init__(self, id):
     """ """
     self.id = id
     self.subscriptions = Subscriptions('subscriptions')
Exemple #16
0
 def tearDown(self):
     LabelPrinter.reset()
     EmailClient.reset()
     Subscriptions.reset()
 def test_dirs_dont_exist(self):
     with self.assertRaises(AttributeError):
         subs = Subscriptions(self.standardpath)
         asub = subs.find("xgenes")
         self.assertTrue(os.path.exists(asub.subscriptions._podcasts_basedir()))
Exemple #18
0
 def tearDown(self):
     LabelPrinter.reset()
     EmailClient.reset()
     Subscriptions.reset()
     DiscountCodes.reset()
     patch.stopall()
Exemple #19
0
class Application(object):
    OAUTH_ACCESS_TOKEN_URL = "https://accounts.google.com/o/oauth2/token"
    OAUTH_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth"
    OAUTH_REDIRECT_URI = "authentification/google"
    OAUTH_API_BASE_URL = "https://www.googleapis.com/"
    OAUTH_SCOPES = [
        'https://www.googleapis.com/auth/glass.location',
        'https://www.googleapis.com/auth/glass.timeline',
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email'
    ]

    def __init__(self, 
                name="",
                client_id=None,
                client_secret=None,
                emulator=False,
                debug=True,
                template_folder='templates'):
        self.name = name
        self.emulator = emulator
        self.debug = debug
        self.web = flask.Flask(self.name,
            static_folder=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'emulator'),
            static_url_path='/emulator')
        self.template_folder = template_folder
        self.logger = self.web.logger
        self.emulator_service = Emulator(app=self)
        self.subscriptions = Subscriptions(app=self)
        self.oauth = rauth.OAuth2Service(name=self.name,
                                  client_id=client_id,
                                  client_secret=client_secret,
                                  access_token_url=self.OAUTH_ACCESS_TOKEN_URL,
                                  authorize_url=self.OAUTH_AUTHORIZE_URL,
                                  base_url=self.OAUTH_API_BASE_URL)

    @property
    def oauth_redirect_uri(self):
        return "%s/glass/oauth/callback" % (self.host)

    def _oauth_authorize(self):
        """
        (view) Display the authorization window for Google Glass
        """
        params = {
            'approval_prompt': 'force',
            'scope': " ".join(self.OAUTH_SCOPES),
            'state': '/profile',
            'redirect_uri': self.oauth_redirect_uri,
            'response_type': 'code'
        }
        url = self.oauth.get_authorize_url(**params)
        return flask.redirect(url)

    def _oauth_callback(self):
        """
        (view) Callback for the oauth
        """
        token = self.oauth.get_access_token(data={
            'code': flask.request.args.get('code', ''),
            'redirect_uri': self.oauth_redirect_uri,
            'grant_type': 'authorization_code'
        }, decoder=json.loads)
        user = User(token=token, app=self)

        # Add subscriptions
        self.subscriptions.init_user(user)

        # Call endpoint for user login
        self.subscriptions.call_endpoint("login", user)

        return token

    def run(self, host="http://localhost", port=8080, debug=None):
        """
        Start the application server
        """
        if self.emulator:
            self.emulator_service.run()

        self.port = port
        self.host = host
        if port != 80:
            self.host = "%s:%i" % (self.host, self.port)

        # OAUTH
        self.web.add_url_rule('/glass/oauth/authorize', 'oauth_authorize', self._oauth_authorize)
        self.web.add_url_rule('/glass/oauth/callback', 'oauth_callback', self._oauth_callback)

        self.web.debug = debug or self.debug

        # Run webserver
        self.web.run(port=self.port)
Exemple #20
0
class Application(object):
    OAUTH_ACCESS_TOKEN_URL = "https://accounts.google.com/o/oauth2/token"
    OAUTH_AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth"
    OAUTH_REDIRECT_URI = "authentification/google"
    OAUTH_API_BASE_URL = "https://www.googleapis.com/"
    OAUTH_SCOPES = [
        'https://www.googleapis.com/auth/glass.location',
        'https://www.googleapis.com/auth/glass.timeline',
        'https://www.googleapis.com/auth/userinfo.profile',
        'https://www.googleapis.com/auth/userinfo.email'
    ]

    def __init__(self,
                 name="",
                 client_id=None,
                 client_secret=None,
                 emulator=False,
                 debug=True,
                 template_folder='templates'):
        self.name = name
        self.emulator = emulator
        self.debug = debug
        self.web = flask.Flask(self.name,
                               static_folder=os.path.join(
                                   os.path.dirname(os.path.abspath(__file__)),
                                   'emulator'),
                               static_url_path='/emulator')
        self.template_folder = template_folder
        self.logger = self.web.logger
        self.emulator_service = Emulator(app=self)
        self.subscriptions = Subscriptions(app=self)
        self.oauth = rauth.OAuth2Service(
            name=self.name,
            client_id=client_id,
            client_secret=client_secret,
            access_token_url=self.OAUTH_ACCESS_TOKEN_URL,
            authorize_url=self.OAUTH_AUTHORIZE_URL,
            base_url=self.OAUTH_API_BASE_URL)

    @property
    def oauth_redirect_uri(self):
        return "%s/glass/oauth/callback" % (self.host)

    def _oauth_authorize(self):
        """
        (view) Display the authorization window for Google Glass
        """
        params = {
            'approval_prompt': 'force',
            'scope': " ".join(self.OAUTH_SCOPES),
            'state': '/profile',
            'redirect_uri': self.oauth_redirect_uri,
            'response_type': 'code'
        }
        url = self.oauth.get_authorize_url(**params)
        return flask.redirect(url)

    def _oauth_callback(self):
        """
        (view) Callback for the oauth
        """
        token = self.oauth.get_access_token(data={
            'code':
            flask.request.args.get('code', ''),
            'redirect_uri':
            self.oauth_redirect_uri,
            'grant_type':
            'authorization_code'
        },
                                            decoder=json.loads)
        user = User(token=token, app=self)

        # Add subscriptions
        self.subscriptions.init_user(user)

        # Call endpoint for user login
        self.subscriptions.call_endpoint("login", user)

        return token

    def run(self, host="http://localhost", port=8080, debug=None):
        """
        Start the application server
        """
        if self.emulator:
            self.emulator_service.run()

        self.port = port
        self.host = host
        if port != 80:
            self.host = "%s:%i" % (self.host, self.port)

        # OAUTH
        self.web.add_url_rule('/glass/oauth/authorize', 'oauth_authorize',
                              self._oauth_authorize)
        self.web.add_url_rule('/glass/oauth/callback', 'oauth_callback',
                              self._oauth_callback)

        self.web.debug = debug or self.debug

        # Run webserver
        self.web.run(port=self.port)