Example #1
0
"""
Created on 15 Oct 2015

@author: mbrandaoca
"""
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from gameevents_app import db, create_app
import os.path
import sys

app = create_app()
with app.app_context():
    db.create_all()

    # Add the admin user
    from gameevents_app.models.client import Client

    # Generate random password
    from random import choice
    import string

    chars = string.ascii_letters + string.digits
    length = 16
    randompass = "".join(choice(chars) for _ in range(length))

    admin = Client("administrator", randompass, "admin")
    db.session.add(admin)

    try:
Example #2
0
import sys, os
INTERP = os.path.join(os.environ['HOME'], '.virtualenvs', 'env', 'bin',
                      'python')
print(INTERP)
if sys.executable != INTERP:
    os.execl(INTERP, INTERP, *sys.argv)

current_dir = os.getcwd()
app_dir = os.path.join(current_dir, 'gameevents')
#sys.path.append(os.getcwd())
sys.path.append(app_dir)

from gameevents_app import create_app

application = create_app()

# Uncomment next two lines to enable debugging
#from werkzeug.debug import DebuggedApplication
#application = DebuggedApplication(application, evalex=True)

#from flask import Flask
#application = Flask(__name__)

#@application.route('/')
#def index():
#	return 'Hello passenger'
    def setUpClass(self):

        self.app = create_app(testing=True)
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()

        LOG.info("Initializing tests.")

        #Create a brand new test db
        db.create_all()

        #Add a clientid and apikey
        new_client = Client("myclientid", "myapikey", "normal")
        new_admin_client = Client("dashboard", "dashboardapikey", "admin")
        db.session.add(new_client)
        db.session.add(new_admin_client)
        try:
            db.session.commit()
            LOG.info("=== Added clients ===")
        except Exception as e:
            LOG.error(e, exc_info=True)

        #Generating gaming sessions ids
        self.newsessionid = UUID(bytes=OpenSSL.rand.bytes(16)).hex
        self.newsessionid2 = UUID(bytes=OpenSSL.rand.bytes(16)).hex
        self.newsessionid3 = UUID(
            bytes=OpenSSL.rand.bytes(16)).hex  #session not in db
        self.unauthorized_sessionid = "ac52bb1d811356ab3a8e8711c5f7ac5d"

        new_session = Session(self.newsessionid, new_client.id)
        new_session2 = Session(self.newsessionid2, new_client.id)
        db.session.add(new_session)
        db.session.add(new_session2)
        try:
            db.session.commit()
            LOG.info("=== Added sessions ===")
            LOG.info("=== Session not in db: %s ===" % self.newsessionid3)
        except Exception as e:
            LOG.error(e, exc_info=True)

        #Generating tokens
        self.mytoken = new_client.generate_auth_token(self.newsessionid)
        self.myexpiredtoken = new_client.generate_auth_token(self.newsessionid,
                                                             expiration=1)

        self.mytokennewsession = new_client.generate_auth_token(
            self.newsessionid3)

        self.myadmintoken = new_admin_client.generate_auth_token()
        self.myexpiredadmintoken = new_admin_client.generate_auth_token(
            expiration=1)

        self.mybadtoken = "badlogin" + self.mytoken.decode()[8:]
        self.mybadtoken = self.mybadtoken.encode("ascii")

        self.xml_valid_event = """<event><timestamp>2015-11-29T12:10:57Z</timestamp>
        <action>STARTGAME</action><level></level><update></update><which_lix>
        </which_lix><result></result></event>"""
        self.json_valid_event = """[{
                "timestamp": "2015-11-29T12:10:57Z",
                "action": "STARTGAME",
                "which_lix": ""
              }]"""
        self.xml_invalid_event = """<event>a
         <action>STARTGAME</action>
         <timestamp>2015-11-29T12:10:57Z</timestamp>
         <which_lix />
      </event>"""
        self.json_invalid_event = """
                "timestamp": "2015-11-29T12:10:57Z",
                "action": "STARTGAME",,
                "which_lix": ""
              """
        self.xml_multiple_events = """<event>
         <action>STARTGAME</action>
         <timestamp>2015-11-29T12:10:57Z</timestamp>
         <which_lix />
      </event>
      <event>
         <action>ENDGAME</action>
         <timestamp>2015-11-29T13:10:57Z</timestamp>
         <which_lix />
      </event>"""

        self.json_multiple_events = """[{ "timestamp": "2015-11-29T12:10:57Z",
                "action": "STARTGAME",
                "which_lix": ""
              }, {
                "timestamp": "2015-11-29T13:10:57Z",
                "action": "ENDGAME",
                "which_lix": ""
              }]"""

        time.sleep(3)  #expire the token

        new_gameevent = GameEvent(new_session.id, self.xml_valid_event)
        db.session.add(new_gameevent)
        try:
            db.session.commit()
            LOG.info("=== Added game event. All set up. ===")
        except Exception as e:
            LOG.error(e, exc_info=True)
