예제 #1
0
        self.assertEqual(1, User.query.join(UserSPAccess).count())

    def tearDown(self):
        info("Drop tables.")

        # Otherwise hangs at drop_all.
        # More info: http://stackoverflow.com/questions/24289808/
        db.session.commit()

        db.drop_all()
        info("Tables dropped.")

if __name__ == '__main__':
    uri = os.getenv('SQLALCHEMY_TESTING_DATABASE_URI')
    print('=' * 80)
    print('  WARNING: You may be about to drop your production database!')
    print('  Database URI in use for testing: {}'.format(uri))
    print('=' * 80)
    try:
        input('Press ^C to cancel, or <Enter> to continue')
    except KeyboardInterrupt:
        os.exit()

    app = create_app()
    app.config['SQLALCHEMY_DATABASE_URI'] = uri

    sp = MockServiceProvider(None)

    with app.app_context():
        unittest.main()
예제 #2
0
import dateutil
from flask import Flask, render_template, request, Response, flash, redirect, url_for, jsonify
from flask_moment import Moment
from flask_sqlalchemy import SQLAlchemy
import logging
from urllib.parse import urlencode
from logging import Formatter, FileHandler
from flask_wtf import Form
from forms import *
from flask_migrate import Migrate
from models import create_app, Artist, Venue, Show
from sqlalchemy.exc import SQLAlchemyError
#----------------------------------------------------------------------------#
# App Config.
app = Flask(__name__)
db = create_app(app)

#----------------------------------------------------------------------------#
# Filters.
#----------------------------------------------------------------------------#


def format_datetime(value, format='medium'):
    date = dateutil.parser.parse(value)
    if format == 'full':
        format = "EEEE MMMM, d, y 'at' h:mma"
    elif format == 'medium':
        format = "EE MM, dd, y h:mma"
    return babel.dates.format_datetime(date, format)

예제 #3
0
import pandas as pd
from flask_sqlalchemy import SQLAlchemy
from models import Event, Location, Category, TypeEvent, create_app, db
from datetime import datetime

app = create_app()
app.config.from_object('config')
app.app_context().push()

# engine = db.create_engine('sqlite:///test.db', engine_opts={})
db.create_all()

events = pd.read_csv('https://stepik.org/media/attachments/course/61900/meetup_events.csv')
events = events.dropna()
locations = pd.read_csv('https://stepik.org/media/attachments/course/61900/meetup_locations.csv')
locations = locations.dropna()
categories = pd.read_csv('https://stepik.org/media/attachments/course/61900/meetup_categories.csv')
types = pd.read_csv('https://stepik.org/media/attachments/course/61900/meetup_types.csv')

# locations.to_sql('locations', con=engine, index=False)
# categories.to_sql('categories', con=engine, index=False, if_exists='replace')
# types.to_sql('types', con=engine, index=True, index_label='id', if_exists='replace')

for row in locations.values.tolist():
    loc = Location(
        code=row[0],
        title=row[1]
    )
    db.session.add(loc)

for row in categories.values.tolist():
예제 #4
0
import logging
from logging import Formatter, FileHandler
from flask_wtf import Form
from forms import *
import config
from flask_migrate import Migrate
from models import create_app, Venue, Show, Artist, State, Genre
import sys
from datetime import datetime
# from seed_data import seed_states_data, seed_genres_data

#----------------------------------------------------------------------------#
# App Config.
#----------------------------------------------------------------------------#

app, db = create_app()
moment = Moment(app)
migrate = Migrate(app, db)

# TODO: connect to a local postgresql database

#----------------------------------------------------------------------------#
# Models.
#----------------------------------------------------------------------------#

# moved to models.py file

#----------------------------------------------------------------------------#
# Filters.
#----------------------------------------------------------------------------#