Exemple #1
0
 def get_dungeons_monster(id):
     if dungeon := Dungeon.find(id):
         response = {
             "level": dungeon.level,
             "Boss Level": dungeon.boss_level,
             "monsters": [m.long() for m in dungeon.monsters],
         }
         return jsonify(response)
Exemple #2
0
    def remove_dungeons_monster(id):
        payload = request.get_json()
        monster_id = payload.get("monster_id", None)

        if not monster_id:
            abort(400)

        if dungeon := Dungeon.find(id):
            if monster := Monster.find(monster_id):
                dungeon.monsters.remove(monster)
                dungeon.update()
    def setUp(self):
        """Define test variables and initialize app."""
        # binds the app to the current context
        self.app = create_app()
        setup_db(self.app)
        self.client = self.app.test_client
        self.headers = {
            "Authorization": "bearer " + os.environ["VALID_TEST_TOKEN"]
        }

        Monster(
            name="monster_name",
            race="monster_race",
            health_points="100",
            armor_points="100",
            attack_damage="100",
            xp_drop="100",
        ).insert()

        Dungeon(
            level="1",
            rooms="1",
            treasures="1",
            traps="1",
            boss_level=False,
            xp_drop="1000",
        ).insert()
Exemple #4
0
    def update_dungeon(id):
        payload = request.get_json()
        if not payload:
            abort(400)

        if dungeon := Dungeon.find(id):

            if level := payload.get("level", None):
                if checker := Dungeon.find_by(level):
                    if dungeon.id != checker.id:
                        abort(
                            Response(
                                response=
                                f"level id: {level} belongs to another dungeon.",
                                status=405,
                            ))
 def test_ok_delete_dungeon(self):
     dungeon = Dungeon.find_by(1)
     id = dungeon.id
     response = self.client().delete(
         f"/dungeons/{id}",
         headers=self.headers,
     )
     self.assertEqual(response.status_code, 200)
 def test_ok_add_monster_to_dungeon(self):
     monster = Monster.find_by("monster_name")
     monster_id = monster.id
     dungeon = Dungeon.find_by(1)
     dungeon_id = dungeon.id
     response = self.client().post(
         f"/dungeons/{dungeon_id}/monsters",
         headers=self.headers,
         json={"monster_id": monster_id},
     )
     self.assertEqual(response.status_code, 200)
 def test_ok_remove_monster_to_dungeon(self):
     monster = Monster.find_by("monster_name")
     monster_id = monster.id
     dungeon = Dungeon.find_by(1)
     dungeon_id = dungeon.id
     dungeon.monsters.append(monster)
     response = self.client().delete(
         f"/dungeons/{dungeon_id}/monsters",
         headers=self.headers,
         json={"monster_id": monster_id},
     )
     self.assertEqual(response.status_code, 200)
Exemple #8
0
    def add_dungeon():
        payload = request.get_json()
        if not payload:
            abort(400)

        level = payload.get("level", None)

        if Dungeon.find_by(level):
            abort(
                Response(
                    response=f"Dungeon level: {level} already created.",
                    status=405,
                ))

        level = payload.get("level", None)
        rooms = payload.get("rooms", None)
        treasures = payload.get("treasures", None)
        traps = payload.get("traps", None)
        boss_level = payload.get("boss_level", None)
        xp_drop = payload.get("xp_drop", None)

        dungeon = Dungeon(
            level=level,
            rooms=rooms,
            treasures=treasures,
            traps=traps,
            boss_level=boss_level,
            xp_drop=xp_drop,
        )
        dungeon.insert()
        return jsonify(dungeon.short())
 def test_ok_create_dungeon(self):
     payload = {
         "level": "2",
         "rooms": "1",
     }
     response = self.client().post(
         "/dungeons",
         headers=self.headers,
         json=payload,
     )
     self.assertEqual(response.status_code, 200)
     dungeon = Dungeon.find_by(2)
     dungeon.delete()
 def test_ok_update_dungeon(self):
     dungeon = Dungeon.find_by(1)
     id = dungeon.id
     payload = {
         "name": "dungeon_name",
         "attack_damage": "3",
         "xp_drop": "100",
     }
     response = self.client().patch(
         f"/dungeons/{id}",
         headers=self.headers,
         json=payload,
     )
     self.assertEqual(response.status_code, 200)
class DungeonMonstersTestCase(unittest.TestCase):
    """This class represents the DM test case"""
    @classmethod
    def setUp(self):
        """Define test variables and initialize app."""
        # binds the app to the current context
        self.app = create_app()
        setup_db(self.app)
        self.client = self.app.test_client
        self.headers = {
            "Authorization": "bearer " + os.environ["VALID_TEST_TOKEN"]
        }

        Monster(
            name="monster_name",
            race="monster_race",
            health_points="100",
            armor_points="100",
            attack_damage="100",
            xp_drop="100",
        ).insert()

        Dungeon(
            level="1",
            rooms="1",
            treasures="1",
            traps="1",
            boss_level=False,
            xp_drop="1000",
        ).insert()

    @classmethod
    def tearDown(cls):
        if monster := Monster.find_by("monster_name"):
            monster.delete()

        if dungeon := Dungeon.find_by(1):
            dungeon.delete()
Exemple #12
0
 def get_dungeon(id):
     if dungeon := Dungeon.find(id):
         result = {"success": True, "Dungeon": dungeon.long()}
         return jsonify(result)
Exemple #13
0
 def get_dungeons():
     if dungeons := Dungeon.all():
         result = {"success": True, "Dungeons": dungeons}
         return jsonify(result)
Exemple #14
0
 def remove_dungeon(id):
     if dungeon := Dungeon.find(id):
         level = dungeon.level
         dungeon.delete()
         result = {"success": True, "removed dungeon level": level}
         return jsonify(result)