예제 #1
0
def add_entry(app, title, body):
    ''' Provide a single entry in the database. '''
    now = datetime.datetime.utcnow()
    expected = (title, body, now)
    with closing(connect_db(settings)) as db:
        world.run_query(db, INSERT_ENTRY, expected, False)
        db.commit()

    return expected
예제 #2
0
def teardown(total):
    with app.test_request_context('/'):
        con = get_database_connection()
        cur = con.cursor()
        cur.execute("DELETE FROM entries")
        # and here as well
        con.commit()
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()
예제 #3
0
def teardown(total):
    with app.test_request_context('/'):
        con = get_database_connection()
        cur = con.cursor()
        cur.execute("DELETE FROM entries")
        # and here as well
        con.commit()
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()
예제 #4
0
def req_context(db, request):
    """mock a request with a database attached"""
    settings = db
    req = testing.DummyRequest()
    with closing(connect_db(settings)) as db:
        req.db = db
        req.exception = None
        yield req

        clear_entries(settings)
예제 #5
0
def req_context(db, request):
    '''Mock a request with a database attached.'''
    settings = db
    req = testing.DummyRequest()
    with closing(connect_db(settings)) as db:
        req.db = db
        req.exception = None
        yield req

        # After the test has run, clear out the entries
        clear_entries(settings)
예제 #6
0
def content_gen(db, request):
    """Create a single entry to test."""
    settings = db
    input = ('some title', 'some text', datetime.datetime.utcnow())
    with closing(connect_db(settings)) as db:
        db.cursor().execute(INSERT_ENTRY, input)
        db.commit()

    def cleanup():
        clear_entries(settings)

    request.addfinalizer(cleanup)

    return input
예제 #7
0
def entry(db, request):
    """provide a single entry in the database"""
    settings = db
    now = datetime.datetime.utcnow()
    expected = ('Test Title', 'Test Text', now)
    with closing(connect_db(settings)) as db:
        run_query(db, INSERT_ENTRY, expected, False)
        db.commit()

    def cleanup():
        clear_entries(settings)

    request.addfinalizer(cleanup)

    return expected
예제 #8
0
def clear_db():

    # This ensures the connection is closed later.
    # Context library is all for this kind of context stuff.
    with contextlib.closing(connect_db()) as db:

        # Testing is not supposed to be used with a deployed database,
        # apparently. That's where TEST_DSN's specification comes in:
        # This will all be done in the test_learning_journal db.
        # ...
        # NOTE: This database must be created manually on the CLI.
        # Done with:
        # createdb test_learning_journal
        db.cursor().execute("DROP TABLE entries")
        db.commit()
예제 #9
0
def setup_db():
    """set up test database"""
    # set up test database
    settings = {'db': TEST_DSN}
    with closing(connect_db(settings)) as db:
        db.cursor().execute(DB_SCHEMA)
        db.commit()
    world.settings = settings

    # setup test app
    os.environ['DATABASE_URL'] = TEST_DSN
    app = main()
    world.app = TestApp(app)
    login_data = {'username': '******', 'password': '******'}
    world.app.post('/login', params=login_data)

    # add initial entry
    world.make_entry('Test Title', 'Test Text')
예제 #10
0
def clear_db():
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()
예제 #11
0
def clear_db(results):
    with closing(connect_db()) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()
예제 #12
0
def clear_entries(settings):
    with closing(connect_db(settings)) as db:
        db.cursor().execute("DELETE FROM entries")
        db.commit()
예제 #13
0
def init_db(settings):
    with closing(connect_db(settings)) as db:
        db.cursor().execute(DB_SCHEMA)
        db.commit()
예제 #14
0
def clear_db(scenario):
    ''' Clear the test database. '''
    with closing(connect_db(settings)) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()
예제 #15
0
def init_db(scenario):
    '''Initialize a test database for the tests.'''
    with closing(connect_db(settings)) as db:
        db.cursor().execute(world.DB_SCHEMA)
        db.commit()
예제 #16
0
def teardown_db(total):
    """tear down a database"""
    with closing(connect_db(world.settings)) as db:
        db.cursor().execute("DROP TABLE entries")
        db.commit()