Ejemplo n.º 1
0
def CreateGuild():
    json = request.json
    try:
        if 'nickname' in json:
            newGuild = Guild(json['name'], json['nickname'])
        else:
            newGuild = Guild(json['name'])
        db.session.add(newGuild)
        db.session.commit()
        data = jsonify(newGuild.to_dict())
        data.status_code = 201
        return data
    except IntegrityError as error:
        return Response(error.args[0], status=400)
Ejemplo n.º 2
0
 def test_create_success(self):
     guild = Guild('new')
     guild.id = 2
     response = self.create_guild(self.DEFAULT_TOKEN, 'new')
     self.assertEqual(response.status_code, 201)
     self.assertEqual(guild.to_dict(), response.get_json())