def test_character_creation_ht_in_constraint(database):
    with pytest.raises(IntegrityError) as excinfo:
        with database.transaction():
            # Create character with height in inches greater than 11
            character1 = Character.create(character_name='Qritz1',
                                          player_name='Avery',
                                          alignment='CG',
                                          race='elf',
                                          size='md',
                                          gender='male',
                                          age='29',
                                          height_ft='5',
                                          height_in='12',
                                          weight='109',
                                          hair_color='black',
                                          eye_color='brown')
    assert 'CHECK constraint failed: character' in str(excinfo.value)

    with pytest.raises(IntegrityError) as excinfo:
        with database.transaction():
            # Create character with height in inches greater less than 0
            character2 = Character.create(character_name='Qritz2',
                                          player_name='Avery',
                                          alignment='CG',
                                          race='elf',
                                          size='md',
                                          gender='male',
                                          age='29',
                                          height_ft='5',
                                          height_in='-1',
                                          weight='109',
                                          hair_color='black',
                                          eye_color='brown')
    assert 'CHECK constraint failed: character' in str(excinfo.value)
Exemple #2
0
    def add():
        '''
        Description :
            Create a new Character with Hat associate, following the rules
        Example :
            >>> request.post(/create?Name=Alain&Age=18&Weight=80
            /   &Human=True&Color=YELLOW)

        '''

        from rules import Character_rules

        character_schema = CharacterSchema()

        Name=request.args.get('Name')
        Age=request.args.get('Age')
        Weight=request.args.get('Weight')
        Human= json.loads(request.args.get('Human').lower())

        if 'Color' in request.args:
            from models import ColorHat, Hat

            Color = request.args.get('Color')
            hat = Hat(Color = Color)
            hat_schema = HatSchema()
            params = {
                'Name' : Name,
                'Age' : Age,
                'Weight' : Weight ,
                'Human' : Human,
                'Hat' : hat
            }
            
            #hat = hat_schema.load({'Color' : Color})
            result_hat = hat_schema.dump(hat.create())

        else:
            params = {
                'Name' : Name,
                'Age' : Age,
                'Weight' : Weight ,
                'Human' : Human,
                'Hat': None
            }
        #Check all the rules
        message = [rule(params) for k,rule in Character_rules.items() ]
        for b, m  in message :
            if not(b):
                return make_response(m,401)
        try:
            #character = character_schema.load(params)
            character = Character(**params)
            result_character = character_schema.dump(character.create())
            return make_response(jsonify({'character': result_character}),200)

        except Exception as e:
            raise str(e) 
Exemple #3
0
def createCharacter(request):
  if request.method == 'POST':
    form = CharacterForm(request.POST)
    if form.is_valid():
      data = form.cleaned_data
      character = Character.create(data['gameSystem'], data['name'])
      return HttpResponseRedirect(reverse(charSheet, kwargs = {'charId': character.id}))
  else:
    form = CharacterForm()

  return render(request, 'createCharacter.html', {'form': form})
def test_character_creation_age_constraint(database):
    with database.transaction():
        character = Character.create(character_name='Qritz',
                                     player_name='Avery',
                                     alignment='CG',
                                     race='elf',
                                     size='md',
                                     gender='male',
                                     age='0',
                                     height_ft='5',
                                     height_in='4',
                                     weight='109',
                                     hair_color='black',
                                     eye_color='brown')
def test_character_creation(database):
    with database.transaction():
        character = Character.create(character_name='Qritz',
                                     player_name='Avery',
                                     alignment='CG',
                                     race='elf',
                                     size='md',
                                     gender='male',
                                     age='29',
                                     height_ft='5',
                                     height_in='4',
                                     weight='109',
                                     hair_color='black',
                                     eye_color='brown')
    from_db = Character.get(Character.character_name == 'Qritz')
    assert from_db == character
    assert Character.select().count() == 1