julen / pootle

Web-based translation and translation management tool

This URL has Read+Write access

pootle / test_client.py
100644 485 lines (438 sloc) 27.864 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
#!/usr/bin/env python
 
"""Top-level tests using urllib2 to check interaction with servers
This uses test_cmdlineserver / test_service / test_apache (which are for different webservers)
ServerTester is mixed in with the different server tests below to generate the required tests"""
 
from Pootle import test_create
from Pootle import test_cmdlineserver
from Pootle import potree
from Pootle import projects
from jToolkit.web import postMultipart
import zipfile
from translate.misc import wStringIO
import urllib
import urllib2
import os
import re
 
try:
    import cookielib
except ImportError:
    # fallback for python before 2.4
    cookielib = None
    import ClientCookie
 
class ServerTester:
    """Tests things directly against the socket of the server. Requires self.baseaddress"""
    setup_class = test_create.TestCreate.setup_class
 
    def setup_cookies(self):
        """handle cookies etc"""
        if cookielib:
            self.cookiejar = cookielib.CookieJar()
            self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookiejar))
            self.urlopen = self.opener.open
        else:
            self.urlopen = ClientCookie.urlopen
 
    def setup_prefs(self, method):
        """sets up any extra preferences required..."""
        if hasattr(method, "userprefs"):
            for key, value in method.userprefs.iteritems():
                self.prefs.setvalue("Pootle.users.testuser." + key, value)
 
    def fetch_page(self, relative_url):
        """Fetches a page from the webserver installed in the service"""
        url = "%s/%s" % (self.baseaddress, relative_url)
        print "fetching", url
        stream = self.urlopen(url)
        contents = stream.read()
        return contents
 
    def post_request(self, relative_url, contents, headers):
        """Posts a request to the webserver installed in the service"""
        url = "%s/%s" % (self.baseaddress, relative_url)
        print "posting to", url
        post_request = urllib2.Request(url, contents, headers)
        stream = self.urlopen(post_request)
        response = stream.read()
        return response
 
    def login(self):
        """calls the login method with username and password"""
        return self.fetch_page("?islogin=1&username=testuser&password=")
 
    def test_login(self):
        """checks that login works and sets cookies"""
        contents = self.login()
        # check login leads us to a normal page
        assert "Log In" not in contents
        # check login is retained on next fetch
        contents = self.fetch_page("")
        assert "Log In" not in contents
 
    def test_non_admin_rights(self):
        """checks that without admin rights we can't access the admin screen"""
        contents = self.login()
        adminlink = '<a href="/admin/">Admin</a>' in contents
        assert not adminlink
        contents = self.fetch_page("admin/")
        denied = "You do not have the rights to administer pootle" in contents
        assert denied
 
    def test_admin_rights(self):
        """checks that admin rights work properly"""
        contents = self.login()
        adminlink = '<a href="/admin/">Admin</a>' in contents
        assert adminlink
        contents = self.fetch_page("admin/")
        admintitle = "<title>Pootle Admin Page</title>" in contents
        assert admintitle
    test_admin_rights.userprefs = {"rights.siteadmin": True}
 
    def test_add_project(self):
        """checks that we can add a project successfully"""
        self.login()
        projects_list = self.fetch_page("admin/projects.html")
        testproject_present = '<a href="../projects/testproject/admin.html">testproject</a>' in projects_list
        assert testproject_present
        testproject2_present = '<a href="../projects/testproject2/admin.html">testproject2</a>' in projects_list
        assert not testproject2_present
        assert projects_list.count(""""selected" value="po""") == 1
        add_dict = {"newprojectcode": "testproject2", "newprojectname": "Test Project 2",
            "newprojectdescription": "Test Project Addition","newprojectfiletype": "xliff", "changeprojects": "Save changes"}
        add_args = "&".join(["%s=%s" % (key, urllib.quote_plus(value)) for key, value in add_dict.items()])
        add_url = "admin/projects.html?" + add_args
        add_result = self.fetch_page(add_url)
        testproject2_present = '<a href="../projects/testproject2/admin.html">testproject2</a>' in add_result
        assert testproject2_present
        projects_list = self.fetch_page("admin/projects.html")
        # The asserts below may fail if output framework changes, html checking does not checking the 'selected' value,
        # but instead relying on the projected 'value' in the project's name
        assert """projectfiletype-testproject" value="po">""" in projects_list
        assert """projectfiletype-testproject2" value="xliff">""" in projects_list
    test_add_project.userprefs = {"rights.siteadmin": True}
 
    def test_add_project_language(self):
        """tests that we can add a language to a project, then access its page when there are no files"""
        self.login()
        language_list = self.fetch_page("projects/testproject/")
        assert "Test Language" not in language_list
        assert "Pootle Unit Tests" in language_list
        project_admin = self.fetch_page("projects/testproject/admin.html")
        assert '<option value="zxx">Test Language: zxx</option>' in project_admin
        add_dict = {"newlanguage": "zxx", "doaddlanguage": "Add Language"}
        add_args = "&".join(["%s=%s" % (key, urllib.quote_plus(value)) for key, value in add_dict.items()])
        add_language = self.fetch_page("projects/testproject/admin.html?" + add_args)
        assert "Test Language" in add_language
        language_page = self.fetch_page("zxx/testproject/")
        assert "Test Language" in language_page
        assert "Pootle Unit Tests" in language_page
        assert "0 files, 0/0 words (0%) translated" in language_page
    test_add_project_language.userprefs = {"rights.siteadmin": True}
 
    def setup_testproject_dir(self, perms=None):
        """Sets up a blank test project directory"""
        projectname = "testproject"
        lang = "zxx"
        projectdir = os.path.join(self.podir, projectname)
        os.mkdir(projectdir)
        podir = os.path.join(projectdir, lang)
        os.mkdir(podir)
