def test_creation_from_db(): db = Database() db.create_table( 'cards', { 'id': integer(primary_key=True), 'name': text(), 'atk': integer(), 'def': integer()}) Card = Item.from_table('Card', db.cards, exclude=['id']) assert all(hasattr(Card, attr) for attr in ('atk', 'def', 'name'))
def test_creation_from_db(self): db = Database('sqlite:///:memory:') db.create_table('cards', OrderedDict( id = integer(primary_key=True), name = string(), atk = integer(), def_ = integer() )) Card = Item.from_table('Card', db.cards, exclude=['id']) self.assertEqual(Card.ATTRIBUTES, ('atk', 'def', 'name'))
def test_creation_from_db(): db = Database() db.create_table( 'cards', { 'id': integer(primary_key=True), 'name': text(), 'atk': integer(), 'def': integer() }) Card = Item.from_table('Card', db.cards, exclude=['id']) assert all(hasattr(Card, attr) for attr in ('atk', 'def', 'name'))
def db(request): db = Database('wtactics.db') def fin(): os.remove(db.location) request.addfinalizer(fin) return db
class TestSQLiteDatabase(unittest.TestCase): def setUp(self): self.db = Database('sqlite:///:memory:') self.test_table_creation() def test_table_creation(self): self.db.create_table('cards', OrderedDict( id = integer(primary_key=True), name = string(), def_ = integer(), atk = integer() )) column_names = [column.name for column in self.db.cards.columns] self.assertIn('cards', self.db.tables) self.assertEqual(sorted(column_names), ['atk', 'def', 'id', 'name']) def test_simple_table_selection(self): self.test_record_creation() result = self.db.select('cards') self.assertIsNotNone(result) def test_record_creation(self): result = self.db.create_record('cards', dict( name = 'Imp', atk = 2, def_ = 2 )) self.assertIsNotNone(result) def test_table_dropping(self): self.db.drop_table('cards') self.assertNotIn('cards', self.db.tables) with self.assertRaises(AttributeError): self.db.drop_table('cards')
def setUp(self): self.db = Database('sqlite:///:memory:') self.test_table_creation()
""" WTactics Plugin Prototype This module is an example of how to write a rules plugin for ViCE. Currently, it is contained within a single file. However, as plugins are really just python files, the different bits could be extracted into separate modules (actions, containers, items, etc) and packaged as a single python package. """ from vice.plugins import Item, Container, Action from vice.database import Database # opens a local db file db = Database('sqlite:///wtactics.db') # Items Item.from_table('Card', db.cards, exclude=('border_color', 'footer')) Item.new( # target is which card it is placed on 'Token', attributes=('owner', 'type_', 'target')) # Containers Zone = Container.new('Zone', lambda cls, item: [item.NAME == 'Card']) for zone in 'Questing', 'Offensive', 'Defensive': Zone.new( '{0}Zone'.format(zone), lambda cls, item: Zone.constraints(cls, item) + [zone.lower() in item.types]) HeroZone = Zone.new(