Ejemplo n.º 1
0
def select_all():
    pokemons = []
    sql = "SELECT * FROM pokemons"
    results = run_sql(sql)
    for row in results:
        nurse = nurse_repository.select(row['nurse_id'])
        trainer = trainer_repository.select(row['trainer_id'])
        pokemon = Pokemon(row['nickname'], row['species'], row['type'],
                          row['dob'], trainer, row['status'], row['id'])
        pokemon.assign_nurse(nurse)
        pokemons.append(pokemon)
    return (pokemons)
Ejemplo n.º 2
0
def select(id):
    pokemon = None
    sql = "SELECT * FROM pokemons WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]

    if result is not None:
        nurse = nurse_repository.select(result['nurse_id'])
        trainer = trainer_repository.select(result['trainer_id'])
        pokemon = Pokemon(result['nickname'], result['species'],
                          result['type'], result['dob'], trainer,
                          result['status'], result['id'])
        pokemon.assign_nurse(nurse)
    return pokemon
Ejemplo n.º 3
0
def edit_pokemon(id):
    nickname = request.form['nickname']
    species = request.form['species']
    type = request.form['type']
    dob = request.form['dob']
    trainer_id = request.form['trainer_id']
    status = request.form['status']
    nurse_id = request.form['nurse_id']

    trainer = trainer_repository.select(trainer_id)
    nurse = nurse_repository.select(nurse_id)
    pokemon = Pokemon(nickname, species, type, dob, trainer, status, id)
    pokemon.assign_nurse(nurse)

    pokemon_repository.update(pokemon)
    return redirect('/pokemon')
Ejemplo n.º 4
0
def search(category, search):
    pokemons = []
    if category == "nickname":
        sql = "SELECT * FROM pokemons WHERE nickname = %s"
    elif category == "type":
        sql = "SELECT * FROM pokemons WHERE type = %s"
    elif category == "species":
        sql = "SELECT * FROM pokemons WHERE species = %s"
    elif category == "status":
        sql = "SELECT * FROM pokemons WHERE status = %s"
    values = [search]
    results = run_sql(sql, values)
    for row in results:
        nurse = nurse_repository.select(row['nurse_id'])
        trainer = trainer_repository.select(row['trainer_id'])
        pokemon = Pokemon(row['nickname'], row['species'], row['type'],
                          row['dob'], trainer, row['status'], row['id'])
        pokemon.assign_nurse(nurse)
        pokemons.append(pokemon)
    return pokemons
Ejemplo n.º 5
0
class TestPokemon(unittest.TestCase):
    def setUp(self):
        trainer = Trainer("Ash", 259)
        self.pokemon = Pokemon("Seed Backman", "Bulbasaur", "Grass",
                               "25/09/1990", trainer, 'burned')

    def test_pokemon_has_nickname(self):
        self.assertEqual("Seed Backman", self.pokemon.nickname)

    def test_pokemon_has_species(self):
        self.assertEqual("Bulbasaur", self.pokemon.species)

    def test_pokemon_has_type(self):
        self.assertEqual("Grass", self.pokemon.type)

    def test_pokemon_has_dob(self):
        self.assertEqual("25/09/1990", self.pokemon.dob)

    def test_pokemon_has_trainer_name(self):
        self.assertEqual("Ash", self.pokemon.trainer.name)

    def test_pokemon_has_trainer_number(self):
        self.assertEqual(259, self.pokemon.trainer.number)

    def test_pokemon_has_status(self):
        self.assertEqual('burned', self.pokemon.status)

    def test_pokemon_before_nurse(self):
        self.assertEqual(None, self.pokemon.nurse)

    def test_assign_nurse(self):
        nurse = Nurse('Joy', 'fire')
        self.pokemon.assign_nurse(nurse)
        self.assertEqual(nurse, self.pokemon.nurse)

    def test_get_nurse_name(self):
        nurse = Nurse('Joy', 'fire')
        self.pokemon.assign_nurse(nurse)
        self.assertEqual('Joy', self.pokemon.nurse.name)
Ejemplo n.º 6
0
from models.trainer import Trainer
import repositories.nurse_repository as nurse_repository
import repositories.pokemon_repository as pokemon_repository
import repositories.trainer_repository as trainer_repository

# pokemon_repository.delete_all()
# nurse_repository.delete_all()
# trainer_repository.delete_all()



nurse_1 = Nurse("Joy", "Fire")
nurse_repository.save(nurse_1)
trainer = Trainer("Simon", 12345)
trainer_repository.save(trainer)


pokemon = Pokemon('Seed Backman', 'Bulbasaur', 'Grass', '25/09/1990', trainer , 'burned')

pokemon.assign_nurse(nurse_1)
pokemon_repository.save(pokemon)

trainer.name = 'Simondovich'



trainer_repository.update(trainer)

nurse_1.name = "Betsy"

nurse_repository.update(nurse_1)
Ejemplo n.º 7
0
pokemon_repository.delete_all()
nurse_repository.delete_all()
# trainer_repository.delete_all()

# trainer_1 = Trainer('Ash', '2 Pallet Town', 32356)
# trainer_2 = Trainer('Misty', 'Cerulean Gym', 78232)
nurse_1 = Nurse('Joy')
nurse_2 = Nurse('Joye')
pokemon_1 = Pokemon('Sparky', 'trainer_1', 'Pikachu', '15/6/2017', nurse_1,
                    "Crushed by Snorlax")
pokemon_2 = Pokemon('Frankie', 'trainer_2', 'Psyduck', '12/1/2016', nurse_1,
                    "Burnt by Charizard")
pokemon_3 = Pokemon('Sally', 'trainer_2', 'Seel', '15/8/2015', nurse_2,
                    "Shocked by Pikachu")

#assign nurse to pokemon before running console.py

# trainer_repository.save(trainer_1)
# trainer_repository.save(trainer_2)
nurse_repository.save(nurse_1)
nurse_repository.save(nurse_2)

pokemon_repository.save(pokemon_1)
pokemon_repository.save(pokemon_2)
pokemon_repository.save(pokemon_3)

pokemon_1.assign_nurse(nurse_1)
pokemon_2.assign_nurse(nurse_2)
pokemon_3.assign_nurse(nurse_2)