Ejemplo n.º 1
0
    def character_create_test(self):
        from tof.models.sotc.character import SotCCharacter as Character
        from tof.models.sotc.crunch import Skill, Aspect, Stunt, Ladder

        try:
            with transaction.manager:
                aspects = [Aspect(name="\"Lucy\", the Century Clipper"), Aspect(name="Fly by Night")]
                skills = [Skill(name="Contacting", level=Ladder.superb), Skill(name="Pilot", level=Ladder.great)]
                stunts = [Stunt(name="Walk the Walk"), Stunt(name="Lucy (Personal Gadget)")]
                model = Character(name='Mack Silver, Entrepreneurial Pilot', played_by="John", skills=skills, aspects=aspects, stunts=stunts, fate_points=11, refresh_rate=11)
                DBSession.add(model)

            with transaction.manager:
                model = DBSession.query(Character).filter(Character.name=="Mack Silver, Entrepreneurial Pilot").one()
                self.assertEqual(model.name, "Mack Silver, Entrepreneurial Pilot")
                self.assertEqual(model.played_by, "John")
                self.assertEqual(model.fate_points, 11)
                self.assertEqual(model.refresh_rate, 11)
                self.assertItemsEqual([m.name for m in model.aspects], [a.name for a in aspects])
                self.assertItemsEqual([{m.name: m.level} for m in model.skills], [{m.name: m.level.value} for m in skills])
                self.assertItemsEqual([m.name for m in model.stunts], [a.name for a in stunts])
        finally:
            with transaction.manager:
                c = DBSession.query(Character).filter(Character.name=="Mack Silver, Entrepreneurial Pilot").one()
                DBSession.delete(c)
                for skill in skills: 
                    s = DBSession.query(Skill).filter(Skill.name==skill.name).one()
                    DBSession.delete(s)
                for aspect in aspects: 
                    s = DBSession.query(Aspect).filter(Aspect.name==aspect.name).one()
                    DBSession.delete(s)
                for stunt in stunts: 
                    s = DBSession.query(Stunt).filter(Stunt.name==stunt.name).one()
                    DBSession.delete(s)
Ejemplo n.º 2
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from tof.models import (
         Base,
         MyModel,
         )
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         model = MyModel(name='one', value=55)
         DBSession.add(model)
Ejemplo n.º 3
0
    def stunt_create_test(self):
        from tof.models.sotc.crunch import Stunt
        try:
            with transaction.manager:
                name = "Stupendous Stunt"
                model = Stunt(name=name)
                DBSession.add(model)

            with transaction.manager:
                model = DBSession.query(Stunt).filter(Stunt.name==name).one()
                self.assertEqual(model.name, name)
        finally:
            with transaction.manager:
                DBSession.delete(model)
Ejemplo n.º 4
0
    def aspect_create_test(self):
        from tof.models.sotc.crunch import Aspect
        try:
            with transaction.manager:
                name = "Astounding Aspect"
                model = Aspect(name=name)
                DBSession.add(model)

            with transaction.manager:
                model = DBSession.query(Aspect).filter(Aspect.name==name).one()
                self.assertEqual(model.name, name)
        finally:
            with transaction.manager:
                DBSession.delete(model)
Ejemplo n.º 5
0
    def character_create_test(self):
        from tof.models.character import Character
        try:
            with transaction.manager:
                model = Character(name='Mack Silver, Entrepreneurial Pilot', played_by="John")
                DBSession.add(model)

            with transaction.manager:
                model = DBSession.query(Character).filter(Character.name=="Mack Silver, Entrepreneurial Pilot").one()
                self.assertEqual(model.name, "Mack Silver, Entrepreneurial Pilot")
                self.assertEqual(model.played_by, "John")
        finally:
            with transaction.manager:
                DBSession.delete(model)
Ejemplo n.º 6
0
    def skill_create_test(self):
        from tof.models.sotc.crunch import Skill, Ladder
        try:
            with transaction.manager:
                name = "Superlative Skill"
                model = Skill(name=name, level=Ladder.superb)
                DBSession.add(model)

            with transaction.manager:
                model = DBSession.query(Skill).filter(Skill.name==name).one()
                self.assertEqual(model.name, name)
                self.assertEqual(model.level, Ladder.superb.value)
        finally:
            with transaction.manager:
                DBSession.delete(model)
Ejemplo n.º 7
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        character = Character(name='Jet Black, Flying Soldier', played_by="John", fate_points=11, refresh_rate=11)
        DBSession.add(character)
        aspect = Aspect(name='Amazing Jet Pack!')
        DBSession.add(aspect)
        skill = Skill(name='Athletics', level=Ladder.superb)
        DBSession.add(skill)
        stunt = Stunt(name='The Amazing Jet Pack')
        DBSession.add(stunt)
        character = Character(name='Henry White, Gentelman Thief', played_by="Radek", fate_points=10, refresh_rate=3)
        DBSession.add(character)
Ejemplo n.º 8
0
 def character_duplicate_test(self):
     from tof.models.character import Character
     with self.assertRaises(IntegrityError):
         with transaction.manager:
             model = Character(name='Jet Black, Flying Soldier', played_by="John")
             DBSession.add(model)
Ejemplo n.º 9
0
 def character_duplicate_test(self):
     from tof.models.sotc.character import SotCCharacter as Character
     with self.assertRaises(IntegrityError):
         with transaction.manager:
             model = Character(name='Jet Black, Flying Soldier', played_by="John", fate_points=11, refresh_rate=11)
             DBSession.add(model)