2011-05-02 07:20:28 +00:00
|
|
|
# Encoding: utf8
|
2011-04-14 14:42:35 +00:00
|
|
|
|
2011-05-02 07:20:28 +00:00
|
|
|
import pytest
|
2014-07-07 03:25:04 +00:00
|
|
|
parametrize = pytest.mark.parametrize
|
2011-05-02 07:20:28 +00:00
|
|
|
|
2011-04-14 17:08:05 +00:00
|
|
|
from pokedex.db import connect, tables, util
|
2011-04-14 14:42:35 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_get_item_identifier(session):
|
2011-04-14 17:08:05 +00:00
|
|
|
item = util.get(session, tables.Item, identifier='master-ball')
|
2011-04-14 14:42:35 +00:00
|
|
|
assert item.name == 'Master Ball'
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_get_item_name(session):
|
2011-04-14 17:08:05 +00:00
|
|
|
item = util.get(session, tables.Item, name='Awakening')
|
2011-04-14 14:42:35 +00:00
|
|
|
assert item.name == 'Awakening'
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_get_english_by_identifier(session):
|
2011-04-14 17:08:05 +00:00
|
|
|
language = util.get(session, tables.Language, 'en')
|
2011-04-14 14:42:35 +00:00
|
|
|
assert language.name == 'English'
|
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@parametrize('identifier', ['burmy', 'shaymin', 'unown', 'cresselia'])
|
|
|
|
def test_get_pokemon_identifier(session, identifier):
|
2011-05-02 07:20:28 +00:00
|
|
|
poke = util.get(session, tables.PokemonSpecies, identifier=identifier)
|
|
|
|
assert poke.identifier == identifier
|
2011-04-14 14:42:35 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@parametrize('name', ['Burmy', 'Shaymin', 'Unown', 'Cresselia'])
|
|
|
|
def test_get_pokemon_name(session, name):
|
2011-05-02 07:20:28 +00:00
|
|
|
poke = util.get(session, tables.PokemonSpecies, name=name)
|
|
|
|
assert poke.name == name
|
2011-04-14 14:42:35 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@parametrize('name', ['Cheniti', 'Shaymin', 'Zarbi', 'Cresselia'])
|
|
|
|
def test_get_pokemon_name_explicit_language(session, name):
|
2011-04-14 17:08:05 +00:00
|
|
|
french = util.get(session, tables.Language, 'fr')
|
2011-05-02 07:20:28 +00:00
|
|
|
poke = util.get(session, tables.PokemonSpecies, name=name, language=french)
|
|
|
|
assert poke.name_map[french] == name, poke.name_map[french]
|
2011-04-14 14:42:35 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
def test_types_french_order(session):
|
2011-04-14 17:08:05 +00:00
|
|
|
french = util.get(session, tables.Language, 'fr')
|
2011-04-14 16:24:30 +00:00
|
|
|
types = session.query(tables.Type).filter(tables.Type.id < 10000)
|
2011-04-14 17:08:05 +00:00
|
|
|
types = list(util.order_by_name(types, tables.Type, language=french))
|
2011-04-14 14:42:35 +00:00
|
|
|
assert types[0].name_map[french] == 'Acier', types[0].name_map[french]
|
2015-05-29 02:43:31 +00:00
|
|
|
# SQLite doesn't know how to sort unicode properly, so accented charaters come last.
|
|
|
|
# Postgres doesn't have this problem.
|
|
|
|
assert types[-1].name_map[french] in (u'Électrik', u'Vol'), types[-1].name_map[french]
|
2011-05-02 07:20:28 +00:00
|
|
|
|
2014-07-07 03:25:04 +00:00
|
|
|
@parametrize('id', range(1, 10))
|
|
|
|
def test_get_pokemon_id(session, id):
|
2011-05-02 07:20:28 +00:00
|
|
|
result = util.get(session, tables.Pokemon, id=id)
|
|
|
|
assert result.id == id
|
|
|
|
assert result.__tablename__ == 'pokemon'
|