julen / pootle

Web-based translation and translation management tool

pootle / test_indexing.py
100644 33 lines (28 sloc) 1.455 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding: utf-8 -*-
from Pootle import pootle
from Pootle import pootlefile
 
def setup_module(module):
    """initialize global variables in the module"""
    parser = pootle.PootleOptionParser()
    options, args = parser.parse_args(["--servertype=dummy"])
    module.server = parser.getserver(options)
    # shortcuts to make tests easier
    module.potree = module.server.potree
 
def test_init():
    """tests that the index can be initialized"""
    for languagecode, languagename in potree.getlanguages("pootle"):
       translationproject = potree.getproject(languagecode, "pootle")
       assert hasattr(translationproject, "indexdir")
 
def test_search():
    """tests that the index can be initialized"""
    pass_search = pootlefile.Search(searchtext="login")
    fail_search = pootlefile.Search(searchtext="Zrogny")
    for languagecode, languagename in potree.getlanguages("pootle"):
       translationproject = potree.getproject(languagecode, "pootle")
       print translationproject.indexdir
       pass_search_results = translationproject.searchpoitems("pootle.po", -1, pass_search)
       pass_search_results = [(pofilename, item) for pofilename, item in pass_search_results]
       assert pass_search_results
       fail_search_results = translationproject.searchpoitems("pootle.po", -1, fail_search)
       fail_search_results = [(pofilename, item) for pofilename, item in fail_search_results]
       assert not fail_search_results