if perms:
            prefsfile = file(os.path.join(projectdir, lang, "pootle-%s-%s.prefs" % (projectname, lang)), 'w')
            prefsfile.write("# Prefs file for Pootle unit tests\nrights:\n testuser = '%s'\n" % perms)
            prefsfile.close()
        language_page = self.fetch_page("%s/%s/" % (lang, projectname))
 
        assert "Test Language" in language_page
        assert "Pootle Unit Tests" in language_page
        assert "0 files, 0/0 words (0%) translated" in language_page
        return podir
 
    def test_upload_new_file(self):
        """tests that we can upload a new file into a project"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate, admin")
        fields = [("doupload", "Upload File")]
        pocontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
        files = [("uploadfile", "test_upload.po", pocontents)]
        content_type, upload_contents = postMultipart.encode_multipart_formdata(fields, files)
        headers = {"Content-Type": content_type, "Content-Length": len(upload_contents)}
        response = self.post_request("zxx/testproject/", upload_contents, headers)
        assert ' href="test_upload.po?' in response
        pofile_storename = os.path.join(podir, "test_upload.po")
        assert os.path.isfile(pofile_storename)
        assert open(pofile_storename).read() == pocontents
        pocontents_download = self.fetch_page("zxx/testproject/test_upload.po")
        assert pocontents_download == pocontents
 
    def test_upload_new_xlifffile(self):
        """tests that we can upload a new xliff file into a project"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate, admin")
        fields = [("doupload", "Upload File")]
        xliffcontents = '''<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1"><file datatype="po" original="test_upload.po" source-language="en-US"><body><trans-unit id="1" xml:space="preserve"><source>test</source><target state="translated">rest</target><context-group name="po-reference" purpose="location"><context context-type="sourcefile">test.c</context></context-group></trans-unit></body></file></xliff>'''
        pocontents_expected = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
        files = [("uploadfile", "test_upload.xlf", xliffcontents)]
        content_type, upload_contents = postMultipart.encode_multipart_formdata(fields, files)
        headers = {"Content-Type": content_type, "Content-Length": len(upload_contents)}
        response = self.post_request("zxx/testproject/", upload_contents, headers)
        assert ' href="test_upload.po?' in response
        pofile_storename = os.path.join(podir, "test_upload.po")
        assert os.path.isfile(pofile_storename)
        assert open(pofile_storename).read() == xliffcontents
        # Well, since it is a new file, it actually now is an xliff file...
