Exemple #1
0
    def setUp(self):
        _settings = dict(
            TESTING=True,
            LOGIN_DISABLED=False,
            MAIL_SUPPRESS_SEND=True,
            SERVER_NAME='localhost',
            SQLALCHEMY_DATABASE_URI='sqlite:///:memory:',
            WTF_CSRF_ENABLED=False,
        )

        init_app(app, db, _settings)
        app.app_context().push()
        self.app = app
Exemple #2
0
    def setUp(self):
        _settings = dict(
            TESTING=True,               
            LOGIN_DISABLED=False,       
            MAIL_SUPPRESS_SEND=True,    
            SERVER_NAME='localhost',    
            SQLALCHEMY_DATABASE_URI='sqlite:///:memory:', 
            WTF_CSRF_ENABLED=False,    
            )

        init_app(app, db, _settings)
        app.app_context().push()
        self.app = app
 def test_get_watch_history_not_end(self):
     app = Flask(__name__)
     with app.app_context():
         res = utils.db.get_watch_history("101034240973870390330")
         # print(res[0])
         self.assertEqual("streamer id: test1, from 2020-12-04",
                          res[0][:35])
 def test_get_analytics_category_all_miss(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         conn.execute("DELETE from watch_history")
         res = utils.db.get_analytics_category_all()
         self.assertEqual(None, res)
 def test_get_streaming_empty(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         conn.execute("DELETE from streaming")
         res = utils.db.get_streaming()
         self.assertEqual(None, res)
 def test_get_db_miss(self):
     os.system("rm utils/sqlite_db")
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         os.system("git restore utils/sqlite_db")
         self.assertTrue(conn)
 def test_get_advertise_streamer_none(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         conn.execute("DELETE from advertise")
         res = utils.db.get_advertise()
         self.assertEqual([], res)
Exemple #8
0
 def setUp(self):
     print("inside setUp the Test")
     self.ctx = app.app_context()
     self.ctx.push()
     db.drop_all()  # just in case
     db.create_all()
     self.client = app.test_client()
Exemple #9
0
def test_numeric_field_save():
    from app import app
    with app.app_context():
        # need the app_context because some of these raise errors
        tester = make_table()
        rec = tester.new()
        assert isinstance(rec,dbm.DataRow)
        
        form = {'name':"test name",'int_field':"0",'real_field':"this is not a number",'float_field':"100",'number_field':"30"}
        rec.update(form,True)
        assert rec.name == "test name"
        assert rec.int_field == 0
        assert rec.real_field == "this is not a number"
        assert rec.float_field == 100.0
        assert rec.number_field == 30.0
        form = {'name':"test name",'int_field':100.345,'real_field':30.2,'float_field':100.34,'number_field':700.2}
        rec.update(form,True)
        assert rec.name == "test name"
        assert rec.int_field == 100
        assert rec.real_field == 30.2
        assert rec.float_field == 100.34
        assert rec.number_field == 700.2
        form = {'name':"test name",'int_field':None,'real_field':None,'float_field':None,'number_field':None}
        rec.update(form,True)
        assert rec.name == "test name"
        assert rec.int_field == None
        assert rec.real_field == None
        assert rec.float_field == None
        assert rec.number_field == None
    
        db.rollback()
        db.execute('DROP TABLE {}'.format(tester.table_name))
        with pytest.raises(sqlite3.OperationalError):
            assert tester.select()
            
            
    def test_add_extra_column():
        tester = make_table()
        rec = tester.new()
        form = {'name':"test name",'int_field':"0",'real_field':"this is not a number",'float_field':"100",'number_field':"30"}
        rec.update(form,True)
        assert rec.name == "test name"
        assert rec.int_field == 0
        assert rec.real_field == "this is not a number"
        assert rec.float_field == 100.0
        assert rec.number_field == 30.0
        
        tester.create_with_add()
        rec = tester.select_one()
        assert rec != None
        assert rec.name == "test name"
        assert rec.int_field == 0
        assert rec.real_field == "this is not a number"
        assert rec.float_field == 100.0
        assert rec.number_field == 30.0
        
        assert rec.added_to_db == None
        
        # run again to be sure it's not added again
        tester.create_with_add() #added the column twice will raise OperationalError
 def test_insert_watch_history_streamer_miss(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         utils.db.insert_watch_history("unit_test001", None, "Life")
         res = conn.execute("SELECT * FROM streaming").fetchall()
         self.assertEqual("test3", res[-1]['id'])
Exemple #11
0
def setup_db():
    with app.app_context():
    # print app
        db.drop_all()
        db.create_all()
        db.session.commit()
    print "database is set up!"
 def test_insert_advertise(self):
     app = Flask(__name__)
     with app.app_context():
         utils.db.insert_advertise("Sony", "Gaming",
                                   "2099-11-11 11:11:11.111", "cool.png")
         conn = utils.db.get_db()
         res = conn.execute("SELECT * FROM advertise").fetchall()
         self.assertEqual("Sony", res[-1]['streamer'])
 def test_update_current_watching_decrease_miss(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         conn.execute("DELETE from streaming where `id` = 'unit_test999'")
         res = utils.db.update_current_watching("unit_test999", False)
         # print(res[-1].keys())
         self.assertEqual(None, res)
 def test_get_streaming_m3u8(self):
     app = Flask(__name__)
     with app.app_context():
         utils.db.create_stream("unit_test001", "unit_test1", "Life")
         utils.db.update_stream("unit_test001", "https://www.HIHI.m3u8")
         res = utils.db.get_streaming_m3u8("unit_test001")
         # print(res[-1].keys())
         self.assertTrue(res)
 def test_get_current_watching(self):
     app = Flask(__name__)
     with app.app_context():
         utils.db.create_stream("unit_test001", "unit_test1", "Life")
         utils.db.update_stream("unit_test001", "https://www.HIHI.m3u8")
         utils.db.update_current_watching("unit_test001")
         res = utils.db.get_current_watching("unit_test001")
         self.assertEqual(1, res)
 def test_insert_watch_history(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         utils.db.insert_watch_history("KIKI", "test1", "KIKI777")
         res = conn.execute("SELECT * FROM streaming").fetchall()
         # print(res[-1].keys())
         self.assertEqual("test3", res[-1]['id'])
 def test_get_streaming_m3u8_miss(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         conn.execute("DELETE from streaming where `id` = 'unit_test999'")
         res = utils.db.get_streaming_m3u8("unit_test999")
         # print(res[-1].keys())
         self.assertEqual(None, res)
 def test_get_analytics_user(self):
     app = Flask(__name__)
     with app.app_context():
         res = utils.db.get_analytics_user("test1")
         print(res[0], res[1])
         self.assertEqual('2020-11-20', res[0][0]['date'])
         # self.assertEqual(2, res[0][0]['value'])
         self.assertEqual('test1', res[1][0])
 def test_insert_advertise_miss(self):
     app = Flask(__name__)
     with app.app_context():
         utils.db.insert_advertise(None, "Gaming",
                                   "2099-11-11 11:11:11.111", "cool.png")
         conn = utils.db.get_db()
         res = conn.execute(
             "SELECT * FROM advertise where image = 'cool.png'").fetchall()
         self.assertEqual([], res)
 def test_get_advertise_over_time_miss(self):
     app = Flask(__name__)
     with app.app_context():
         utils.db.insert_advertise("Sony", "Gaming",
                                   "2011-11-11 11:11:11.111", "cool.png")
         #utils.db.create_stream("Sony", "Sony", "Gaming")
         res = utils.db.get_advertise("Sony")
         # print(res)
         self.assertEqual([], res)
Exemple #21
0
def init_handler(event, context):
    from sls-flask-app.app import app

    if not app.config.get("DEV_DB_SCRIPTS_ENABLED"):
        raise Exception("DEV_DB_SCRIPTS_ENABLED is not enabled")
    with app.app_context():
        drop_all_tables(app=app)
        db.create_all(app=app)
    return "DB initialized."
Exemple #22
0
    def test_get_all(self):
        """
        Testing GET request to ensure API payload and db data are a match.
        """
        with app.app_context():
            test_response = jsonify(User.objects.all()).json
            payload = routes.UserAll.get(self.userAll).json

            self.assertEqual(test_response, payload)
 def test_get_audience_comment_miss(self):
     app = Flask(__name__)
     with app.app_context():
         utils.db.insert_audience_comment("Jason", "Alice", "Hello, World!")
         utils.db.get_audience_comment("Jason")
         conn = utils.db.get_db()
         res = conn.execute(
             "SELECT * FROM audience_comment where streamer = 'Jason'"
         ).fetchall()
         self.assertEqual([], res)
Exemple #24
0
def test_template(app, events):
    with app.app_context():
        flask.render_template('test.html')
    assert events[0].to_dict() == DictIncluding({
        'path': 'appmap/test/data/flask/templates/test.html',
        'event': 'call',
        'defined_class': '<templates>.AppmapTestDataFlaskTemplatesTestHtml',
        'method_id': 'render',
        'static': False
    })
 def test_create_stream(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         utils.db.create_stream("unit_test001", "unit_test1", "Life")
         res = conn.execute("SELECT * FROM streaming").fetchall()
         # print(res[-1].keys())
         self.assertEqual("unit_test001", res[-1]['id'])
         self.assertEqual("unit_test1", res[-1]['name'])
         self.assertEqual("Life", res[-1]['category'])
 def test_create_stream_miss(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         utils.db.create_stream("unit_test001", None, "Life")
         res = conn.execute(
             "SELECT * FROM streaming where `id` = 'unit_test001'"
         ).fetchall()
         # print(res[-1].keys())
         self.assertEqual([], res)
 def test_update_watch_history_miss(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         utils.db.update_watch_history("UUID999")
         res = conn.execute(
             "SELECT * FROM watch_history where UUID = 'UUIC999'").fetchall(
             )
         # print(res[-1].keys())
         self.assertEqual([], res)
 def test_update_stream(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         utils.db.create_stream("unit_test001", "unit_test1", "Life")
         utils.db.update_stream("unit_test001", "https://www.HIHI.m3u8")
         res = conn.execute("SELECT * FROM streaming").fetchall()
         # print(res[-1].keys())
         self.assertEqual("unit_test001", res[-1]['id'])
         self.assertEqual("https://www.HIHI.m3u8", res[-1]['m3u8_URL'])
 def test_update_current_watching_decrease(self):
     app = Flask(__name__)
     with app.app_context():
         utils.db.create_stream("unit_test001", "unit_test1", "Life")
         utils.db.update_stream("unit_test001", "https://www.HIHI.m3u8")
         utils.db.update_current_watching("unit_test001", False)
         conn = utils.db.get_db()
         res = conn.execute("SELECT * FROM streaming").fetchall()
         # print(res[-1].keys())
         self.assertEqual(-1, res[-1]['current_watching'])
 def test_update_stream_miss(self):
     app = Flask(__name__)
     with app.app_context():
         conn = utils.db.get_db()
         utils.db.update_stream("unit_test999", "https://www.HIHI.m3u8")
         res = conn.execute(
             "SELECT * FROM streaming where `id` = 'unit_test999'"
         ).fetchall()
         # print(res[-1].keys())
         self.assertEqual([], res)
Exemple #31
0
def app():
    from {{ cookiecutter.project_slug }}.app import app as _app, db

    with _app.app_context():
        db.create_all()

    yield  _app

    db.session.remove()
    db.drop_all()
Exemple #32
0
    def test_get_all_fail(self):
        """
        Testing API payload against new user which has been created after response. Which should not be equal.
        """
        with app.app_context():
            payload = routes.UserAll.get(self.userAll).json
            User(email='*****@*****.**',
                 password=bcrypt.generate_password_hash('ireland')).save()
            test_response = jsonify(User.objects.all()).json

            self.assertNotEqual(payload, test_response)
Exemple #33
0
 def run(self, username):
     while True:
         password = getpass.getpass(prompt="Enter Password: "******"Confirm Password: "******"Passwords did not match. Please try again.")
     create_db()
     api_profile = models.APIProfile(username=username)
     api_profile.set_password(password)
     with app.app_context():
         flask.g.db.session.add(api_profile)
         flask.g.db.session.commit()
     print("An API Profile was succesfully created for username, %s." %
           username)
def process_image(filename, type, data, user_id):
    app = create_app(os.getenv('FLASK_CONFIG') or 'default')
    with app.app_context():
        source_filename = secure_filename(filename)
        source_extension = os.path.splitext(source_filename)[1]

        destination_filename = uuid4().hex + source_extension
        conn = boto.connect_s3(os.environ["AWS_ACCESS_KEY_ID"], os.environ["AWS_SECRET_ACCESS_KEY"])
        b = conn.get_bucket(os.environ["S3_BUCKET"])
        sml = b.new_key("/".join([destination_filename]))
        sml.set_contents_from_string(data)
        sml.set_acl('public-read')
        
        user = User.query.filter_by(id=user_id).first()
        if type == 'image': 
            user.image = 'https://s3-us-west-2.amazonaws.com/{}/{}'.format(os.environ["S3_BUCKET"], destination_filename)
        if type == 'pdf':
            user.pdf = 'https://s3-us-west-2.amazonaws.com/{}/{}'.format(os.environ["S3_BUCKET"], destination_filename)
        db.session.commit()
Exemple #35
0
    callSendAPI(messageData)


def callSendAPI(messageData):
    print "messageData", messageData
    r = requests.post(
        "https://graph.facebook.com/v2.6/me/messages/?access_token=" +
        PAGE_ACCESS_TOKEN,
        json=messageData
    )
    print r.json()
    if r.status_code == 200:
        print "Successfully sent message."
    else:
        print "Unable to send message."

@manager.command
def setup_db():
    with app.app_context():
    # print app
        db.drop_all()
        db.create_all()
        db.session.commit()
    print "database is set up!"


if __name__ == "__main__":
    with app.app_context():
        db.create_all()
    manager.run()
Exemple #36
0
def create_db():
    with app.app_context():
        flask.g.db.drop_all()
        flask.g.db.create_all()