# Path: authserver.py
# class UserController(object):
# class RegistrationHandler(BaseHandler):
# class AuthHandler(BaseHandler):
# class LogoutHandler(BaseHandler):
# class CharacterHandler(BaseHandler):
#     def hash_password(cls, password):
#     def check_password(cls, plaintext, hashed):
#     def post(self):
#     def register_user(self, username, password, email=None):
#     def post(self):
#     def authenticate(self, username, password):
#     def set_admin(self, user):
#     def set_current_user(self, user):
#     def get(self):
#     def get(self):
#     def get_characters(self, username):
# 
# Path: charserver.py
# class CharacterZoneHandler(BaseHandler):
#     '''CharacterZoneHandler gets zone information for a given character.'''
# 
#     def get(self, character):
#         self.write(json.dumps(self.get_zone(character)))
#         self.set_header('Content-Type', 'application/json')
# 
#     def get_zone(self, charname):
#         '''Queries the database for information pertaining directly
#         to the character.
#         It currently only returns the zone the character is in.'''
#         return {'zone':'playerinstance-GhibliHills-%s' % (charname,)}
# 
#     # TODO: Add character online/offline status
# 
# Path: zoneserver.py
# class ObjectsHandler(DateLimitedObjectHandler):
#     '''ObjectsHandler returns a list of objects and their data.'''
#     target_object = Object
# 
# class CharStatusHandler(BaseHandler):
#     '''Manages if a character is active in the zone or not.'''
# 
#     @tornado.web.authenticated
#     def post(self):
#         user = self.get_secure_cookie('user')
#         character = self.get_argument('character', '')
#         status = self.get_argument('status', '')
#         self.char_controller = CharacterController()
# 
#         # If the character is not owned by this user, disallow it.
# #         if not self.char_controller.is_owner(user, character):
# #             retval = False
# 
#         retval = False
#         # Only allow setting the status to online or offline.
#         if status in ("online", "offline"):
#             if self.char_controller.set_char_status(character, status, user=user):
#                 retval = True
# 
#         self.write(json.dumps(retval))
# 
# class MovementHandler(BaseHandler):
#     '''A stupid HTTP-based handler for handling character movement.'''
#     @tornado.web.authenticated
#     def post(self):
#         character = self.get_argument('character', '')
#         user = self.get_secure_cookie('user')
#         self.char_controller = CharacterController()
# #         if not self.char_controller.is_owner(user, character):
# #             self.set_status(403)
# #             self.write("User %s does not own Character %s." % (user, character))
# #             return False
# 
#         xmod = int(self.get_argument('x', 0))
#         ymod = int(self.get_argument('y', 0))
#         zmod = int(self.get_argument('z', 0))
#         logging.info("Locmod is: %d, %d, %d" % (xmod, ymod, zmod))
# 
#         result = self.char_controller.set_movement(character, xmod, ymod, zmod, user=user)
# 
#         logging.info("Tried to set movement, result was: %s" % result)
# 
#         if result is not False:
#             retval = result.json_dumps()
#         else:
#             retval = json.dumps(result, cls=ComplexEncoder)
# 
#         self.content_type = 'application/json'
#         self.write(retval)
# 
# Path: elixir_models.py
# class RetryDB(RetryOperationalError, SqliteExtDatabase):
# class ComplexEncoder(json.JSONEncoder):
# class BaseModel(Model):
#     class Meta:
# class User(BaseModel):
# class Character(BaseModel):
# class Zone(BaseModel):
# class Message(BaseModel):
# class Object(BaseModel):
# class Message(BaseModel):
# class ScriptedObject(Object):
#     def default(self, obj):
#     def exists(cls, *args, **kwargs):
#     def json_dumps(self):
#     def __repr__(self):
#     def __repr__(self):
#     def loc(self):
#     def loc(self, val):
#     def set_modified(self, date_time=None):
#     def get_objects(since=None, physical=None, limit=None, player=None, scripted=None, name=None):
# def setup(db_uri='simplemmo.sqlite', echo=False):
# 
# Path: elixir_models.py
# class User(BaseModel):
#     '''User contains details useful for authenticating a user for when they
#     initially log in.'''
# 
#     username = CharField(unique=True)
#     password = CharField()
#     email = CharField(null=True)
#     # Also has 'characters'
# 
#     def __repr__(self):
#         uname = self.username
#         s = "s"*(len(self.characters)-1)
#         chars = ', '.join([c.name for c in self.characters])
#         return '<User "%s" owning character%s: %s.>' % (uname, s, chars)


import unittest
import sys
import json
import settings
from tornado.web import Application
from tornado.testing import AsyncHTTPTestCase
from urllib import urlencode
from authserver import PingHandler, AuthHandler, LogoutHandler, CharacterHandler
from charserver import CharacterZoneHandler
from zoneserver import ObjectsHandler, CharStatusHandler, MovementHandler
from elixir import session
from elixir_models import metadata, setup_all, create_all
from elixir_models import User
#!/usr/bin/env python2.7
'''Test the full client access sequence.
It is pretty much the anti-pattern of testing.
'''


sys.path.append(".")





def set_up_db():
    '''Connects to an in-memory SQLite database,
    with the purpose of emptying it and recreating it.'''
    metadata.bind = "sqlite:///:memory:"
#     metadata.bind.echo = True
    setup_all()
    create_all()

# Call it the first time for tests that don't care if they have clean data.
set_up_db()

class TestFullIntegration(AsyncHTTPTestCase):
    def get_app(self):
        handlers = []
        handlers.append((r"/ping", PingHandler))
        handlers.append((r"/login", AuthHandler))

