Beispiel #1
0
def main():
    """This is the main program."""
    from optparse import OptionParser

    # TODO I might move this to config but there is problem of mentor and probe
    # being different apps !
    parser = OptionParser(version='Mentor Probe version ' + __version__)
    parser.add_option("-d", "--debug", action="store_true", dest="debug", default=config.DEBUG,
                      help="run program in debugged mode" )
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=config.VERBOSE,
                      help="print output verbosely")
    parser.add_option("-p", "--pretend", action="store_true", dest="pretend", default=False,
                      help="run a a simulation only")
    parser.add_option("-t", "--test", action="store_true", dest="test", default=False,
                      help="runs a series of tests")

    opts, args = parser.parse_args(sys.argv[1:])
    # apply to config
    config.TEST    =  opts.test
    config.VERBOSE =  opts.verbose
    config.PRETEND =  opts.pretend
    config.DEBUG   =  opts.debug


    if config.TEST:
        # import path from tests
        # sys.path.append(os.path.join(os.path.dirname(os.path.dirname(__file__)), "tests"))
        from tests import test_utils, test_probe, test_cards, test_models
        import unittest
        # do I need it?
        suite = unittest.TestSuite([test_utils.suite(),
                                    test_probe.suite(),
                                    test_cards.suite(),
                                    test_models.suite()])
        runner = unittest.TextTestRunner(verbosity=2)
        runner.run(suite)
        sys.exit()


    if config.DEBUG:
        enable_logging(True)
    else:
        enable_logging(False)


    if len(args) == 0:
        print "No input file specified. "
        sys.exit()
 


    processor = Processor()

    for input in args:
        processor.process(input)
    __tablename__ = 'blogs'

    id = sa.Column(sa.Integer, primary_key=True)

    # lazy = True / 'joined' are the same
    comments = sa.orm.relationship(lambda: Comment,
                                   lazy='dynamic',
                                   backref='blog')


class Comment(Base, MethodsMixin):
    __tablename__ = 'comments'

    id = sa.Column(sa.Integer, primary_key=True)
    blog_id = sa.Column(sa.ForeignKey(Blog.id, ondelete='cascade'),
                        nullable=False)


init_entities(Blog, Comment)
enable_logging()

sess = Session()

profiler = sqltap.ProfilingSession()
with profiler:
    for b in sess.query(Blog):
        assert b.comments.order_by('id').all()

query_stats = profiler.collect()
assert len(query_stats) == 3
Beispiel #3
0
#!/usr/bin/env python

import utils
import api
from faker import Faker

utils.enable_logging()
fake = Faker()

def user_exists(user):
    try:
        api.login(user['login'], user['password'])
    except:
        return False
    return True

def ensure_user(user):
    if not user_exists(user):
        api.post('/api/data/user', user)

users = [
    {
        'login': '******',
        'name': 'admin',
        'email': '*****@*****.**',
        'password': '******',
    },
    {
        'login': '******',
        'name': 'sergeyt',
        'email': '*****@*****.**',