def apply(self): return # see # 21 access_tuple = patches.utils.parseDBAccessDirective() con = patches.utils.getPostgreSQLConnection(*access_tuple) cur = con.cursor() cur.execute("""alter table location add column city VARCHAR(40);""") con.commit() dburi = patches.utils.parseDBURI('dev.cfg').split('=')[1][1:-1] database.set_db_uri(dburi) database.run_with_transaction(add_cities)
def tearDown(self): """Clear database configuration and drop database. """ try: session.expunge_all() except: session.clear() clear_mappers() metadata.drop_all() metadata.clear() set_db_uri(self.sa_dburi, 'sqlalchemy')
def setUp(self): """Set database configuration and set up database. """ self.sa_dburi = config.get('sqlalchemy.dburi') set_db_uri('sqlite:///:memory:', 'sqlalchemy') bind_metadata() self.users_table = Table("users", metadata, Column("user_id", Integer, primary_key=True), Column("user_name", String(40)), Column("password", String(10))) metadata.create_all()
def setup_module(): global _sa_dburi, _so_dburi _so_dburi = config.get("sqlobject.dburi", "sqlite:///:memory:") _sa_dburi = config.get("sqlalchemy.dburi", "sqlite:///:memory:") # sqlalchemy setup database.set_db_uri({"sqlalchemy.dburi": "sqlite:///:memory:"}) sqlalchemy_cleanup() get_engine() # sqlobject setup database.set_db_uri("sqlite:///:memory:") # table setup create_tables() hub.commit()
def apply(self): # This is copied from patch #25 access_tuple = patches.utils.parseDBAccessDirective() con = patches.utils.getPostgreSQLConnection(*access_tuple) cur = con.cursor() cur.execute("ALTER TABLE location ADD COLUMN is_region int DEFAULT 0") cur.execute("ALTER TABLE location add column in_region_id INTEGER CONSTRAINT in_region_id_exists REFERENCES location(id)") cur.execute("""alter table location add column city VARCHAR(40);""") con.commit() # end of patch # 25 dburi = patches.utils.parseDBURI('dev.cfg').split('=')[1][1:-1] database.set_db_uri(dburi) database.run_with_transaction(setup_microsite_spaces) database.run_with_transaction(migrate)
def setup_module(): global _sa_dburi, _so_dburi _so_dburi = config.get("sqlobject.dburi", "sqlite:///:memory:") _sa_dburi = config.get("sqlalchemy.dburi", "sqlite:///:memory:") # sqlalchemy setup database.set_db_uri("sqlite:///:memory:", "sqlalchemy") sqlalchemy_cleanup() bind_metadata() # sqlobject setup database.set_db_uri("sqlite:///:memory:", "sqlobject") create_tables() hub.commit()
def apply(self): # This is copied from patch #25 access_tuple = patches.utils.parseDBAccessDirective() con = patches.utils.getPostgreSQLConnection(*access_tuple) dburi = patches.utils.parseDBURI('dev.cfg').split('=')[1][1:-1] database.set_db_uri(dburi) database.run_with_transaction(setup_listtable) cur = con.cursor() cur.execute("ALTER TABLE list_item ADD COLUMN list_id INTEGER CONSTRAINT list_id_exists REFERENCES list(id)") con.commit() database.run_with_transaction(migrate_lists) database.run_with_transaction(create_subpage_lists)
def populate_default_data(): """Populates default data into a new database. Run from shell: $ python calabro/model.py """ # figure out why I have to set this manually, PackageHub can not seem to find the dev.cfg set_db_uri(dburi="mysql://root:@localhost:5432/calabro") user = User(user_name="Joe", email_address="*****@*****.**", display_name="Joe John", password="******") user2 = User(user_name="applepy", email_address="*****@*****.**", display_name="Apple Py", password="******") group = Group(group_name="admin", display_name="Administrator") permission = Permission(permission_name="create_posts", description="Can create new posts") group.addPermission(permission) group.addUser(user) group.addUser(user2) theme1 = Themes(name="hemingway_reloaded") theme2 = Themes(name="simpla") site = Sites( title="My Blog", name="my", subtitle="Calabro powered", email="*****@*****.**", about_image="/static/images/calabro_logo.png", url="http://code.google.com/p/calabro", posts_per_page=5, description="""The fun easy to use web publishing system.""", theme="hemingway_reloaded", ) site2 = Sites( title="Python Talk", name="py_talk", subtitle="Discussing Python", about_image="/static/images/py_talk.png", email="*****@*****.**", url="http://py_talk.com", posts_per_page=10, description="""The joy, questions, answers, and ramblings in the Python world.""", theme="simpla", ) site.addUser(user) site2.addUser(user2)
def apply(self): uri = capture_pg_uri() con = getPostgreSQLConnection(uri) cur = con.cursor() cur.execute(""" ALTER TABLE tg_user ADD COLUMN rfid VARCHAR(40); ALTER TABLE location ADD COLUMN holidays BYTEA DEFAULT '%s'; ALTER TABLE tg_user ADD COLUMN access_policies BYTEA DEFAULT '%s'; ALTER TABLE tg_user ADD COLUMN disabled_policies BYTEA DEFAULT '%s'; DROP TABLE open; ALTER TABLE location drop column opens RESTRICT, drop column closes RESTRICT; ALTER TABLE user_group add column id SERIAL PRIMARY KEY; ALTER TABLE resourcegroup add column group_type VARCHAR(40) DEFAULT 'member_calendar'; ALTER TABLE location add column calendar_id INTEGER CONSTRAINT calendar_id_exists REFERENCES resource(id); """ %(empty_list_pickle, empty_list_pickle, empty_list_pickle)) con.commit() database.set_db_uri(uri['pg_uri']) database.run_with_transaction(create_tables) database.run_with_transaction(update_locations)
modulename = "%s.app" % dirpath[2:].replace(os.sep, ".") break else: modulename = None # XXX This is a temporary workaround, the code above to find the config # package should really be improved and moved elsewhere. # See http://trac.turbogears.org/ticket/2043 try: update_config(configfile="test.cfg", modulename=modulename) except ImportError, exc: import warnings warnings.warn("Could not import configuration from module: %s" % exc, RuntimeWarning) update_config(configfile="test.cfg", modulename=None) else: database.set_db_uri("sqlite:///:memory:") config.update( {'global': { 'autoreload.on': False, 'tg.new_style_logging': True }}) def start_cp(): if not config.get("cherrypy_started", False): cherrypy.server.start(serverClass=None, initOnly=True) config.update({"cherrypy_started": True}) test_user = None
def apply(self): # This is copied from patch #25 dburi = patches.utils.parseDBURI("dev.cfg").split("=")[1][1:-1] database.set_db_uri(dburi) database.run_with_transaction(fix_users_without_object_references)
def apply(self): access_tuple = patches.utils.parseDBAccessDirective() dburi = patches.utils.parseDBURI('dev.cfg').split('=')[1][1:-1] database.set_db_uri(dburi) database.run_with_transaction(sync_joinus_field)
modulename = "%s.app" % dirpath[2:].replace(os.sep, ".") break else: modulename = None # XXX This is a temporary workaround, the code above to find the config # package should really be improved and moved elsewhere. # See http://trac.turbogears.org/ticket/2043 try: update_config(configfile="test.cfg", modulename=modulename) except ImportError, exc: import warnings warnings.warn("Could not import configuration from module: %s" % exc, RuntimeWarning) update_config(configfile="test.cfg", modulename=None) else: database.set_db_uri("sqlite:///:memory:") config.update({'global': {'autoreload.on': False, 'tg.new_style_logging': True}}) def start_cp(): if not config.get("cherrypy_started", False): cherrypy.server.start(serverClass=None, initOnly=True) config.update({"cherrypy_started" : True}) test_user = None def set_identity_user(user): """Setup a user for configuring request's identity."""
import cherrypy import inspect, sqlobject from sqlobject.inheritance import InheritableSQLObject config.update({ 'visit.on': True, 'identity.on': True, 'identity.failure_url': '/login', }) cherrypy.root = Root() #work on the dev database, so that we don't have to repopulate all the time #and can also check on the results of the tests base = '/'.join(model.__file__.split('/')[:-2]) #database.set_db_uri("sqlite:///%s/devdata.sqlite" % base) database.set_db_uri("sqlite:///%s/devdata.sqlite" % base) #Have our own testclass so that we destroy data at the beginning of the tests class Hubspacetest(testutil.DBTest): def setUp(self): print "asdfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" for item in model.__dict__.values(): if inspect.isclass(item) and issubclass(item, sqlobject.SQLObject) and item != sqlobject.SQLObject \ and item != InheritableSQLObject: item.dropTable(ifExists=True) testutil.DBTest.setUp(self) self.objs = populate() def tearDown(self): startup.stopTurboGears() pass
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from datetime import datetime from sqlalchemy import * from sqlalchemy.orm import relation from turbogears import database database.set_db_uri('sqlite:///:memory:', 'sqlalchemy') database.get_engine() metadata = database.metadata metadata.bind.echo = True groups_table = Table('tg_group', metadata, Column('group_id', Integer, primary_key=True), Column('group_name', Unicode(16), unique=True), Column('display_name', Unicode(255)), Column('created', DateTime, default=datetime.now) ) users_table = Table('tg_user', metadata, Column('user_id', Integer, primary_key=True), Column('user_name', Unicode(16), unique=True), Column('email_address', Unicode(255), unique=True),
# def get_model(self): # return User # def test_creation(self): # "Object creation should set the name" # obj = User(user_name = "creosote", # email_address = "*****@*****.**", # display_name = "Mr Creosote", # password = "******") # assert obj.display_name == "Mr Creosote" import maap.model as model from maap.model import Place, Module, Lesson, MapAsset, MapPatch, ImageAsset, VideoAsset soClasses = [Place, Module, Lesson, MapAsset, MapPatch, ImageAsset, VideoAsset] database.set_db_uri("sqlite:///:memory:?debug=1") def create_tables(): for c in soClasses: c.createTable(ifNotExists = True) def drop_tables(): cs = soClasses[:] cs.reverse() for c in cs: c.dropTable(ifExists=True) class TestPlace(testutil.DBTest): def setUp(self): drop_tables()