0955ded1ecaa5bc4979ff75ce19ecb67f0d8903d
[zzz-pokedex.git] / pokedex / tests / test_strings.py
1 # Encoding: UTF-8
2
3 from nose.tools import *
4
5 from pokedex.db import tables, connect
6
7 class TestStrings(object):
8 def setup(self):
9 self.connection = connect()
10
11 def teardown(self):
12 self.connection.rollback()
13
14 def test_filter(self):
15 q = self.connection.query(tables.Pokemon).filter(
16 tables.Pokemon.name == u"Marowak")
17 assert q.one().identifier == 'marowak'
18
19 def test_gt(self):
20 # Assuming that the identifiers are just lowercase names
21 q1 = self.connection.query(tables.Pokemon).filter(
22 tables.Pokemon.name > u"Xatu").order_by(
23 tables.Pokemon.id)
24 q2 = self.connection.query(tables.Pokemon).filter(
25 tables.Pokemon.identifier > u"xatu").order_by(
26 tables.Pokemon.id)
27 assert q1.all() == q2.all()
28
29 def test_languages(self):
30 q = self.connection.query(tables.Pokemon).filter(
31 tables.Pokemon.name == u"Mightyena")
32 pkmn = q.one()
33 for lang, name in (
34 ('en', u'Mightyena'),
35 ('ja', u'グラエナ'),
36 ('roomaji', u'Guraena'),
37 ('fr', u'Grahyèna'),
38 ):
39 language = self.connection.query(tables.Language).filter_by(
40 identifier=lang).one()
41 assert pkmn.name_map[language] == name
42
43 @raises(KeyError)
44 def test_bad_lang(self):
45 q = self.connection.query(tables.Pokemon).filter(
46 tables.Pokemon.name == u"Mightyena")
47 pkmn = q.one()
48 pkmn.names["identifier of a language that doesn't exist"]
49
50 def test_mutating(self):
51 item = self.connection.query(tables.Item).filter_by(
52 identifier=u"jade-orb").one()
53 language = self.connection.query(tables.Language).filter_by(
54 identifier=u"de").one()
55 item.name_map[language] = u"foo"
56 assert item.name_map[language] == "foo"
57 item.name_map[language] = u"xyzzy"
58 assert item.name_map[language] == "xyzzy"
59
60 def test_mutating_default(self):
61 item = self.connection.query(tables.Item).filter_by(
62 identifier=u"jade-orb").one()
63 item.name = u"foo"
64 assert item.name == "foo"
65
66 def test_string_mapping(self):
67 item = self.connection.query(tables.Item).filter_by(
68 identifier=u"jade-orb").one()
69 assert len(item.name_map) == len(item.names)
70 for lang in item.names:
71 assert item.name_map[lang] == item.names[lang].name
72 assert lang in item.name_map
73 assert "language that doesn't exist" not in item.name_map
74 assert tables.Language() not in item.name_map
75
76 def test_new_language(self):
77 item = self.connection.query(tables.Item).filter_by(
78 identifier=u"jade-orb").one()
79 language = tables.Language()
80 language.id = -1
81 language.identifier = u'test'
82 language.iso639 = language.iso3166 = u'--'
83 language.official = False
84 self.connection.add(language)
85 item.name_map[language] = u"foo"
86 assert item.name_map[language] == "foo"
87 assert language in item.name_map
88 item.name_map[language] = u"xyzzy"
89 assert item.name_map[language] == "xyzzy"
90
91 @raises(AssertionError)
92 def test_delstring(self):
93 item = self.connection.query(tables.Item).filter_by(
94 identifier=u"jade-orb").one()
95 language = self.connection.query(tables.Language).filter_by(
96 identifier=u"en").one()
97 del item.name_map[language]
98 self.connection.commit()
99
100 def test_markdown(self):
101 move = self.connection.query(tables.Move).filter_by(
102 identifier=u"thunderbolt").one()
103 language = self.connection.query(tables.Language).filter_by(
104 identifier=u"en").one()
105 assert '10%' in move.effect.as_text
106 assert '10%' in move.effect_map[language].as_text