def setUp(self): from tutorial import main app = main({}) from webtest import TestApp self.testapp = TestApp(app)
def setUpClass(cls): from tutorial.models.meta import Base from tutorial.models import ( User, Page, get_tm_session, ) from tutorial import main settings = { 'sqlalchemy.url': 'sqlite://', 'auth.secret': 'seekrit', } app = main({}, **settings) cls.testapp = TestApp(app) session_factory = app.registry['dbsession_factory'] cls.engine = session_factory.kw['bind'] Base.metadata.create_all(bind=cls.engine) with transaction.manager: dbsession = get_tm_session(session_factory, transaction.manager) editor = User(name='editor', role='editor') editor.set_password('editor') basic = User(name='basic', role='basic') basic.set_password('basic') page1 = Page(name='FrontPage', data='This is the front page') page1.creator = editor page2 = Page(name='BackPage', data='This is the back page') page2.creator = basic dbsession.add_all([basic, editor, page1, page2])
def setUp(self): from tutorial import main settings = { 'sqlalchemy.url': 'sqlite://'} app = main({}, **settings) from webtest import TestApp self.testapp = TestApp(app) _initTestingDB()
def setUp(self): from tutorial import main settings = {} app = main(settings) from webtest import TestApp self.testapp = TestApp(app)
def setUp(self): from tutorial import main settings = {"sqlalchemy.url": "sqlite:///:memory:"} app = main({}, **settings) from webtest import TestApp self.testapp = TestApp(app)
def setUp(self): self.session = _initTestingDB() self.config = testing.setUp() from tutorial import main settings = {} app = main(settings) from webtest import TestApp self.testapp = TestApp(app)
def setUp(self): from tutorial import main settings = { 'pyramid.includes': [ 'pyramid_jinja2' ] } app = main({}, **settings) from webtest import TestApp self.testapp = TestApp(app)
def setUp(self): from tutorial import main app = main({}) from webtest import TestApp self.testapp = TestApp(app) def test_home(self): res = self.testapp.get('/', status=200) self.assertIn(b'<body>Visit', res.body) def test_hello(self): res = self.testapp.get('/howdy', status=200) self.assertIn(b'<body>Go back', res.body)
def setUp(self): import tempfile import os.path from tutorial import main self.tmpdir = tempfile.mkdtemp() dbpath = os.path.join( self.tmpdir, 'test.db') settings = { 'zodb_uri' : 'file://' + dbpath } app = main({}, **settings) from repoze.zodbconn.middleware import EnvironmentDeleterMiddleware app = EnvironmentDeleterMiddleware(app) from webtest import TestApp self.testapp = TestApp(app)
def setUp(self): from tutorial import main app = main({}) from webtest import TestApp self.testapp = TestApp(app) def test_home(self): res = self.testapp.get('/howdy/jane/doe', status=200) print('res.status') print(res.status) self.assertEqual(res.status, 200) self.assertIn(b'Jane', res.body) self.assertIn(b'Doe', res.body)
def setUp(self): from tutorial import main app = main({}) from webtest import TestApp self.testapp = TestApp(app) def test_plain_without_name(self): res = self.testapp.get('/plain', status=200) self.assertIn(b'No Name Provided', res.body) def test_plain_with_name(self): res = self.testapp.get('/plain?name=Jane%20Doe', status=200) self.assertIn(b'Jane Doe', res.body)
def setUp(self): import tempfile import os.path from tutorial import main self.tmpdir = tempfile.mkdtemp() dbpath = os.path.join(self.tmpdir, "test.db") uri = "file://" + dbpath settings = {"zodbconn.uri": uri, "pyramid.includes": ["pyramid_zodbconn", "pyramid_tm"]} app = main({}, **settings) self.db = app.registry.zodb_database from webtest import TestApp self.testapp = TestApp(app)
def setUp(self): import tempfile import os.path from tutorial import main self.tmpdir = tempfile.mkdtemp() dbpath = os.path.join( self.tmpdir, 'test.db') from repoze.zodbconn.uri import db_from_uri db = db_from_uri('file://' + dbpath) settings = { 'zodb_uri' : None } app = main({}, **settings) from repoze.zodbconn.connector import Connector app = Connector(app, db) self.db = db from webtest import TestApp self.testapp = TestApp(app)
def setUp(self): from tutorial import main app = main({}) from webtest import TestApp self.testapp = TestApp(app) def test_home(self): res = self.testapp.get('/', status=200) self.assertIn(b'<h1>Hi Home View', res.body) def test_hello(self): res = self.testapp.get('/howdy', status=200) self.assertIn(b'<h1>Hi Hello View', res.body) def test_hello_json(self): res = self.testapp.get('/howdy', status=200) self.assertIn(b'{"name": "Hello View"}', res.body) self.assertEqual(res.content_type, 'application/json')
def _callFUT(self, settings): from tutorial.scripts.populate import main main(['foo', 'development.ini'], settings)
def setUp(self): from tutorial import main settings = {} app = main(settings) from webtest import TestApp self.testApp = TestApp(app)
def main(): vars = tutorial.main() points_report = vars['points_report'] owner_id = vars['owner_id'] owner_dashboards = vars['owner_dashboards'] dashboard = vars['dashboard'] SECTION('Tile_config and tile_options') from mqe.dataseries import SeriesSpec from mqe.tiles import Tile tile_config = { 'series_spec_list': [ SeriesSpec(2, 0, { 'op': 'eq', 'args': ['john'] }), SeriesSpec(2, 0, { 'op': 'eq', 'args': ['monique'] }), ], 'tile_options': { 'tile_title': 'Points by user', } } tile = Tile.insert(owner_id, points_report.report_id, dashboard.dashboard_id, tile_config) pprint(tile.tile_options) tile_options2 = tile.tile_options.copy() tile_options2['owner_id'] = uuid.uuid4() tile2 = Tile.insert_with_tile_options(dashboard.dashboard_id, tile_options2) SECTION('Updating tile\'s config') from mqe.layouts import Layout, replace_tiles layout = Layout.select(owner_id, dashboard.dashboard_id) tile = layout.tile_dict.keys()[0] tile_config = tile.get_tile_config() tile_config['tile_options']['seconds_back'] = 3600 repl_tile = tile.insert_similar(tile_config) replace_tiles({tile: repl_tile}, for_layout_id=layout.layout_id) SECTION('Formatting tile data - tilewidgets and drawers') tile_config = { 'tw_type': 'Range', 'series_spec_list': [ SeriesSpec(2, 0, { 'op': 'eq', 'args': ['john'] }), SeriesSpec(2, 0, { 'op': 'eq', 'args': ['monique'] }), ], 'tile_options': { 'tile_title': 'Points by user', 'drawer_type': 'ChartRangeDrawer', 'colors': ['red', 'blue'], 'seconds_back': 3600, } } SECTION('Updating tile data') tile_data = tile.get_tile_data() input = """\ user_name is_active points john true 144 monique true 241 """ res = points_report.process_input(input) last_report_instance_id = tile_data['series_data'][0]['data_points'][ -1].rid new_tile_data = tile.get_new_tile_data(last_report_instance_id) SECTION('Managing colors') from mqe.dataseries import update_default_options tile_config = { 'series_spec_list': [ SeriesSpec(2, 0, { 'op': 'eq', 'args': ['john'] }), SeriesSpec(2, 0, { 'op': 'eq', 'args': ['monique'] }), ], 'tile_options': { 'colors': ['blue', 'red'], } } tile = Tile.insert(owner_id, points_report.report_id, dashboard.dashboard_id, tile_config) print tile.get_tile_data()['combined_colors'] update_default_options(tile) tile_config_2 = { 'series_spec_list': [ SeriesSpec(2, 0, { 'op': 'eq', 'args': ['monique'] }), ], } tile_2 = Tile.insert(owner_id, points_report.report_id, dashboard.dashboard_id, tile_config_2) print tile_2.get_tile_data()['combined_colors'] SECTION('Data series names') series_spec = SeriesSpec(2, 0, {'op': 'eq', 'args': ['monique']}) series_spec.set_name("monique's points") tile_config = {'series_spec_list': [series_spec]} tile = Tile.insert(owner_id, points_report.report_id, dashboard.dashboard_id, tile_config) print tile.get_tile_data()['series_data'][0]['name'] SECTION('Creating custom tilewidgets and drawers') from mqe.tilewidgets import register_drawer_class, Drawer @register_drawer_class class MaxNumberDrawer(Drawer): drawer_type = 'MaxNumberDrawer' def process_tile_data(self, tile_data): max_number = 0 for series_data in tile_data['series_data']: for point in series_data['data_points']: if int(point.value) > max_number: max_number = int(point.value) tile_data['max_number'] = max_number tile_config = { 'series_spec_list': [ SeriesSpec(2, 0, { 'op': 'eq', 'args': ['john'] }), SeriesSpec(2, 0, { 'op': 'eq', 'args': ['monique'] }), ], 'tile_options': { 'drawer_type': 'MaxNumberDrawer', } } tile = Tile.insert(owner_id, points_report.report_id, dashboard.dashboard_id, tile_config) print tile.get_tile_data()['max_number']
def main(username): clock = pg.time.Clock() font = pg.font.SysFont('Corbel', 60, bold=True) screen = pg.display.set_mode((800, 640), pg.RESIZABLE) def showScore(username): con = mysql.connector.connect(host='localhost', user='******', passwd=password, database='brain_rush') if con.is_connected(): try: cur = con.cursor() cur.execute( 'select high_score from user_dets where username = "******"'. format(username)) high_score = cur.fetchone()[0] bgImg = pg.image.load('QImages\\confetti.jpg') screen.blit(bgImg, (0, 0)) showError('High Score: ' + str(high_score), screen, x=290, y=300, color=(0, 0, 0), size=35) except mysql.connector.Error: showError('Database Issue; Please Try Later', screen) finally: con.close() else: showError('Error Connecting to Database; Please Try Later', screen) return False def updateScore(score, username): con = mysql.connector.connect(host='localhost', user='******', passwd=password, database='brain_rush') if con.is_connected(): try: cur = con.cursor() cur.execute( 'select high_score from user_dets where username = "******"'. format(username)) high_score = cur.fetchone() if high_score: if score > high_score[0]: cur.execute( 'update user_dets set high_score = {} where username = "******"' .format(score, username)) con.commit() return True except mysql.connector.Error: showError('Database Issue; Please Try Later', screen) finally: con.close() else: showError('Error Connecting to Database; Please Try Later', screen) return False done = False loop = 1 bg_main = pg.image.load("QImages\\traffic_wp.jpg") playerImg = pg.image.load('vampire.png') pg.display.set_icon(playerImg) pg.display.set_caption("Brain Rush!") while not done: try: screen.blit(bg_main, (0, 0)) except: done = True continue if loop: start_time = time.time() show = True while show: if time.time() - start_time > 0.088: show = False loop = 0 screen.blit(font.render('Welcome to Brain Rush!!!', True, (0, 0, 0)), (75, 20)) screen.blit(playerImg, (370, 70)) pos = pg.mouse.get_pos() click = pg.mouse.get_pressed() button('Start running', 300, 150, 200, 42, screen) button('How to play', 300, 250, 200, 42, screen) button('High score', 300, 350, 200, 42, screen) button('User details', 300, 450, 200, 42, screen) button('Leaderboard', 300, 550, 200, 42, screen) for event in pg.event.get(): if event.type == pg.QUIT: done = True pg.quit() if 500 > pos[0] > 300 and 192 > pos[1] > 150 and click[ 0] == 1 and not done: score = run.run() if updateScore(score, username): try: showError('New High Score!:' + str(score), screen, x=200, y=100, size=35) except: pass if 500 > pos[0] > 300 and 292 > pos[1] > 250 and click[ 0] == 1 and not done: tutorial.main(username) if 500 > pos[0] > 300 and 392 > pos[1] > 350 and click[ 0] == 1 and not done: showScore(username) if 500 > pos[0] > 300 and 492 > pos[1] > 450 and click[ 0] == 1 and not done: screen.fill((174, 214, 220)) done = True user_details.main(username) if 500 > pos[0] > 300 and 592 > pos[1] > 550 and click[ 0] == 1 and not done: Leaderboard.main(username) try: pg.display.update() except: pass clock.tick(30)
def app(app_settings): return main({}, **app_settings)
def app(app_settings, dbengine): return main({}, dbengine=dbengine, **app_settings)
def goTutorial(): global current_menu current_menu.turnOffButtons() tutorial.main()
def main(): vars = tutorial.main() owner_id = vars['owner_id'] owner_dashboards = vars['owner_dashboards'] dashboard = vars['dashboard'] points_report = vars['points_report'] SECTION('Label-less report instances') numbers = Report.select_or_insert(owner_id, 'numbers') input = """\ 10 20 30 40 50 60 """ res = numbers.process_input(input) series_spec = SeriesSpec(1, -1, {'op': 'eq', 'args': ['1']}) print series_spec.get_cell(res.report_instance) metric = Report.select_or_insert(owner_id, 'metric') res = metric.process_input('32.4') series_spec = SeriesSpec(0, -1, {'op': 'eq', 'args': ['0']}) print series_spec.get_cell(res.report_instance) SECTION('Handling reordering of columns') input = """\ user_name is_active points john true 128 monique true 210 """ res = points_report.process_input(input, force_header=[0]) series_spec = SeriesSpec(2, 0, {'op': 'eq', 'args': ['monique']}) print series_spec.get_cell(res.report_instance) input_2 = """\ user_name points is_active john 128 true monique 210 true """ res_2 = points_report.process_input(input_2, force_header=[0]) print series_spec.get_cell(res_2.report_instance) series_spec.promote_colnos_to_headers(res.report_instance) print series_spec.get_cell(res_2.report_instance) SECTION('A lower-level interface to data series') from mqe.dataseries import SeriesDef, get_series_values from datetime import datetime series_spec = SeriesSpec(2, 0, {'op': 'eq', 'args': ['monique']}) series_id = SeriesDef.insert(points_report.report_id, [], series_spec) series_def = SeriesDef.select(points_report.report_id, [], series_id) series_values = get_series_values(series_def, points_report, from_dt=datetime(2017, 1, 1), to_dt=datetime(2018, 1, 1)) point_values = [sv.value for sv in series_values]