def test_character_mutation(client):
    thor = Character(name="thor")
    db_thor = GameCharacter(
        user_id=1,
        name=thor.name,
        data_keys=str(thor.keys()),
        data_vals=str(thor.values()),
    )
    db.session.add(db_thor)
    db.session.commit()
    new_thor = GameCharacter.query.first()
    assert new_thor.as_dict() == dict(thor)
def test_character_mutation_with_class(client):
    thor = Character(name="thor", classs=CLASSES["fighter"])
    db_thor = GameCharacter(
        user_id=1,
        name=thor.name,
        data_keys=str(thor.keys()),
        data_vals=str(thor.values()),
    )
    db.session.add(db_thor)
    db.session.commit()
    new_thor = GameCharacter.query.first()
    assert new_thor.as_dict() == dict(new_thor.character) == dict(thor)
def test_character_mutation_with_experience(client):
    thor = Character(name="thor", experience=255)
    db_thor = GameCharacter(
        user_id=1,
        name=thor.name,
        data_keys=str(thor.keys()),
        data_vals=str(thor.values()),
    )
    db.session.add(db_thor)
    db.session.commit()
    new_thor = GameCharacter.query.first()
    new_thor_character = new_thor.character

    assert (thor.experience.to_next_level ==
            new_thor_character.experience.to_next_level == 45)
예제 #4
0
def create_character_chosen(class_key):
    if class_key not in CLASSES:
        abort(400)
    new_char = Character(
        classs=CLASSES[class_key],
        name="New Character",
        age="Unknown",
        gender="Unknown",
        alignment="LG",
        description="A human",
        biography="",
    )
    db_char = GameCharacter(
        user_id=int(flask_login.current_user.get_id()),
        name=new_char.name,
        data_keys=str(new_char.keys()),
        data_vals=str(new_char.values()),
    )
    db.session.add(db_char)
    db.session.commit()
    edit_character(character_id=db_char.id, selected_field=None, autosubmit=True)
    return redirect(url_for(".edit_character", character_id=db_char.id))
예제 #5
0
 def update_data(self, data):
     # remove armour class so it will be recalculated properly
     del data["armour_class"]
     new = Character(**data)
     self.data_keys = str(new.keys())
     self.data_vals = str(new.values())