# Path: elixir_models.py
# def setup(db_uri='simplemmo.sqlite', echo=False):
#     print "dburi:", db_uri
#     global db
#     db.init(db_uri)
#     db.connect()
#     db.create_tables([User, Character, Zone, Message, Object], True)
# 
# 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)
# 
# class Character(BaseModel):
#     '''Character contains the details for characters that users may control.'''
# 
#     name = CharField(unique=True)
# 
#     speed = FloatField(default=1)
# 
#     user = ForeignKeyField(User, related_name='characters')
#     # Also has 'zones'
# 
# 
#     def __repr__(self):
#         return '<Character "%s" owned by "%s">' % (self.name, self.user.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


import unittest
import json
import sys
import settings
from tornado.web import Application
from tornado.testing import AsyncHTTPTestCase
from mock import Mock
from elixir_models import setup as elixir_setup, User, Character
from playhouse.sqlite_ext import SqliteExtDatabase
from playhouse.test_utils import test_database
from charserver import CharacterZoneHandler
#
# Copyright (C) 2011, 2012  Charles Nelson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ##### END AGPL LICENSE BLOCK #####



sys.path.append(".")




test_db = SqliteExtDatabase(':memory:', fields={'json':'json'})


class TestCharacterZoneHandler(AsyncHTTPTestCase):
    def get_app(self):

# Path: elixir_models.py
# def setup(db_uri='simplemmo.sqlite', echo=False):
#     print "dburi:", db_uri
#     global db
#     db.init(db_uri)
#     db.connect()
#     db.create_tables([User, Character, Zone, Message, Object], True)
# 
# 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)
# 
# class Character(BaseModel):
#     '''Character contains the details for characters that users may control.'''
# 
#     name = CharField(unique=True)
# 
#     speed = FloatField(default=1)
# 
#     user = ForeignKeyField(User, related_name='characters')
#     # Also has 'zones'
# 
# 
#     def __repr__(self):
#         return '<Character "%s" owned by "%s">' % (self.name, self.user.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: tests/test_charserver.py
import unittest
import json
import sys
import settings
from tornado.web import Application
from tornado.testing import AsyncHTTPTestCase
from mock import Mock
from elixir_models import setup as elixir_setup, User, Character
from playhouse.sqlite_ext import SqliteExtDatabase
from playhouse.test_utils import test_database
from charserver import CharacterZoneHandler

#
# Copyright (C) 2011, 2012  Charles Nelson
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ##### END AGPL LICENSE BLOCK #####



sys.path.append(".")




test_db = SqliteExtDatabase(':memory:', fields={'json':'json'})


class TestCharacterZoneHandler(AsyncHTTPTestCase):
    def get_app(self):

        return Application([('/(.*)/zone', CharacterZoneHandler)], cookie_secret=settings.COOKIE_SECRET)