def test_make_terms(self): result = make_terms(["foo", "bar", "baz"]) for term in result: assert isinstance(term, SimpleTerm) assert len(result) == 3 term_strings = [(x.title, x.token, x.value) for x in result] self.assertEqual(term_strings, [(u"foo", "Zm9v", u"foo"), (u"bar", "YmFy", u"bar"), (u"baz", "YmF6", u"baz")])
def test_make_terms_umlauts(self): result = make_terms(["ümläut", "ömläut"]) term_strings = [(x.title, x.token, x.value) for x in result] self.assertEqual( term_strings, [(u"\xfcml\xe4ut", "w7xtbMOkdXQ=", u"\xfcml\xe4ut"), (u"\xf6ml\xe4ut", "w7ZtbMOkdXQ=", u"\xf6ml\xe4ut")], )
def __call__(self, context): if self.vocab is not None: return self.vocab util = queryUtility(IExternalVocabConfig, name=self.name) if util is None: return SimpleVocabulary.fromValues([]) path = util.get('path', None) if not path or not os.path.isfile(path): return SimpleVocabulary.fromValues([]) self.vocab = SimpleVocabulary( make_terms([line.strip() for line in open(path, 'r')])) return self.vocab
def test_make_terms_ignore_empty(self): # emtpy strings are ignored when creating terms result = make_terms(["", "foo", "", "bar", ""]) term_strings = [(x.title, x.token, x.value) for x in result] self.assertEqual(term_strings, [(u"foo", "Zm9v", u"foo"), (u"bar", "YmFy", u"bar")])