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(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_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)
def test_dnd_campaign_combat_set_characters():
    chars = [Character() for _ in range(6)]
    for i in range(6):
        chars[i].id = i
    c = Combat()
    c.set_characters(chars)
    for i in range(6):
        assert c.characters[i] == (chars[i].id, chars[i].dexterity)
Example #5
0
 def test_random_character_is_valid(self):
     Char = Character()
     self.assertIn(Char.strength, range(3, 19))
     self.assertIn(Char.dexterity, range(3, 19))
     self.assertIn(Char.constitution, range(3, 19))
     self.assertIn(Char.intelligence, range(3, 19))
     self.assertIn(Char.wisdom, range(3, 19))
     self.assertIn(Char.charisma, range(3, 19))
     self.assertEqual(Char.hitpoints, 10 + modifier(Char.constitution))
 def test_random_character_is_valid(self):
     Char = Character()
     self.assertIs(Char.strength >= 3 and Char.strength <= 18, True)
     self.assertIs(Char.dexterity >= 3 and Char.dexterity <= 18, True)
     self.assertIs(Char.constitution >= 3 and Char.constitution <= 18, True)
     self.assertIs(Char.intelligence >= 3 and Char.intelligence <= 18, True)
     self.assertIs(Char.wisdom >= 3 and Char.wisdom <= 18, True)
     self.assertIs(Char.charisma >= 3 and Char.charisma <= 18, True)
     self.assertIs(Char.hitpoints == 10 + modifier(Char.constitution), True)
def combat():
    c = Combat()
    chars = [Character() for _ in range(6)]
    for i in range(6):
        chars[i].id = i
    npcs = [NPC.from_template(SRD_monsters["zombie"]) for _ in range(6)]
    for i in range(6):
        npcs[i].id = i
    c.set_npcs(npcs)
    c.set_characters(chars)
    yield c
Example #8
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))
Example #9
0
 def test_each_ability_is_only_calculated_once(self):
     Char = Character()
     self.assertEqual(Char.strength, Char.strength)
Example #10
0
 def test_random_ability_is_within_range(self):
     self.assertIn(Character().roll_dice(), range(3, 19))
 def test_each_ability_is_only_calculated_once(self):
     Char = Character()
     self.assertIs(Char.strength == Char.strength, True)
 def test_random_ability_is_within_range(self):
     score = Character().ability()
     self.assertIs(score >= 3 and score <= 18, True)
Example #13
0
 def character(self):
     """
     Return a real Character object using the data in this database row
     """
     i = 0
     return Character(**self.as_dict())
Example #14
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())