Move the rest of pokedex.util.get to pokedex.db.util
[zzz-pokedex.git] / pokedex / tests / test_util.py
1 # encoding: utf8
2 from nose.tools import *
3 import unittest
4
5 from pokedex.db import connect, tables, util
6 from pokedex.util import simple
7
8 session = connect()
9
10 def test_get_item_identifier():
11 item = util.get(session, tables.Item, identifier='master-ball')
12 assert item.name == 'Master Ball'
13
14 def test_get_item_name():
15 item = util.get(session, tables.Item, name='Awakening')
16 assert item.name == 'Awakening'
17
18 def test_get_english_by_identifier():
19 language = util.get(session, tables.Language, 'en')
20 assert language.name == 'English'
21
22 def test_get_pokemon_baseform_identifier():
23 for identifier in 'burmy shaymin unown cresselia'.split():
24 poke = util.get(session, tables.Pokemon, identifier=identifier)
25 assert poke.identifier == identifier
26 assert poke.is_base_form
27
28 def test_get_pokemon_baseform_name():
29 for name in 'Burmy Shaymin Unown Cresselia'.split():
30 poke = util.get(session, tables.Pokemon, name=name)
31 assert poke.name == name
32 assert poke.is_base_form
33
34 def test_get_pokemon_baseform_name_explicit_language():
35 french = util.get(session, tables.Language, 'fr')
36 for name in 'Cheniti Shaymin Zarbi Cresselia'.split():
37 poke = util.get(session, tables.Pokemon, name=name, language=french)
38 assert poke.name_map[french] == name, poke.name_map[french]
39 assert poke.is_base_form
40
41 def test_get_pokemon_other_form_identifier():
42 for ii in 'wormadam/trash shaymin/sky shaymin/land'.split():
43 pokemon_identifier, form_identifier = ii.split('/')
44 poke = util.get(session, tables.Pokemon, identifier=pokemon_identifier, form_identifier=form_identifier)
45 assert poke.identifier == pokemon_identifier
46 if poke.form.unique_pokemon_id:
47 assert poke.form.identifier == form_identifier
48
49 def test_types_french_order():
50 french = util.get(session, tables.Language, 'fr')
51 types = session.query(tables.Type).filter(tables.Type.id < 10000)
52 types = list(util.order_by_name(types, tables.Type, language=french))
53 assert types[0].name_map[french] == 'Acier', types[0].name_map[french]
54 assert types[-1].name_map[french] == 'Vol', types[-1].name_map[french]
55
56 def test_simple_pokemon():
57 pokemon = simple.pokemon(session)
58 assert pokemon[0].identifier == 'bulbasaur'
59 assert pokemon[-1].identifier == 'genesect'
60
61 def test_simple_types():
62 types = simple.types(session)
63 assert types[0].identifier == 'bug'
64 assert types[-1].identifier == 'water'
65
66 def test_simple_moves():
67 moves = simple.moves(session)
68 assert moves[0].identifier == 'absorb'
69 assert moves[-1].identifier == 'zen-headbutt'
70
71 def test_simple_items():
72 items = simple.items(session)
73 assert items[0].identifier == 'ability-urge'
74 assert items[-1].identifier == 'zoom-lens'
75