eba081958aa81d24496e78f5aa7f9f07e4e20597
[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 assert pkmn.names[lang] == name
40
41 @raises(KeyError)
42 def test_bad_lang(self):
43 q = self.connection.query(tables.Pokemon).filter(
44 tables.Pokemon.name == u"Mightyena")
45 pkmn = q.one()
46 pkmn.names["identifier of a language that doesn't exist"]
47
48 def test_mutating(self):
49 item = self.connection.query(tables.Item).filter_by(
50 identifier=u"jade-orb").one()
51 language = self.connection.query(tables.Language).filter_by(
52 identifier=u"de").one()
53 item.names['de'] = u"foo"
54 assert item.names['de'] == "foo"
55 assert item.names[language] == "foo"
56 item.names[language] = u"xyzzy"
57 assert item.names['de'] == "xyzzy"
58 assert item.names[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.names) == len(item.texts)
70 for lang in item.texts:
71 assert item.names[lang] == item.texts[lang].name
72 assert item.names[lang] == item.names[lang.identifier]
73 assert lang in item.names
74 assert lang.identifier in item.names
75 assert "language that doesn't exist" not in item.names
76 assert tables.Language() not in item.names
77
78 def test_new_language(self):
79 item = self.connection.query(tables.Item).filter_by(
80 identifier=u"jade-orb").one()
81 language = tables.Language()
82 language.id = -1
83 language.identifier = u'test'
84 language.iso639 = language.iso3166 = u'--'
85 language.official = False
86 self.connection.add(language)
87 item.names[u'test'] = u"foo"
88 assert item.names[language] == "foo"
89 assert item.names['test'] == "foo"
90 assert 'de' in item.names
91 assert language in item.names
92 item.names[language] = u"xyzzy"
93 assert item.names[language] == "xyzzy"
94 assert item.names['test'] == "xyzzy"
95
96 @raises(NotImplementedError)
97 def test_delstring(self):
98 item = self.connection.query(tables.Item).filter_by(
99 identifier=u"jade-orb").one()
100 del item.names['en']
101
102 def test_markdown(self):
103 move = self.connection.query(tables.Move).filter_by(
104 identifier=u"thunderbolt").one()
105 assert '10%' in move.effect.as_text
106 assert '10%' in move.effects['en'].as_text