2024-03-24 16:56:13 -07:00
|
|
|
from ttfrog.db import schema
|
|
|
|
|
|
|
|
|
|
|
|
def test_create_character(db, classes, ancestries):
|
|
|
|
with db.transaction():
|
2024-03-26 00:53:21 -07:00
|
|
|
darkvision = db.session.query(schema.AncestryTrait).filter_by(name="Darkvision")[0]
|
2024-03-24 16:56:13 -07:00
|
|
|
|
|
|
|
# create a human character (the default)
|
2024-03-26 00:53:21 -07:00
|
|
|
char = schema.Character(name="Test Character")
|
2024-03-24 16:56:13 -07:00
|
|
|
db.add(char)
|
|
|
|
assert char.id == 1
|
|
|
|
assert char.armor_class == 10
|
2024-03-26 00:53:21 -07:00
|
|
|
assert char.name == "Test Character"
|
|
|
|
assert char.ancestry.name == "human"
|
2024-03-24 16:56:13 -07:00
|
|
|
assert darkvision not in char.traits
|
|
|
|
|
|
|
|
# switch ancestry to tiefling
|
2024-03-26 00:53:21 -07:00
|
|
|
char.ancestry = ancestries["tiefling"]
|
2024-03-24 16:56:13 -07:00
|
|
|
db.add(char)
|
|
|
|
char = db.session.get(schema.Character, 1)
|
2024-03-26 00:53:21 -07:00
|
|
|
assert char.ancestry.name == "tiefling"
|
2024-03-24 16:56:13 -07:00
|
|
|
assert darkvision in char.traits
|
|
|
|
|
|
|
|
# assign a class and level
|
2024-03-26 00:53:21 -07:00
|
|
|
char.add_class(classes["fighter"], level=1)
|
2024-03-24 16:56:13 -07:00
|
|
|
db.add(char)
|
2024-03-26 00:53:21 -07:00
|
|
|
assert char.levels == {"fighter": 1}
|
2024-03-24 16:56:13 -07:00
|
|
|
assert char.level == 1
|
|
|
|
assert char.class_attributes == []
|
|
|
|
|
|
|
|
# level up
|
2024-03-26 00:53:21 -07:00
|
|
|
char.add_class(classes["fighter"], level=2)
|
2024-03-24 16:56:13 -07:00
|
|
|
db.add(char)
|
2024-03-26 00:53:21 -07:00
|
|
|
assert char.levels == {"fighter": 2}
|
2024-03-24 16:56:13 -07:00
|
|
|
assert char.level == 2
|
|
|
|
assert char.class_attributes == []
|
|
|
|
|
|
|
|
# multiclass
|
2024-03-26 00:53:21 -07:00
|
|
|
char.add_class(classes["rogue"], level=1)
|
2024-03-24 16:56:13 -07:00
|
|
|
db.add(char)
|
|
|
|
assert char.level == 3
|
2024-03-26 00:53:21 -07:00
|
|
|
assert char.levels == {"fighter": 2, "rogue": 1}
|
2024-03-24 16:56:13 -07:00
|
|
|
|
|
|
|
# remove a class
|
2024-03-26 00:53:21 -07:00
|
|
|
char.remove_class(classes["rogue"])
|
2024-03-24 16:56:13 -07:00
|
|
|
db.add(char)
|
2024-03-26 00:53:21 -07:00
|
|
|
assert char.levels == {"fighter": 2}
|
2024-03-24 16:56:13 -07:00
|
|
|
assert char.level == 2
|
|
|
|
|
|
|
|
# remove all remaining classes
|
2024-03-26 00:53:21 -07:00
|
|
|
char.remove_class(classes["fighter"])
|
2024-03-24 16:56:13 -07:00
|
|
|
db.add(char)
|
|
|
|
|
|
|
|
# ensure we're not persisting any orphan records in the map table
|
|
|
|
dump = db.dump()
|
2024-03-26 00:53:21 -07:00
|
|
|
assert dump["class_map"] == []
|