# Path: authserver.py
# class UserController(object):
# class RegistrationHandler(BaseHandler):
# class AuthHandler(BaseHandler):
# class LogoutHandler(BaseHandler):
# class CharacterHandler(BaseHandler):
#     def hash_password(cls, password):
#     def check_password(cls, plaintext, hashed):
#     def post(self):
#     def register_user(self, username, password, email=None):
#     def post(self):
#     def authenticate(self, username, password):
#     def set_admin(self, user):
#     def set_current_user(self, user):
#     def get(self):
#     def get(self):
#     def get_characters(self, username):
# 
# Path: charserver.py
# class CharacterZoneHandler(BaseHandler):
#     '''CharacterZoneHandler gets zone information for a given character.'''
# 
#     def get(self, character):
#         self.write(json.dumps(self.get_zone(character)))
#         self.set_header('Content-Type', 'application/json')
# 
#     def get_zone(self, charname):
#         '''Queries the database for information pertaining directly
#         to the character.
#         It currently only returns the zone the character is in.'''
#         return {'zone':'playerinstance-GhibliHills-%s' % (charname,)}
# 
#     # TODO: Add character online/offline status
# 
# Path: zoneserver.py
# class ObjectsHandler(DateLimitedObjectHandler):
#     '''ObjectsHandler returns a list of objects and their data.'''
#     target_object = Object
# 
# class CharStatusHandler(BaseHandler):
#     '''Manages if a character is active in the zone or not.'''
# 
#     @tornado.web.authenticated
#     def post(self):
#         user = self.get_secure_cookie('user')
#         character = self.get_argument('character', '')
#         status = self.get_argument('status', '')
#         self.char_controller = CharacterController()
# 
#         # If the character is not owned by this user, disallow it.
# #         if not self.char_controller.is_owner(user, character):
# #             retval = False
# 
#         retval = False
#         # Only allow setting the status to online or offline.
#         if status in ("online", "offline"):
#             if self.char_controller.set_char_status(character, status, user=user):
#                 retval = True
# 
#         self.write(json.dumps(retval))
# 
# class MovementHandler(BaseHandler):
#     '''A stupid HTTP-based handler for handling character movement.'''
#     @tornado.web.authenticated
#     def post(self):
#         character = self.get_argument('character', '')
#         user = self.get_secure_cookie('user')
#         self.char_controller = CharacterController()
# #         if not self.char_controller.is_owner(user, character):
# #             self.set_status(403)
# #             self.write("User %s does not own Character %s." % (user, character))
# #             return False
# 
#         xmod = int(self.get_argument('x', 0))
#         ymod = int(self.get_argument('y', 0))
#         zmod = int(self.get_argument('z', 0))
#         logging.info("Locmod is: %d, %d, %d" % (xmod, ymod, zmod))
# 
#         result = self.char_controller.set_movement(character, xmod, ymod, zmod, user=user)
# 
#         logging.info("Tried to set movement, result was: %s" % result)
# 
#         if result is not False:
#             retval = result.json_dumps()
#         else:
#             retval = json.dumps(result, cls=ComplexEncoder)
# 
#         self.content_type = 'application/json'
#         self.write(retval)
# 
# Path: elixir_models.py
# class RetryDB(RetryOperationalError, SqliteExtDatabase):
# class ComplexEncoder(json.JSONEncoder):
# class BaseModel(Model):
#     class Meta:
# class User(BaseModel):
# class Character(BaseModel):
# class Zone(BaseModel):
# class Message(BaseModel):
# class Object(BaseModel):
# class Message(BaseModel):
# class ScriptedObject(Object):
#     def default(self, obj):
#     def exists(cls, *args, **kwargs):
#     def json_dumps(self):
#     def __repr__(self):
#     def __repr__(self):
#     def loc(self):
#     def loc(self, val):
#     def set_modified(self, date_time=None):
#     def get_objects(since=None, physical=None, limit=None, player=None, scripted=None, name=None):
# def setup(db_uri='simplemmo.sqlite', echo=False):
# 
# Path: elixir_models.py
# class User(BaseModel):
#     '''User contains details useful for authenticating a user for when they
#     initially log in.'''
# 
#     username = CharField(unique=True)
#     password = CharField()
#     email = CharField(null=True)
#     # Also has 'characters'
# 
#     def __repr__(self):
#         uname = self.username
#         s = "s"*(len(self.characters)-1)
#         chars = ', '.join([c.name for c in self.characters])
#         return '<User "%s" owning character%s: %s.>' % (uname, s, chars)


# Path: tests/integration/test_full_integration.py
import unittest
import sys
import json
import settings
from tornado.web import Application
from tornado.testing import AsyncHTTPTestCase
from urllib import urlencode
from authserver import PingHandler, AuthHandler, LogoutHandler, CharacterHandler
from charserver import CharacterZoneHandler
from zoneserver import ObjectsHandler, CharStatusHandler, MovementHandler
from elixir import session
from elixir_models import metadata, setup_all, create_all
from elixir_models import User

#!/usr/bin/env python2.7
'''Test the full client access sequence.
It is pretty much the anti-pattern of testing.
'''


sys.path.append(".")





def set_up_db():
    '''Connects to an in-memory SQLite database,
    with the purpose of emptying it and recreating it.'''
    metadata.bind = "sqlite:///:memory:"
#     metadata.bind.echo = True
    setup_all()
    create_all()

# Call it the first time for tests that don't care if they have clean data.
set_up_db()

class TestFullIntegration(AsyncHTTPTestCase):
    def get_app(self):
        handlers = []
        handlers.append((r"/ping", PingHandler))
        handlers.append((r"/login", AuthHandler))

        handlers.append((r"/logout", LogoutHandler))