class SlrPrepATests(TestCase): """Tests for _prep_a()""" def setUp(self): self.testrepo = SQLiteRepo() self.chardict = self.testrepo.special_chars def test_prep_a_special_chars_forbidden(self): """Handle forbidden characters in relation names or anchor content. """ ins = ("".join((self.chardict["E"], x, self.chardict["WC"])) for x in self.chardict["F"]) outs = ("".join((self.chardict["E"], escape(x), self.chardict["WC"])) for x in self.chardict["F"]) for term, expected in zip(ins, outs): with self.subTest(term=term): self.assertEqual(self.testrepo._prep_a(term, wildcards=False), expected) def test_prep_a_special_characters_prefix(self): """Handle prefix characters in relation names or anchor content. """ ins = ("".join((x, self.chardict["E"], self.chardict["WC"])) for x in self.chardict["PX"]) outs = ("".join((escape(x), self.chardict["E"], self.chardict["WC"])) for x in self.chardict["PX"]) for term, expected in zip(ins, outs): with self.subTest(term=term): self.assertEqual(self.testrepo._prep_a(term, wildcards=False), expected)
class SlrPrepTermTests(TestCase): """Tests for _prep_term()""" def setUp(self): self.testrepo = SQLiteRepo() self.escape = self.testrepo.CHAR_ESCAPE self.alias = self.testrepo._char_alias def test_prep_term_alias(self): """Handle ROWID aliases""" val = 9001 term = "{}{}".format(self.alias, val) self.assertEqual(self.testrepo._prep_a(term), val) def test_prep_term_wildcards(self): """Conversion of TAGS wildcards to SQL wildcards""" args_outs = ( { 'args': { 'a': '*ananas' }, 'out': '%ananas' }, { 'args': { 'a': 'ana*nas' }, 'out': 'ana%nas' }, { 'args': { 'a': 'ananas*' }, 'out': 'ananas%' }, { 'args': { 'a': 'a??na' }, 'out': 'a__na' }, { 'args': { 'a': '100%an_a' }, 'out': '100{0}%an{0}_a'.format(self.escape) }, { 'args': { 'a': '100%an_a' }, 'out': '100{0}%an{0}_a'.format(self.escape) }, ) for a in args_outs: with self.subTest(term=a['args']): self.assertEqual(self.testrepo._prep_a(**a['args']), a['out'])