示例#1
0
from unittest import TestCase

from app import app
from models import connect_db, Cupcake, db
from dbcred import get_database_uri

# Use test database and don't clutter tests with SQL
app.config['SQLALCHEMY_DATABASE_URI'] = get_database_uri("cupcake_test",
                                                         save=False)
app.config['SQLALCHEMY_ECHO'] = False

# Make Flask errors be real errors, rather than HTML pages with error info
app.config['TESTING'] = True

connect_db(app)
db.drop_all()
db.create_all()

CUPCAKE_DATA = {
    "flavor": "TestFlavor",
    "size": "TestSize",
    "rating": 5.0,
    "image": "http://test.com/cupcake.jpg"
}

CUPCAKE_DATA_2 = {
    "flavor": "TestFlavor2",
    "size": "TestSize2",
    "rating": 10.0,
    "image": "http://test.com/cupcake2.jpg"
}
示例#2
0
#!/usr/bin/env python

"""Tag model tests."""

from unittest import TestCase, main

from models import connect_db, db, Tag
from dbcred import get_database_uri

from app import app
app.config['SQLALCHEMY_DATABASE_URI'] = get_database_uri(
    "fictionsource-test",
    cred_file = ".dbtestcred",
    save = False
)
if app.config['SQLALCHEMY_DATABASE_URI'] is None:
    app.config['SQLALCHEMY_DATABASE_URI'] = get_database_uri(
        "fictionsource-test",
        cred_file = None,
        save = False
    )

app.config['SQLALCHEMY_ECHO'] = False

# == TEST CASE =================================================================================== #

class TagModelTestCase(TestCase):
    """Test cases for Tag ORM."""

    @classmethod
    def setUpClass(cls) -> None:
示例#3
0
import sys

# Flask stuff
from flask import Flask, jsonify, redirect, render_template, request
from flask_accept import accept
from flask_debugtoolbar import DebugToolbarExtension
from flaskkey import get_key

# Database stuff
from models import *
from dbcred import get_database_uri

# == FLASK SET-UP ==================================================================================

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = get_database_uri()
if app.config['SQLALCHEMY_DATABASE_URI'] is None:
    app.config['SQLALCHEMY_DATABASE_URI'] = get_database_uri("blogly",
                                                             cred_file=None,
                                                             save=False)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_ECHO'] = True

app.config['SECRET_KEY'] = get_key()
app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False

# == PAGE ROUTES ===================================================================================


@app.route("/")
def homepage():