# pocontents_download = self.fetch_page("zxx/testproject/test_upload.po")
# assert pocontents_download == pocontents_expected
 
    def test_upload_suggestions(self):
        """tests that we can upload when we only have suggest rights"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, suggest")
 
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        po1contents = '#: test.c\nmsgid "test"\nmsgstr ""\n'
        open(os.path.join(podir, "test_upload.po"), "w").write(po1contents)
 
        fields = [("doupload", "Upload File")]
        pocontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
        files = [("uploadfile", "test_upload.po", pocontents)]
        content_type, upload_contents = postMultipart.encode_multipart_formdata(fields, files)
        headers = {"Content-Type": content_type, "Content-Length": len(upload_contents)}
        response = self.post_request("zxx/testproject/", upload_contents, headers)
        assert ' href="test_upload.po?' in response
        # Check that the orignal file didn't take the new suggestion.
        # We test with 'in' since the header is added
        assert po1contents in self.fetch_page("zxx/testproject/test_upload.po")
        suggestions_content = open(os.path.join(podir, "test_upload.po.pending"), 'r').read()
        assert 'msgstr "rest"' in suggestions_content
    test_upload_suggestions.userprefs = {"rights.siteadmin": False}
 
    def test_upload_overwrite(self):
        """tests that we can overwrite a file in a project"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate, overwrite")
 
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        po1contents = '#: test.c\nmsgid "test"\nmsgstr ""\n'
        open(os.path.join(podir, "test_upload.po"), "w").write(po1contents)
 
        fields = [("doupload", "Upload File"),("dooverwrite", "No")]
        pocontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
        files = [("uploadfile", "test_upload.po", pocontents)]
        content_type, upload_contents = postMultipart.encode_multipart_formdata(fields, files)
        headers = {"Content-Type": content_type, "Content-Length": len(upload_contents)}
        response = self.post_request("zxx/testproject/", upload_contents, headers)
        assert ' href="test_upload.po?' in response
        # Now we only test with 'in' since the header is added
        assert pocontents in self.fetch_page("zxx/testproject/test_upload.po")
        firstpofile = self.fetch_page("zxx/testproject/test_upload.po")
 
        fields = [("doupload", "Upload File"),("dooverwrite", "Yes")]
        pocontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n#: test.c\nmsgid "azoozoo"\nmsgstr ""'
        files = [("uploadfile", "test_upload.po", pocontents)]
        content_type, upload_contents = postMultipart.encode_multipart_formdata(fields, files)
        headers = {"Content-Type": content_type, "Content-Length": len(upload_contents)}
        response = self.post_request("zxx/testproject/", upload_contents, headers)
        assert pocontents == self.fetch_page("zxx/testproject/test_upload.po")
 
    def test_upload_new_archive(self):
        """tests that we can upload a new archive of files into a project"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate, admin")
        fields = [("doupload", "Upload File")]
        po1contents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
        po2contents = '#: frog.c\nmsgid "tadpole"\nmsgstr "fish"\n'
        archivefile = wStringIO.StringIO()
        archive = zipfile.ZipFile(archivefile, "w", zipfile.ZIP_DEFLATED)
        archive.writestr("test.po", po1contents)
        archive.writestr("frog.po", po2contents)
        archive.close()
        files = [("uploadfile", "upload.zip", archivefile.getvalue())]
        content_type, upload_contents = postMultipart.encode_multipart_formdata(fields, files)
        headers = {"Content-Type": content_type, "Content-Length": len(upload_contents)}
        response = self.post_request("zxx/testproject/", upload_contents, headers)
        for filename, contents in [("test.po", po1contents), ("frog.po", po2contents)]:
            assert (' href="%s?' % filename) in response
            pofile_storename = os.path.join(podir, filename)
            assert os.path.isfile(pofile_storename)
            assert open(pofile_storename).read() == contents
            pocontents_download = self.fetch_page("zxx/testproject/%s" % filename)
            assert pocontents_download == contents
 
    def test_upload_over_file(self):
        """tests that we can upload a new version of a file into a project"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate")
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        po1contents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n\n#: frog.c\nmsgid "tadpole"\nmsgstr "fish"\n'
        open(os.path.join(podir, "test_existing.po"), "w").write(po1contents)
        po2contents = '#: test.c\nmsgid "test"\nmsgstr "rested"\n\n#: toad.c\nmsgid "slink"\nmsgstr "stink"\n'
        fields = [("doupload", "Upload File")]
        files = [("uploadfile", "test_existing.po", po2contents)]
        content_type, upload_contents = postMultipart.encode_multipart_formdata(fields, files)
        headers = {"Content-Type": content_type, "Content-Length": len(upload_contents)}
        response = self.post_request("zxx/testproject/?editing=1", upload_contents, headers)
        # NOTE: this is what we do currently, any altered strings become suggestions.
        # It may be a good idea to change this
        mergedcontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n\n#: frog.c\nmsgid "tadpole"\nmsgstr "fish"\n\n#: toad.c\nmsgid "slink"\nmsgstr "stink"\n'
        suggestedcontents = '#: test.c\nmsgid ""\n"_: suggested by testuser\\n"\n"test"\nmsgstr "rested"\n'
        assert ' href="test_existing.po?' in response
        pofile_storename = os.path.join(podir, "test_existing.po")
        assert os.path.isfile(pofile_storename)
        assert open(pofile_storename).read().find(mergedcontents) >= 0
        pendingfile_storename = os.path.join(podir, "test_existing.po.pending")
        assert os.path.isfile(pendingfile_storename)
        assert open(pendingfile_storename).read().find(suggestedcontents) >= 0
        pocontents_download = self.fetch_page("zxx/testproject/test_existing.po")
        assert pocontents_download.find(mergedcontents) >= 0
    test_upload_over_file.userprefs = {"rights.siteadmin": True}
 
    def test_upload_xliff_over_file(self):
        """tests that we can upload a new version of a file into a project"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate")
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        pocontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n\n#: frog.c\nmsgid "tadpole"\nmsgstr "fish"\n'
        open(os.path.join(podir, "test_existing.po"), "w").write(pocontents)
        xlfcontents = '''<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.1" xmlns="urn:oasis:names:tc:xliff:document:1.1">
<file datatype="po" original="test_existing.po" source-language="en-US"><body>
<trans-unit id="1" xml:space="preserve" approved="yes">
<source>test</source>
<target state="translated">rested</target>
<context-group name="po-reference" purpose="location">
<context context-type="sourcefile">test.c</context>
</context-group>
</trans-unit>
<trans-unit id="2" xml:space="preserve" approved="yes">
<source>slink</source>
<target state="translated">stink</target>
<context-group name="po-reference" purpose="location">
<context context-type="sourcefile">toad.c</context>
</context-group>
</trans-unit>
</body></file></xliff>
'''
        fields = [("doupload", "Upload File")]
        files = [("uploadfile", "test_existing.xlf", xlfcontents)]
        content_type, upload_contents = postMultipart.encode_multipart_formdata(fields, files)
        headers = {"Content-Type": content_type, "Content-Length": len(upload_contents)}
        response = self.post_request("zxx/testproject/?editing=1", upload_contents, headers)
        # NOTE: this is what we do currently, any altered strings become suggestions.
        # It may be a good idea to change this
        mergedcontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n\n#: frog.c\nmsgid "tadpole"\nmsgstr "fish"\n\n#: toad.c\nmsgid "slink"\nmsgstr "stink"\n'
        suggestedcontents = '#: test.c\nmsgid ""\n"_: suggested by testuser\\n"\n"test"\nmsgstr "rested"\n'
        assert ' href="test_existing.po?' in response
        pofile_storename = os.path.join(podir, "test_existing.po")
        assert os.path.isfile(pofile_storename)
        assert open(pofile_storename).read().find(mergedcontents) >= 0
        pendingfile_storename = os.path.join(podir, "test_existing.po.pending")
        assert os.path.isfile(pendingfile_storename)
        assert open(pendingfile_storename).read().find(suggestedcontents) >= 0
        pocontents_download = self.fetch_page("zxx/testproject/test_existing.po")
        assert pocontents_download.find(mergedcontents) >= 0
    test_upload_xliff_over_file.userprefs = {"rights.siteadmin": True}
 
    def test_submit_translation(self):
        """tests that we can upload a new file into a project"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate")
        pofile_storename = os.path.join(podir, "test_upload.po")
        pocontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
        open(pofile_storename, "w").write(pocontents)
        expected_pocontents = '#: test.c\nmsgid "test"\nmsgstr "restrain"\n'
        fields = {"orig-pure0.0": "test", "trans0": "restrain", "submit0": "submit", "pofilename": "test_upload.po"}
        content_type, post_contents = postMultipart.encode_multipart_formdata(fields.items(), [])
        headers = {"Content-Type": content_type, "Content-Length": len(post_contents)}
        translatepage = self.post_request("zxx/testproject/test_upload.po?translate=1&editing=1", post_contents, headers)
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        pofile = project.getpofile("test_upload.po")
        assert str(pofile.units[1]) == expected_pocontents
 
    def test_submit_plural_translation(self):
        """tests that we can submit a translation with plurals"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate")
        pofile_storename = os.path.join(podir, "test_upload.po")
        pocontents = 'msgid "singular"\nmsgid_plural "plural"\nmsgstr[0] "enkelvoud string"\nmsgstr[1] "meervoud boodskap"\n'
        open(pofile_storename, "w").write(pocontents)
        expected_pocontents = 'msgid "singular"\nmsgid_plural "plural"\nmsgstr[0] "enkelvoud"\nmsgstr[1] "meervoud"\n'
        fields = {"orig-pure0.0": "singular", "trans0.0": "enkelvoud", "trans0.1": "meervoud", "submit0": "submit", "pofilename": "test_upload.po"}
        content_type, post_contents = postMultipart.encode_multipart_formdata(fields.items(), [])
        headers = {"Content-Type": content_type, "Content-Length": len(post_contents)}
        translatepage = self.post_request("zxx/testproject/test_upload.po?translate=1&editing=1", post_contents, headers)
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        pofile = project.getpofile("test_upload.po")
        assert str(pofile.units[1]) == expected_pocontents
 
    def test_submit_plural_to_singular_lang(self):
        """tests that we can submit a translation with plurals to a language without plurals."""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate")
        pofile_storename = os.path.join(podir, "test_upload.po")
        pocontents = 'msgid "singular"\nmsgid_plural "plural"\nmsgstr[0] "enkelvoud string"\n'
        open(pofile_storename, "w").write(pocontents)
        expected_pocontents = 'msgid "singular"\nmsgid_plural "plural"\nmsgstr[0] "enkelvoud"\n'
        fields = {"orig-pure0.0": "singular", "trans0.0": "enkelvoud", "submit0": "submit", "pofilename": "test_upload.po"}
        content_type, post_contents = postMultipart.encode_multipart_formdata(fields.items(), [])
        headers = {"Content-Type": content_type, "Content-Length": len(post_contents)}
        translatepage = self.post_request("zxx/testproject/test_upload.po?translate=1&editing=1", post_contents, headers)
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        pofile = project.getpofile("test_upload.po")
        assert str(pofile.units[1]) == expected_pocontents
 
 
    def test_submit_fuzzy(self):
        """tests that we can mark a unit as fuzzy"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate")
        pofile_storename = os.path.join(podir, "test_fuzzy.po")
        pocontents = '#: test.c\nmsgid "fuzzy"\nmsgstr "wuzzy"\n'
        open(pofile_storename, "w").write(pocontents)
        expected_pocontents = '#: test.c\n#, fuzzy\nmsgid "fuzzy"\nmsgstr "wuzzy"\n'
 
        # Fetch the page and check that the fuzzy checkbox is NOT checked.
        translatepage = self.fetch_page("zxx/testproject/test_fuzzy.po?translate=1&editing=1")
        assert '<input accesskey="f" type="checkbox" name="fuzzy0" />' in translatepage
 
        fields = {"orig-pure0.0": "fuzzy", "trans0": "wuzzy", "submit0": "submit", "fuzzy0": "on", "pofilename": "test_fuzzy.po"}
        content_type, post_contents = postMultipart.encode_multipart_formdata(fields.items(), [])
        headers = {"Content-Type": content_type, "Content-Length": len(post_contents)}
        translatepage = self.post_request("zxx/testproject/test_fuzzy.po?translate=1&editing=1", post_contents, headers)
 
        # Fetch the page again and check that the fuzzy checkbox IS checked.
        translatepage = self.fetch_page("zxx/testproject/test_fuzzy.po?translate=1&editing=1")
        assert '<input type="checkbox" accesskey="f" checked="checked" name="fuzzy0" />' in translatepage
 
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        pofile = project.getpofile("test_fuzzy.po")
        assert str(pofile.units[1]) == expected_pocontents
        assert pofile.units[1].isfuzzy()
 
        # Submit the translation again, without the fuzzy checkbox checked
        fields = {"orig-pure0.0": "fuzzy", "trans0": "wuzzy", "submit0": "submit", "pofilename": "test_fuzzy.po"}
        content_type, post_contents = postMultipart.encode_multipart_formdata(fields.items(), [])
        headers = {"Content-Type": content_type, "Content-Length": len(post_contents)}
        translatepage = self.post_request("zxx/testproject/test_fuzzy.po?translate=1&editing=1", post_contents, headers)
 
        # Fetch the page once more and check that the fuzzy checkbox is NOT checked.
        translatepage = self.fetch_page("zxx/testproject/test_fuzzy.po?translate=1&editing=1")
        assert '<input accesskey="f" type="checkbox" name="fuzzy0" />' in translatepage
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        pofile = project.getpofile("test_fuzzy.po")
        assert not pofile.units[1].isfuzzy()
 
    def test_submit_translator_comments(self):
        """tests that we can edit translator comments"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate")
        pofile_storename = os.path.join(podir, "test_upload.po")
        pocontents = '#: test.c\nmsgid "test"\nmsgstr "rest"\n'
        open(pofile_storename, "w").write(pocontents)
        expected_pocontents = '# Some test comment\n# test comment line 2\n#: test.c\nmsgid "test"\nmsgstr "rest"\n'
        fields = {"orig-pure0.0": "test", "trans0": "rest", "translator_comments0": "Some test comment\ntest comment line 2", "submit0": "submit", "pofilename": "test_upload.po"}
        content_type, post_contents = postMultipart.encode_multipart_formdata(fields.items(), [])
        headers = {"Content-Type": content_type, "Content-Length": len(post_contents)}
        translatepage = self.post_request("zxx/testproject/test_upload.po?translate=1&editing=1", post_contents, headers)
        tree = potree.POTree(self.prefs.Pootle)
        project = projects.TranslationProject("zxx", "testproject", tree)
        pofile = project.getpofile("test_upload.po")
        assert str(pofile.units[1]) == expected_pocontents
 
       
    def test_navigation_url_parameters(self):
        """tests that the navigation urls (next/end etc) has the necessary parameters"""
        self.login()
        podir = self.setup_testproject_dir(perms="view, translate")
        pofile_storename = os.path.join(podir, "test_nav_url.po")
        pocontents = '#: test.c\nmsgid "test1"\nmsgstr "rest"\n'
        pocontents += '\n#. Second Unit\nmsgid "test2"\nmsgstr "rest2"\n'
        open(pofile_storename, "w").write(pocontents)
        self.prefs.setvalue("Pootle.users.testuser.viewrows", 1)
        translatepage = self.fetch_page("zxx/testproject/test_nav_url.po?translate=1&view=1")
        patterns = re.findall('<a href=".(.*)".*Next 1.*</a>', translatepage)
        parameters = patterns[0].split('&amp;')
        assert 'pofilename=test_nav_url.po' in parameters
        assert 'item=1' in parameters
 
def MakeServerTester(baseclass):
    """Makes a new Server Tester class using the base class to setup webserver etc"""
    class TestServer(baseclass, ServerTester):
        def setup_method(self, method):
            ServerTester.setup_prefs(self, method)
            baseclass.setup_method(self, method)
            ServerTester.setup_cookies(self)
    return TestServer
 
TestServerCmdLine = MakeServerTester(test_cmdlineserver.TestCmdlineServer)
# TestServerService = MakeServerTester(test_service.TestjLogbookService)
# TestServerApache = MakeServerTester(test_apache.TestApachejLogbook)