Example #4
0
'''
Run the application
'''

# under normal circumstances, this script would not be necessary. the
# sample_application would have its own setup.py and be properly installed;
# however since it is not bundled in the sdist package, we need some hacks
# to make it work

import os
import sys

sys.path.append(os.path.dirname(__name__))

#from sample_application import create_app
from gameevents_app import create_app

# create an app instance
app = create_app()

app.run(debug=True, port=5000)
 def setUpClass(self):
     
     self.app = create_app(testing=True)
     self.app_context = self.app.app_context()
     self.app_context.push()
     self.client = self.app.test_client()
     
     LOG.info("Initializing tests.")
     
     #Create a brand new test db
     db.create_all()
     
     #Add a clientid and apikey
     new_client = Client("myclientid", "myapikey", "normal")
     new_admin_client = Client("dashboard", "dashboardapikey", "admin")  
     db.session.add(new_client)
     db.session.add(new_admin_client)
     try:
         db.session.commit()
         LOG.info("=== Added clients ===")
     except Exception as e:
         LOG.error(e, exc_info=True)      
     
     #Generating gaming sessions ids
     self.newsessionid = UUID(bytes = OpenSSL.rand.bytes(16)).hex
     self.newsessionid2 = UUID(bytes = OpenSSL.rand.bytes(16)).hex
     self.newsessionid3 = UUID(bytes = OpenSSL.rand.bytes(16)).hex #session not in db
     self.unauthorized_sessionid = "ac52bb1d811356ab3a8e8711c5f7ac5d"
     
     new_session = Session(self.newsessionid, new_client.id)
     new_session2 = Session(self.newsessionid2, new_client.id)
     db.session.add(new_session)
     db.session.add(new_session2)
     try:
         db.session.commit()
         LOG.info("=== Added sessions ===")
         LOG.info("=== Session not in db: %s ===" % self.newsessionid3)
     except Exception as e:
         LOG.error(e, exc_info=True)
     
     #Generating tokens        
     self.mytoken = new_client.generate_auth_token(self.newsessionid)
     self.myexpiredtoken = new_client.generate_auth_token(self.newsessionid, expiration=1)
     
     self.mytokennewsession = new_client.generate_auth_token(self.newsessionid3)
     
     self.myadmintoken = new_admin_client.generate_auth_token()
     self.myexpiredadmintoken = new_admin_client.generate_auth_token(expiration=1)
     
     self.mybadtoken = "badlogin" + self.mytoken.decode()[8:]
     self.mybadtoken = self.mybadtoken.encode("ascii")
     
     self.xml_valid_event = """<event><timestamp>2015-11-29T12:10:57Z</timestamp>
     <action>STARTGAME</action><level></level><update></update><which_lix>
     </which_lix><result></result></event>""";
     self.json_valid_event = """[{
             "timestamp": "2015-11-29T12:10:57Z",
             "action": "STARTGAME",
             "which_lix": ""
           }]"""
     self.xml_invalid_event = """<event>a
      <action>STARTGAME</action>
      <timestamp>2015-11-29T12:10:57Z</timestamp>
      <which_lix />
   </event>"""
     self.json_invalid_event = """
             "timestamp": "2015-11-29T12:10:57Z",
             "action": "STARTGAME",,
             "which_lix": ""
           """
     self.xml_multiple_events = """<event>
      <action>STARTGAME</action>
      <timestamp>2015-11-29T12:10:57Z</timestamp>
      <which_lix />
   </event>
   <event>
      <action>ENDGAME</action>
      <timestamp>2015-11-29T13:10:57Z</timestamp>
      <which_lix />
   </event>"""
     
     self.json_multiple_events = """[{ "timestamp": "2015-11-29T12:10:57Z",
             "action": "STARTGAME",
             "which_lix": ""
           }, {
             "timestamp": "2015-11-29T13:10:57Z",
             "action": "ENDGAME",
             "which_lix": ""
           }]"""
     
     time.sleep(3) #expire the token
  
     new_gameevent = GameEvent(new_session.id,self.xml_valid_event)
     db.session.add(new_gameevent)        
     try:
         db.session.commit()
         LOG.info("=== Added game event. All set up. ===")
     except Exception as e:
         LOG.error(e, exc_info=True)