def test_site_notification_update(self): active = 'True' impressions = '7' content = 'test1' user_role = 'test2' page_regex = 'test3' page_tool_type = 'test4' note = M.notification.SiteNotification(active=False, impressions=0, content='test') ThreadLocalORMSession().flush_all() count = M.notification.SiteNotification.query.find().count() r = self.app.post('/nf/admin/site_notifications/{}/update'.format(note._id), params=dict( active=active, impressions=impressions, content=content, user_role=user_role, page_regex=page_regex, page_tool_type=page_tool_type)) ThreadLocalORMSession().flush_all() note = M.notification.SiteNotification.query.find().sort('_id', -1).next() assert '/nf/admin/site_notifications' in r.location assert M.notification.SiteNotification.query.find().count() == count assert note.active == bool('True') assert note.impressions == int(impressions) assert note.content == content assert note.user_role == user_role assert note.page_regex == page_regex assert note.page_tool_type == page_tool_type
def test_site_notification_edit_template(self): note = M.notification.SiteNotification(active=True, impressions=0, content='test1', user_role='test2', page_regex='test3', page_tool_type='test4') ThreadLocalORMSession().flush_all() r = self.app.get('/nf/admin/site_notifications/{}/edit'.format(note._id)) assert r assert 'checked' in r.form['active'].attrs assert r.form['impressions'].value == '0' assert r.form['content'].value == 'test1' assert r.form['user_role'].value == 'test2' assert r.form['page_regex'].value == 'test3' assert r.form['page_tool_type'].value == 'test4' assert 'Edit Site Notification' in r assert 'Active' in r assert 'Impressions' in r assert 'Content' in r assert 'User Role' in r assert 'Page Regex' in r assert 'Page Type' in r
def test_site_notifications(self): M.notification.SiteNotification(active=True, impressions=0, content='test1', user_role='test2', page_regex='test3', page_tool_type='test4') ThreadLocalORMSession().flush_all() assert M.notification.SiteNotification.query.find().count() == 1 r = self.app.get('/nf/admin/site_notifications/', extra_environ=dict( username='******')) table = r.html.find('table') headers = table.findAll('th') row = table.findAll('td') assert headers[0].contents[0] == 'Active' assert headers[1].contents[0] == 'Impressions' assert headers[2].contents[0] == 'Content' assert headers[3].contents[0] == 'User Role' assert headers[4].contents[0] == 'Page Regex' assert headers[5].contents[0] == 'Page Type' assert row[0].contents[0].contents[0] == 'True' assert row[1].contents[0].contents[0] == '0' assert row[2].contents[0].contents[0] == 'test1' assert row[3].contents[0].contents[0] == 'test2' assert row[4].contents[0].contents[0] == 'test3' assert row[5].contents[0].contents[0] == 'test4'
def setUp(self): super(TestUsersSearch, self).setUp() # Create user that matches TEST_HIT id _id = ObjectId('540efdf2100d2b1483155d39') u = M.User.query.get(_id=_id) if not u: M.User(_id=_id, username='******') ThreadLocalORMSession().flush_all()
def test_site_notification_delete(self): note = M.notification.SiteNotification(active=False, impressions=0, content='test') ThreadLocalORMSession().flush_all() count = M.notification.SiteNotification.query.find().count() self.app.post('/nf/admin/site_notifications/{}/delete'.format(note._id)) assert M.notification.SiteNotification.query.find().count() == count -1 assert M.notification.SiteNotification.query.get(_id=bson.ObjectId(note._id)) is None
def setUp(self): super(TestProjectsSearch, self).setUp() # Create project that matches TEST_HIT id _id = ObjectId('53ccf6e8100d2b0741746e9f') p = M.Project.query.get(_id=_id) if not p: M.Project( _id=_id, neighborhood_id=M.Neighborhood.query.get(url_prefix='/u/')._id, shortname='test-project', ) ThreadLocalORMSession().flush_all()
def update(self, active=True, impressions=0, content='', user_role=None, page_regex=None, page_tool_type=None): self.note.active = active self.note.impressions = impressions self.note.content = content self.note.user_role = user_role self.note.page_regex = page_regex self.note.page_tool_type = page_tool_type ThreadLocalORMSession().flush_all() redirect('..')
def create(self, impressions, content, user_role, page_regex, page_tool_type, active=False): """Post a new note""" M.notification.SiteNotification(active=active, impressions=impressions, content=content, user_role=user_role, page_regex=page_regex, page_tool_type=page_tool_type) ThreadLocalORMSession().flush_all() redirect('../site_notifications')
def delete(self): self.note.delete() ThreadLocalORMSession().flush_all() redirect(request.referer)
import ming from ming.datastore import create_datastore from ming import Session from ming import schema as s from ming.odm import ThreadLocalORMSession, FieldProperty, Mapper from ming.odm.declarative import MappedClass from datetime import datetime mainsession = Session() DBSession = ThreadLocalORMSession(mainsession) database_setup = False bind = None def setup_database(): global bind, database_setup if not database_setup: bind = create_datastore('mim:///test') mainsession.bind = bind ming.odm.Mapper.compile_all() database_setup = True def clear_database(): global engine, database_setup if not database_setup: setup_database() class Thing(MappedClass):
def delete(self): self.note.delete() ThreadLocalORMSession().flush_all() redirect(six.ensure_text(request.referer or '/'))
from ming.datastore import DataStore from ming.odm import ThreadLocalORMSession __all__ = ['session'] engine = DataStore(database='flask_tutorial') session = ThreadLocalORMSession(bind=engine)