Permalink
Browse files

Added testapp from the pycon2012 repository. It has a couple of butto…

…ns to test

out several functionalities.

Updated .gitignore, updated the little TODO file there... but we should take
it out.
  • Loading branch information...
abourget committed Mar 17, 2012
1 parent 491d6fa commit 50446ae053253af95eae2fb305a6bc3d86727285
View
@@ -3,6 +3,7 @@ jst.js
prod.ini
data/
*.swo
*~
# web assets generated directory
gen/
.webassets-cache/
View
2 TODO
@@ -1 +1,3 @@
* Find an easy way to send disconnected events.:wq
* Implement server-side "once" event... to add an event listener only once.
@@ -0,0 +1,11 @@
[app:main]
paste.app_factory = testapp:main
session.type = file
session.data_dir = /tmp/chatter/data/sessions/data
session.lock_dir = /tmp/chatter/data/sessions/lock
sqlalchemy.url = sqlite:///%(here)s/chatter.db
[server:main]
use = egg:waitress#main
port = 6543
host = 0.0.0.0
View
@@ -0,0 +1,10 @@
from socketio.server import SocketIOServer
from pyramid.paster import get_app
from gevent import monkey; monkey.patch_all()
if __name__ == '__main__':
app = get_app('development.ini')
print 'Listening on port http://127.0.0.1:8080 and on port 843 (flash policy server)'
SocketIOServer(('127.0.0.1', 8080), app, policy_server=False,
transports=['websocket']).serve_forever()
View
@@ -0,0 +1,61 @@
import os
import sys
from setuptools import setup, find_packages, Command
here = os.path.abspath(os.path.dirname(__file__))
def _read(path):
with open(path) as f:
data= f.read()
f.close()
return data
README = ''
CHANGES = ''
requires = []
if sys.version_info[:3] < (2,5,0):
requires.append('pysqlite')
class PyTest(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import subprocess
errno = subprocess.call('py.test')
raise SystemExit(errno)
setup(name='testapp',
version='0.0',
description='testapp',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pylons",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
author='',
author_email='',
url='',
keywords='web wsgi bfg pylons pyramid',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
test_suite='testapp',
install_requires = requires,
#cmdclass = {'test': PyTest},
entry_points = """\
[paste.app_factory]
main = testapp:main
""",
paster_plugins=['pyramid'],
)
@@ -0,0 +1,34 @@
#!/usr/bin/env python
from sqlalchemy import engine_from_config
from pyramid.config import Configurator
from testapp.views import socketio_service
from testapp.views import index
from testapp.models import DBSession
def simple_route(config, name, url, fn):
""" Function to simplify creating routes in pyramid
Takes the pyramid configuration, name of the route, url, and view
function
"""
config.add_route(name, url)
config.add_view(fn, route_name=name,
renderer="testapp:templates/%s.mako" % name)
def main(global_config, **settings):
config = Configurator()
engine = engine_from_config(settings, 'sqlalchemy.')
DBSession.configure(bind=engine)
simple_route(config, 'index', '/', index)
# The socketio view configuration
config.add_route('socket_io', 'socket.io/*remaining')
config.add_static_view('static', 'static', cache_max_age=3600)
config.scan('testapp.views')
app = config.make_wsgi_app()
return app
@@ -0,0 +1,21 @@
from sqlalchemy import Column
from sqlalchemy.types import UnicodeText
from sqlalchemy.types import Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session
from sqlalchemy.orm import sessionmaker
DBSession = scoped_session(sessionmaker())
Base = declarative_base()
class Chat(Base):
""" Base model for storing the chat log """
__table_args__ = {'sqlite_autoincrement': True}
__tablename__ = 'chat'
pk = Column(Integer, primary_key=True, autoincrement=True)
chat_line = Column(UnicodeText, nullable=False)
def includeme(config):
""" Pyramid configuration """
config.scan('testapp.models')
@@ -0,0 +1 @@
# package
@@ -0,0 +1,49 @@
#!/usr/bin/env python
import os
import sys
from pyramid.config import Configurator
from sqlalchemy import engine_from_config
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import scoped_session
from testapp.models import Base
from pyramid.paster import (
get_appsettings,
setup_logging,
)
DBSession = scoped_session(sessionmaker())
here = os.path.dirname(__file__)
def usage(argv):# pragma: no cover
cmd = os.path.basename(argv[0])
print('usage: %s <config_uri>\n'
'(example: "%s development.ini")' % (cmd, cmd))
sys.exit(1)
def main(argv=sys.argv): # pragma: no cover
if len(argv) != 2:
usage(argv)
config_uri = argv[1]
setup_logging(config_uri)
settings = get_appsettings(config_uri)
config = Configurator(
settings=settings
)
config.include('testapp.models')
engine = engine_from_config(settings, 'sqlalchemy.')
Base.metadata.bind = engine
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)
if __name__ == "__main__": # pragma: no cover
main()
Oops, something went wrong.

0 comments on commit 50446ae

Please sign in to comment.