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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
|
Translation Groups
==================
Make sure we can actually display the Translation Groups page.
>>> anon_browser.open('http://translations.launchpad.dev/')
>>> print anon_browser.url
http://translations.launchpad.dev/
>>> anon_browser.getLink('translation groups').click()
>>> print anon_browser.url
http://translations.launchpad.dev/+groups
>>> print anon_browser.title
Translation groups
Only Rosetta experts and Launchpad administrators can create translation
groups. Unprivileged users do not have access to the group creation
page.
>>> anon_browser.open(
... 'http://translations.launchpad.dev/+groups/+new')
Traceback (most recent call last):
...
Unauthorized...
Same for a regular, unprivileged user.
>>> user_browser.open(
... 'http://translations.launchpad.dev/+groups/+new')
Traceback (most recent call last):
...
Unauthorized...
OK, best we try again, with administrator rights!
>>> admin_browser.open(
... 'http://translations.launchpad.dev/+groups/+new')
>>> print find_main_content(
... admin_browser.contents).first('h1').renderContents()
Create a new translation group
Translation group names must meet certain conditions. For example, they
may not contain any upper-case letters.
>>> admin_browser.getControl('Name').value = 'PolYglot'
>>> admin_browser.getControl('Title').value = (
... 'The PolyGlot Translation Group')
>>> admin_browser.getControl('Summary').value = (
... "The PolyGlots are a well organised translation group that "
... "handles the work of translating a number of Ubuntu and upstream "
... "projects. It consists of a large number of translation teams, "
... "each specialising in their own language.")
>>> admin_browser.getControl('Create').click()
>>> for message in find_tags_by_class(admin_browser.contents, 'message'):
... print message.renderContents()
There is 1 error.
Invalid name 'PolYglot'. Names must be at least two characters ...
Neither we can use the name of an already existing group like testing-
translation-team.
>>> browser.open('http://translations.launchpad.dev/+groups')
>>> print browser.url
http://translations.launchpad.dev/+groups
>>> print browser.getLink('Just a testing team').url
http://translations.launchpad.dev/+groups/testing-translation-team
>>> admin_browser.getControl('Name').value = 'testing-translation-team'
>>> admin_browser.getControl('Create').click()
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/+new
>>> for message in find_tags_by_class(admin_browser.contents, 'message'):
... print message.renderContents()
There is 1 error.
There is already a translation group with such name
The same request will be accepted if the group is given a saner name,
such as just "polyglot" (no upper-case letters).
>>> admin_browser.getControl('Name').value='polyglot'
>>> admin_browser.getControl('Translation instructions').value=(
... u'https://help.launchpad.net/Translations/PolyglotPolicies')
>>> admin_browser.getControl('Create').click()
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/polyglot
After creating a translation group, the user automatically ends up on
that group's page.
>>> admin_browser.url
'http://translations.launchpad.dev/+groups/polyglot'
>>> admin_browser.title
'...The PolyGlot Translation Group...'
>>> docs = find_tag_by_id(admin_browser.contents, 'documentation')
>>> print extract_text(docs)
Please read the translation instructions...
>>> docs_url = docs.find('a')
>>> extract_link_from_tag(docs_url)
u'https://help.launchpad.net/Translations/PolyglotPolicies'
A Rosetta administrator is also allowed to create groups.
>>> browser.addHeader('Authorization', 'Basic jordi@ubuntu.com:test')
>>> browser.open(
... 'http://translations.launchpad.dev/+groups/+new')
>>> browser.getControl('Name').value='monolingua'
>>> browser.getControl('Title').value='Single-language Translators'
>>> browser.getControl('Summary').value = (
... "Since each of us only speaks one language, we work out software "
... "translations through drawings and hand signals.")
>>> browser.getControl('Create').click()
>>> print browser.url
http://translations.launchpad.dev/+groups/monolingua
>>> browser.title
'...Single-language Translators...'
By default, when a group is created, the creator is its owner.
>>> for t in find_tags_by_class(browser.contents, 'link'):
... print t.renderContents()
Jordi Mallach
The Rosetta administrator assigns ownership of the group to Sample
Person.
>>> browser.getLink(id='link-reassign').click()
>>> browser.url
'http://translations.launchpad.dev/+groups/monolingua/+reassign'
>>> browser.getControl(name='field.owner').value = 'name12'
>>> browser.getControl('Change').click()
>>> browser.url
'http://translations.launchpad.dev/+groups/monolingua'
The Rosetta administrator is still able to administer this group:
>>> browser.getLink('Appoint a new translation team')
<...+appoint'>
But Sample Person is now listed as its owner:
>>> for t in find_tags_by_class(browser.contents, 'link'):
... print t.renderContents()
Sample Person
That means that Sample Person is allowed to administer "his" group.
>>> browser.addHeader('Authorization', 'Basic test@canonical.com:test')
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'translations/groups/monolingua/')
>>> browser.getLink('Appoint a new translation team')
<...+appoint'>
The new groups should show up on the "Translation groups" page.
>>> anon_browser.open('http://translations.launchpad.dev/+groups')
>>> print anon_browser.url
http://translations.launchpad.dev/+groups
>>> groups_table = find_tag_by_id(
... anon_browser.contents, 'translation-groups')
>>> groups = groups_table.find('tbody').findAll('tr')
>>> for group_row in groups:
... group = group_row.findNext('td')
... print '%s: %s' % (group.a.string, group.a['href'])
Just a testing team: ...testing-translation-team
Single-language Translators: ...monolingua
The PolyGlot Translation Group: ...polyglot
When editing translation group details, we could rename the translation
group.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/+groups')
>>> print admin_browser.url
http://translations.launchpad.dev/+groups
We can see that the translation group that we are going to duplicate
exists already:
>>> print admin_browser.getLink('The PolyGlot Translation Group').url
http://translations.launchpad.dev/+groups/polyglot
Navigate to the one we are going to rename.
>>> admin_browser.getLink('Just a testing team').click()
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/testing-translation-team
And select to edit its details.
>>> admin_browser.getLink('Change details').click()
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/testing-translation-team/+edit
Change the name.
>>> admin_browser.getControl('Name').value = u'polyglot'
>>> admin_browser.getControl('Change').click()
The system detected that we tried to use an already existing name, so we
didn't move away from this form.
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/testing-translation-team/+edit
>>> for tag in find_tags_by_class(admin_browser.contents, 'message'):
... print tag.renderContents()
There is 1 error.
There is already a translation group with this name
Choosing another name should work though.
>>> admin_browser.getControl('Name').value = u'renamed-group'
>>> admin_browser.getControl('Change').click()
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/renamed-group
>>> for tag in find_tags_by_class(admin_browser.contents, 'message'):
... print tag.renderContents()
You can also edit the generic translation instructions for the team
>>> admin_browser.getLink('Change details').click()
>>> admin_browser.getControl('Translation instructions').value = (
... u'https://help.launchpad.net/Translations/RenamedGroup')
>>> admin_browser.getControl('Change').click()
Now, let's go have a look at where we can use these translation groups.
We want to check out the distro side first.
Ubuntu is using Launchpad for translations. Ubuntu doesn't have
TranslationGroup and uses open permissions. We can see that from the
translations page.
>>> anon_browser.open('http://launchpad.dev/ubuntu')
>>> anon_browser.getLink('Translations').click()
>>> print anon_browser.title
Translations : Ubuntu
>>> print extract_text(
... find_tag_by_id(anon_browser.contents, 'translation-permissions'))
Ubuntu is translated with Open permissions...
And now make sure we can see the form to change the translation group
and permissions on a project. For that, we are going to use Colin
Watson's account, he's one of the owners of Ubuntu.
>>> ubuntu_owner_browser = setupBrowser(
... auth='Basic colin.watson@ubuntulinux.com:test')
>>> ubuntu_owner_browser.open(anon_browser.url)
>>> ubuntu_owner_browser.getLink('Configure translations').click()
>>> print ubuntu_owner_browser.title
Settings : Translations : Ubuntu
Other users cannot access this page, nor see the menu link to it.
>>> user_browser.open(anon_browser.url)
>>> user_browser.getLink('Configure translations').click()
Traceback (most recent call last):
...
LinkNotFoundError
>>> user_browser.open(ubuntu_owner_browser.url)
Traceback (most recent call last):
...
Unauthorized...
Let's post to the form, setting the translation group to polyglot and
closed permissions.
>>> ubuntu_owner_browser.getControl(
... 'Translation permissions policy').displayValue = ['Closed']
>>> print ubuntu_owner_browser.getControl(
... 'Translation group').displayOptions
['(no value)', 'Single-language Translators',
'The PolyGlot Translation Group', 'Just a testing team']
>>> ubuntu_owner_browser.getControl(
... 'Translation group').displayValue = [
... 'The PolyGlot Translation Group']
>>> ubuntu_owner_browser.getControl('Change').click()
>>> print ubuntu_owner_browser.title
Translations : Ubuntu
>>> print extract_text(
... find_tag_by_id(ubuntu_owner_browser.contents,
... 'translation-permissions'))
Ubuntu is translated by The PolyGlot Translation Group...
These changes are now reflected in the Ubuntu translations page for
everybody else as well.
>>> anon_browser.reload()
>>> print anon_browser.title
Translations : Ubuntu
>>> print extract_text(
... find_tag_by_id(anon_browser.contents, 'translation-permissions'))
Ubuntu is translated by The PolyGlot Translation Group
with Closed permissions...
We should also be able to set a translation group and translation
permissions on a product. We'll use the Netapplet product for this test.
First make sure it uses Launchpad for translations.
>>> netapplet_owner_browser = setupBrowser(
... auth='Basic test@canonical.com:test')
>>> netapplet_owner_browser.open('http://launchpad.dev/netapplet')
>>> netapplet_owner_browser.getLink(
... 'Configure translations').click()
>>> print netapplet_owner_browser.title
Configure translations : NetApplet
>>> netapplet_owner_browser.getControl('Launchpad').click()
>>> netapplet_owner_browser.getControl('Change').click()
>>> print netapplet_owner_browser.title
NetApplet in Launchpad
Netapplet doesn't have TranslationGroup and uses open permissions. We
can see that from the translations page.
>>> netapplet_owner_browser.open('http://launchpad.dev/netapplet')
>>> netapplet_owner_browser.getLink('Translations').click()
>>> print netapplet_owner_browser.title
Translations : NetApplet
>>> print extract_text(
... find_tag_by_id(netapplet_owner_browser.contents,
... 'translation-permissions'))
NetApplet is translated with Open permissions.
Now let's make sure we can see the page to let us change translation
group and permissions.
>>> translations_page_url = netapplet_owner_browser.url
>>> netapplet_owner_browser.getLink('Configure translations').click()
>>> change_translators_url = netapplet_owner_browser.url
>>> print netapplet_owner_browser.title
Configure translations : Translations : NetApplet
>>> print netapplet_owner_browser.getControl(
... 'Translation group').displayOptions
['(no value)', 'Single-language Translators',
'The PolyGlot Translation Group', 'Just a testing team']
>>> print netapplet_owner_browser.getControl(
... 'Translation group').displayValue
['(no value)']
Ordinary users cannot see the "Configure translations" link or the page it
leads to.
>>> user_browser.open(translations_page_url)
>>> user_browser.getLink('Configure translations').click()
Traceback (most recent call last):
...
LinkNotFoundError
>>> user_browser.open(change_translators_url)
Traceback (most recent call last):
...
Unauthorized...
Now let's post to the form. We should be redirected to the product page.
>>> netapplet_owner_browser.getControl(
... 'Translation group').displayValue = [
... 'The PolyGlot Translation Group']
>>> netapplet_owner_browser.getControl('Change').click()
>>> print netapplet_owner_browser.title
Translations : NetApplet
Now these changes show up in the product page. (XXX mpt 20070126:
Launchpad should be fixed so that you can't set translation
group/permissions without using Translations.)
Lastly, we should be able to set the translation group on a project.
We'll use the Gnome project as an example. First make sure we can see
the Gnome project page and that it has no translation group assigned.
>>> gnome_owner_browser = setupBrowser(
... auth='Basic test@canonical.com:test')
>>> gnome_owner_browser.open('http://launchpad.dev/gnome')
>>> gnome_owner_browser.getLink('Translations').click()
>>> translations_page_url = gnome_owner_browser.url
>>> print gnome_owner_browser.title
Translations : GNOME
And now make sure we can see the form to change the translation group
and permissions on a project.
>>> gnome_owner_browser.getLink('Change permissions').click()
>>> print gnome_owner_browser.title
Permissions and policies...
Other users don't see the "Change translators" link and aren't allowed
to access the page it leads to.
>>> user_browser.open(translations_page_url)
>>> user_browser.getLink('Change permissions').click()
Traceback (most recent call last):
...
LinkNotFoundError
>>> user_browser.open(gnome_owner_browser.url)
Traceback (most recent call last):
...
Unauthorized...
Let's post to the form, setting the translation group to polyglot and
closed permissions.
>>> gnome_owner_browser.getControl(
... 'Translation permissions policy').displayValue = ['Closed']
>>> print gnome_owner_browser.getControl(
... 'Translation group').displayOptions
['(no value)', 'Single-language Translators',
'The PolyGlot Translation Group', 'Just a testing team']
>>> gnome_owner_browser.getControl(
... 'Translation group').displayValue = [
... 'The PolyGlot Translation Group']
>>> gnome_owner_browser.getControl('Change').click()
And make sure these changes are now reflected in the Gnome project page
in the relevant portlet.
>>> gnome_owner_browser.url
'http://translations.launchpad.dev/gnome'
>>> print gnome_owner_browser.title
Translations : GNOME
We should now see the various distro's, projects and products that the
group has been assigned as the translator for.
>>> browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot')
>>> print browser.url
http://translations.launchpad.dev/+groups/polyglot
>>> def find_projects_portlet(browser):
... """Find the portlet with projects/distros this group works with.
... """
... return find_tag_by_id(browser.contents, "related-projects")
>>> portlet = find_projects_portlet(browser)
>>> for link in portlet.findAll('a'):
... print '%s: %s' % (link.find(text=True), link['href'])
Ubuntu: http://launchpad.dev/ubuntu
GNOME: http://launchpad.dev/gnome
NetApplet: http://launchpad.dev/netapplet
If we disable some of these projects...
>>> admin_browser.open("http://launchpad.dev/gnome/+review")
>>> admin_browser.getControl("Active").click()
>>> admin_browser.getControl("Change").click()
>>> admin_browser.url
'http://launchpad.dev/projectgroups'
# Unlink the source packages so the project can be deactivated.
>>> from zope.component import getUtility
>>> from lp.registry.interfaces.product import IProductSet
>>> from lp.testing import unlink_source_packages
>>> login('admin@canonical.com')
>>> unlink_source_packages(getUtility(IProductSet).getByName('netapplet'))
>>> logout()
>>> admin_browser.open("http://launchpad.dev/netapplet/+admin")
>>> admin_browser.getControl("Active").click()
>>> admin_browser.getControl("Change").click()
>>> admin_browser.url
'http://launchpad.dev/projects'
They disappear from the listing:
>>> browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot')
>>> print browser.url
http://translations.launchpad.dev/+groups/polyglot
>>> portlet = find_projects_portlet(browser)
>>> for link in portlet.findAll('a'):
... print '%s: %s' % (link.string, link['href'])
Ubuntu: http://launchpad.dev/ubuntu
Let's undo this so we don't get in trouble with other tests in this
story!
>>> admin_browser.open("http://launchpad.dev/gnome/+review")
>>> admin_browser.getControl("Active").click()
>>> admin_browser.getControl("Change").click()
>>> admin_browser.open("http://launchpad.dev/netapplet/+admin")
>>> admin_browser.getControl("Active").click()
>>> admin_browser.getControl("Change").click()
Appointing translators in a translation group
---------------------------------------------
No translators have been appointed in the polyglot group so far.
A user can have rights to appoint or remove members on any of three
grounds: owning the group, being a Rosetta expert, or being a Launchpad
administrator.
Jordi Mallach is a Rosetta administrator ("expert"). He does not own
polyglot nor is he a Launchpad adminstrator. That is enough to allow
him to appoint a translator.
>>> browser.addHeader('Authorization', 'Basic jordi@ubuntu.com:test')
>>> browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/')
>>> print find_tag_by_id(browser.contents, "translation-teams-listing")
<...
No translation teams or supervisors have been appointed in this
group yet.
...
Verify that the appointments form displays, and offers the option to
appoint a translator.
>>> browser.getLink('Appoint a new translation team').click()
>>> browser.url
'http://translations.launchpad.dev/+groups/polyglot/+appoint'
Appoint a translator. Hoary Gnome Team will translate into Abkhazian.
>>> browser.getControl('Language').value=['ab']
>>> browser.getControl('Translator').value='name21'
>>> browser.getControl('Appoint').click()
We should get redirected back to the group page.
>>> browser.url
'http://translations.launchpad.dev/+groups/polyglot'
>>> browser.getLink('Appoint a new translation team').click()
>>> browser.url
'http://translations.launchpad.dev/+groups/polyglot/+appoint'
And let's appoint No Privileges user for Afrikaans too.
>>> browser.getControl('Language').value=['af']
>>> browser.getControl('Translator').value='no-priv'
>>> browser.getControl('Appoint').click()
Now we should see both of those appointments on the polyglot page:
>>> find_main_content(browser.contents)
<...Abkhazian...Hoary Gnome Team...
...Afrikaans...No Privileges Person...
>>> browser.url
'http://translations.launchpad.dev/+groups/polyglot'
Appointing a new Abkhazian translator must fail gracefully, not crash as
it used to do (Bug #52991).
>>> browser.getLink('Appoint a new translation team').click()
>>> browser.getControl('Language').value=['ab']
>>> browser.getControl('Translator').value='name12'
>>> browser.getControl('Appoint').click()
The error means we stay on the appoint page:
>>> browser.url
'http://translations.launchpad.dev/+groups/polyglot/+appoint'
>>> for message in find_tags_by_class(browser.contents, 'message'):
... print message.renderContents()
There is 1 error.
There is already a translator for this language
Launchpad administrators, are allowed too to manage translation group
membership.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/')
>>> admin_browser.getLink('Appoint a new translation team').click()
>>> admin_browser.url
'http://translations.launchpad.dev/+groups/polyglot/+appoint'
Even to edit details of the translation group.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/')
>>> admin_browser.getLink('Change details').click()
>>> admin_browser.url
'http://translations.launchpad.dev/+groups/polyglot/+edit'
Normal users, however, are not.
>>> user_browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/')
>>> user_browser.url
'http://translations.launchpad.dev/+groups/polyglot/'
>>> user_browser.getLink('Appoint a new translation team')
Traceback (most recent call last):
...
LinkNotFoundError
>>> user_browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/')
>>> user_browser.url
'http://translations.launchpad.dev/+groups/polyglot/'
>>> user_browser.getLink('Change details').click()
Traceback (most recent call last):
...
LinkNotFoundError
Change a translator in a translation group
------------------------------------------
The system allows us to change the translator for a concrete language
# Let's see the list of languages we have right now:
>>> anon_browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot')
>>> print anon_browser.url
http://translations.launchpad.dev/+groups/polyglot
>>> portlet = find_tag_by_id(
... anon_browser.contents, "translation-teams-listing")
>>> language_rows = portlet.find('tbody').findAll('tr')
>>> for language_row in language_rows:
... cell = language_row.findNext('td')
... lang_name = extract_text(cell)
... lang_team = extract_text(cell.findNext('td').findNext('a'))
... print '%s: %s' % (lang_name, lang_team)
Abkhazian (ab): Hoary Gnome Team
Afrikaans (af): No Privileges Person
>>> browser.addHeader('Authorization', 'Basic jordi@ubuntu.com:test')
>>> browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/')
>>> print browser.url
http://translations.launchpad.dev/+groups/polyglot/
# We are going to change the Afrikaans (af) translator.
>>> browser.getLink(id='edit-af-translator').click()
>>> print browser.url
http://translations.launchpad.dev/+groups/polyglot/af
Let's change the language it translates to Afrikaans, which already
exist.
# Abkhazian URL exists.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/ab')
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/polyglot/ab
# And we change the one we are editing from Afrikaans to Abkhazian
>>> browser.getControl('Language').value = ['ab']
>>> browser.getControl('Change').click()
# We stay in the same page (+admin is the default view for
# polyglot/af/).
>>> print browser.url
http://translations.launchpad.dev/+groups/polyglot/af/+admin
the system detects it and notify the user that is not possible.
>>> for message in find_tags_by_class(browser.contents, 'message'):
... print message.renderContents()
There is 1 error.
<a href="http://translations.launchpad.dev/~name21">Hoary Gnome Team</a>
is already a translator for this language
However, if the language selected doesn't have yet a translator, for
instance Welsh (cy), the change will work.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/cy')
Traceback (most recent call last):
...
NotFound:...
>>> browser.getControl('Language').value = ['cy']
>>> browser.getControl('Change').click()
# We are back to the translation group summary page.
>>> print browser.url
http://translations.launchpad.dev/+groups/polyglot
# And the 'Translation Teams' portlet shows the new information.
>>> portlet = find_tag_by_id(
... browser.contents, "translation-teams-listing")
>>> language_rows = portlet.find('tbody').findAll('tr')
>>> for language_row in language_rows:
... cell = language_row.findNext('td')
... lang_name = extract_text(cell)
... lang_team = extract_text(cell.findNext('td').findNext('a'))
... print '%s: %s' % (lang_name, lang_team)
Abkhazian (ab): Hoary Gnome Team
Welsh (cy): No Privileges Person
Let's remove the Hoary Gnome Team, they are not really translators. We
should be redirected to the polyglot page.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/+groups/' +
... 'polyglot/ab/+remove')
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/polyglot/ab/+remove
>>> admin_browser.getControl('Remove').click()
>>> print admin_browser.url
http://translations.launchpad.dev/+groups/polyglot
And on that page, we should see the removal message.
>>> for tag in find_tags_by_class(admin_browser.contents, 'message'):
... print tag.renderContents()
Removed Hoary Gnome Team as the Abkhazian translator for The PolyGlot
Translation Group.
So now No Privileges Person is the Welsh translator for the PolyGlot
translation group, and they are the translation group for Ubuntu, which
uses the Closed translation mode. This means that No Privileges Person
should be able to translate any strings in Ubuntu to Welsh. In other
languages, he will not be able to add or change translations.
Let's see if No Privileges Person can see the translated strings in
Southern Sotho. We expect them to see a readonly form:
>>> delpoints = []
>>> for pos, (key, _) in enumerate(browser.mech_browser.addheaders):
... if key == 'Authorization':
... delpoints.append(pos)
>>> for pos in reversed(delpoints):
... del browser.mech_browser.addheaders[pos]
>>> browser.addHeader(
... 'Authorization', 'Basic no-priv@canonical.com:test')
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'ubuntu/hoary/+source/evolution/'
... '+pots/evolution-2.2/st/+translate')
>>> print browser.url
http://.../ubuntu/.../evolution/+pots/evolution-2.2/st/+translate
We are in read only mode, so there shouldn't be any textareas:
>>> main_content = find_tag_by_id(
... browser.contents, 'messages_to_translate')
>>> for textarea in main_content.findAll('textarea'):
... print 'Found textarea:\n%s' % textarea
Neither any input widget:
>>> for input in main_content.findAll('input'):
... print 'Found input:\n%s' % input
However, in Welsh, No Privileges Person does have the ability to edit
directly.
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'ubuntu/hoary/+source/evolution/'
... '+pots/evolution-2.2/cy/19/+translate')
>>> print browser.url
http://.../ubuntu/.../evolution/+pots/evolution-2.2/cy/19/+translate
No Privileges is going to do some translation here. Right now, message
number 148 is not translated.
>>> tag = find_tag_by_id(browser.contents, 'msgset_148_cy_translation_0')
>>> print tag.renderContents()
(no translation yet)
After No posts a translation, however, it is.
>>> browser.getControl(
... name='msgset_148_cy_translation_0_radiobutton').value = [
... 'msgset_148_cy_translation_0_new']
>>> browser.getControl(
... name='msgset_148_cy_translation_0_new').value = 'foo\n%i%i%i\n'
>>> browser.getControl('Save & Continue').click()
>>> print browser.url
http://.../ubuntu/.../evolution/+pots/evolution-2.2/cy/20/+translate
And finally, let's take a look again, and we should have a translation
added (with some extra html code, but the same content we wanted to add)
>>> browser.getLink('Previous').click()
>>> print browser.url
http://.../ubuntu/.../evolution/+pots/evolution-2.2/cy/19/+translate
>>> tag = find_tag_by_id(browser.contents, 'msgset_148_cy_translation_0')
>>> print tag.renderContents()
foo<img alt="" src="/@@/translation-newline" /><br />
%i%i%i
Now No Privileges Person is still the Welsh translator for the PolyGlot
translation group, and they are the translation group for Ubuntu, which
we are going to set as having Restricted translations. This means that
No Privileges Person should be able to translate any strings in Ubuntu
to Welsh. In other languages, No Privileges Person should be warned that
he is not a designated translator.
>>> browser.addHeader('Authorization', 'Basic no-priv@canonical.com:test')
>>> admin_browser.open(
... 'http://translations.launchpad.dev/ubuntu/'
... '+configure-translations')
>>> admin_browser.getControl(
... 'Translation permissions policy').value = ['RESTRICTED']
>>> admin_browser.getControl('Change').click()
>>> print admin_browser.url
http://translations.launchpad.dev/ubuntu
>>> print extract_text(
... find_tag_by_id(admin_browser.contents, 'translation-permissions'))
Ubuntu is translated by ... with Restricted permissions...
The translation group does not assign anyone to tend to the Southern
Sotho translation, so for that language, No Privileges can't even make
suggestions.
>>> def find_translation_input_label(contents):
... """Find first "New suggestion:" or "New translation:" label."""
... labels = find_tags_by_class(contents, 'translation-input-label')
... if not labels:
... return None
... else:
... return labels[0].renderContents()
>>> def get_detail_tag(browser, tag_class):
... """Find tag of given class in translation page."""
... tag = find_tag_by_id(browser.contents, tag_class)
... if not tag:
... return None
... else:
... return tag.renderContents()
>>> def print_menu_option(contents, option):
... """Print given navigation menu on given page, if present."""
... found = False
... for item in find_tags_by_class(contents, 'menu-link-%s' % option):
... print item.renderContents()
... found = True
... if not found:
... print "Not found."
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'ubuntu/hoary/+source/evolution/'
... '+pots/evolution-2.2/')
>>> print_menu_option(browser.contents, 'edit')
Not found.
>>> print_menu_option(browser.contents, 'upload')
Not found.
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'ubuntu/hoary/+source/evolution/'
... '+pots/evolution-2.2/st/+translate')
>>> print find_translation_input_label(browser.contents)
None
>>> managers = get_detail_tag(browser, 'translation-managers')
>>> print managers
This translation is managed by <...> translation group
<...>polyglot<...>.
>>> print get_detail_tag(browser, 'translation-access')
There is nobody to manage translation into this particular language. If
you are interested in working on it, please contact the translation group.
>>> print_menu_option(browser.contents, 'upload')
Not found.
The Polyglot translation group now assigns a Southern Sotho translation
team, of which No Privileges however is not a member.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/+groups/polyglot/+appoint')
>>> admin_browser.getControl('Language').value=['st']
>>> admin_browser.getControl('Translator').value='name21'
>>> admin_browser.getControl('Appoint').click()
No Privileges Person can now enter text, but the page does warn that it
will only accept suggestions.
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'ubuntu/hoary/+source/evolution/'
... '+pots/evolution-2.2/st/+translate')
>>> print find_translation_input_label(browser.contents)
New suggestion:
>>> managers = get_detail_tag(browser, 'translation-managers')
>>> print managers
This translation is managed by <...>...Hoary Gnome Team<...>, assigned
by <...>The PolyGlot Translation Group<...>.
The ability to upload files is restricted to those with full edit
privileges.
>>> print_menu_option(browser.contents, 'upload')
Not found.
The translation-managers detail may use ", and" to separate items, but
since there is only one item in this case, we don't see that.
>>> import re
>>> print re.search('\band\b', managers)
None
>>> print get_detail_tag(browser, 'translation-access')
Your suggestions will be held for review...
In Welsh, No Privileges Person does have the ability to edit directly,
as well as to upload files.
>>> def find_no_translation_marker(contents):
... """Find first "no translation yet" marker in contents."""
... markers = find_tags_by_class(contents, 'no-translation')
... if not markers:
... return None
... else:
... return markers[0].renderContents()
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'ubuntu/hoary/+source/evolution/'
... '+pots/evolution-2.2/cy/+translate')
>>> print_menu_option(browser.contents, 'upload')
Upload translation
No Privileges person is going to translate here. Message number 137 is
not yet translated.
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'ubuntu/hoary/+source/evolution/'
... '+pots/evolution-2.2/cy/8/+translate')
>>> print get_detail_tag(browser, 'translation-managers')
This translation is managed by <...No Privileges Person<...>, assigned by
<...>The PolyGlot Translation Group<...>.
>>> print get_detail_tag(browser, 'translation-access')
You have full access to this translation.
>>> print find_no_translation_marker(browser.contents)
(no translation yet)
Now, we need to show that it is translated after a post. Let's go ahead and
POST and see that all goes well:
>>> browser.getControl(
... name='msgset_137_cy_translation_0_radiobutton').value = [
... 'msgset_137_cy_translation_0_new']
>>> msg_137 = browser.getControl(name='msgset_137_cy_translation_0_new')
>>> msg_137.value = 'evolution minikaart'
>>> browser.getControl(name='submit_translations').click()
>>> print browser.url
http://.../ubuntu/.../+pots/evolution-2.2/cy/9/+translate
And finally, let's take a look again, and we see that the translation
has been added.
>>> browser.getLink('Previous').click()
>>> print find_no_translation_marker(browser.contents)
None
>>> print find_main_content(browser.contents).renderContents()
<...evolution minikaart...
First, we verify that netapplet is using Launchpad Translations.
>>> admin_browser.open('http://launchpad.dev/netapplet')
>>> admin_browser.getLink('Configure translations').click()
>>> print_radio_button_field(admin_browser.contents, "translations_usage")
( ) Unknown
(*) Launchpad
( ) External
( ) Not Applicable
>>> admin_browser.getLink('Cancel').click()
>>> print admin_browser.title
NetApplet in Launchpad
We set the 'Structured' permission and select the 'Just a testing team'
as the translation group for the netapplet product...
>>> admin_browser.getLink('Translations').click()
>>> admin_browser.getLink('Configure translations').click()
>>> admin_browser.getControl('Translation group').displayOptions
['(no value)', 'Single-language Translators',
'The PolyGlot Translation Group', 'Just a testing team']
>>> admin_browser.getControl('Translation group').displayValue = [
... 'Just a testing team']
>>> admin_browser.getControl(
... 'Translation permissions policy').displayValue = ['Structured']
>>> admin_browser.getControl('Change').click()
>>> print admin_browser.title
Translations : NetApplet
... and its associated project, GNOME.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/gnome/+settings')
>>> admin_browser.getControl('Translation group').displayValue = [
... 'Just a testing team']
>>> admin_browser.getControl(
... 'Translation permissions policy').displayValue = ['Structured']
>>> admin_browser.getControl('Change').click()
>>> admin_browser.url
'http://translations.launchpad.dev/gnome'
Now, we test that a member of a translation team is able to translate
directly, in this example, we are using 'tsukimi' account.
>>> tsukimi_browser = setupBrowser(auth='Basic tsukimi@quaqua.net:test')
>>> tsukimi_browser.open(
... 'http://translations.launchpad.dev/netapplet/trunk/+pots/' +
... 'netapplet/es/+translate')
>>> content = find_main_content(tsukimi_browser.contents)
>>> print content
<...
...Translating into Spanish...
...Dial-up connection...
Next test is with a non member of that translation team, the 'No
Privileges' account. We check that we get the warning that we are not
members of the team.
>>> no_priv_browser = setupBrowser(
... auth='Basic no-priv@canonical.com:test')
>>> no_priv_browser.open(
... 'http://translations.launchpad.dev/netapplet/trunk/+pots/' +
... 'netapplet/es/+translate')
>>> content = find_main_content(no_priv_browser.contents)
>>> print content
<...
...Translating into Spanish...
...Your suggestions will be held for review...
And finally, we test that a language without a team lets anyone (in this
case, the 'No Privileges' account) to translate directly.
>>> no_priv_browser.open(
... 'http://translations.launchpad.dev/netapplet/trunk/+pots/' +
... 'netapplet/fr/+translate')
>>> content = find_main_content(no_priv_browser.contents)
>>> print content
<...
...Translating into French...
First, make sure we can see the page.
Try to get the page when unauthenticated.
>>> browser.open(
... 'http://translations.launchpad.dev/ubuntu/hoary/+source/' +
... 'evolution/+pots/evolution-2.2/af/+upload')
Traceback (most recent call last):
...
Unauthorized:...
And now with valid credentials.
>>> admin_browser.open(
... 'http://translations.launchpad.dev/ubuntu/hoary/+source/' +
... 'evolution/+pots/evolution-2.2/af/+upload')
>>> print admin_browser.url
http://.../ubuntu/hoary/+source/evolution/+pots/evolution-2.2/af/+upload
Now hit the upload button, but without giving a file for upload. We get
an error message back.
>>> admin_browser.getControl('Upload').click()
>>> print admin_browser.url
http://.../ubuntu/hoary/+source/evolution/+pots/evolution-2.2/af/+upload
>>> for tag in find_tags_by_class(admin_browser.contents, 'error'):
... print tag.renderContents()
Ignored your upload because you didn't select a file to upload.
Uploading files with an unkown file format notifies the user that it
cannot be handled.
>>> from StringIO import StringIO
>>> af_file = '''
... # Afrikaans translation for Silky
... # Copyright (C) 2004 Free Software Foundation, Inc.
... # This file is distributed under the same license as the silky package.
... # Hanlie Pretorius <hpretorius@pnp.co.za>, 2004.
... #
... msgid ""
... msgstr ""
... "Project-Id-Version: hello-ycp-0.13.1\n"
... "Report-Msgid-Bugs-To: bug-gnu-gettext@gnu.org\n"
... "PO-Revision-Date: 2003-12-31 10:30+2\n"
... "Last-Translator: Ysbeer <ysbeer@af.org.za>\n"
... "Language-Team: Afrikaans <i18n@af.org.za>\n"
... "MIME-Version: 1.0\n"
... "Content-Type: text/plain; charset=UTF-8\n"
... "Content-Transfer-Encoding: 8bit\n"
...
... #: hello.ycp:16
... msgid "Hello, world!"
... msgstr "Hallo wêreld!"
...
... #: hello.ycp:20
... #, ycp-format
... msgid "This program is running as process number %1."
... msgstr "Hierdie program loop as prosesnommer %1."'''
>>> upload = admin_browser.getControl(name='file')
>>> upload.add_file(StringIO(af_file), 'application/msword', 'af.doc')
>>> admin_browser.getControl('Upload').click()
>>> print admin_browser.url
http://translations.launchpad.dev/ubuntu/hoary/+source/evolution/+pots/evolution-2.2/af/+upload
>>> for tag in find_tags_by_class(admin_browser.contents, 'error'):
... print tag.renderContents()
Ignored your upload because the file you uploaded was not recognised as
a file that can be imported.
With all the correct information, a file can be uploaded.
>>> upload = admin_browser.getControl(name='file')
>>> upload.add_file(StringIO(af_file), 'application/x-po', 'af.po')
>>> admin_browser.getControl('Upload').click()
>>> print admin_browser.url
http://translations.launchpad.dev/ubuntu/hoary/+source/evolution/+pots/evolution-2.2/af/+upload
>>> for tag in find_tags_by_class(admin_browser.contents, 'message'):
... print tag.renderContents()
Thank you for your upload. It will be automatically reviewed...
We are going to test the system by which rosetta provides alternative
translation suggestions. This will need to be updated when we change the
presentation of these items.
This test is going to work with evolution source package for Ubuntu
Hoary. As part of this history, we have Hoary distro release with
RESTRICTED permissions and with the Polyglot translation team in charge
of its translations.
Polyglot has someone assigned for Spanish translations, and though No
Privileges is not that person, this does make it possible to enter
suggestions in Spanish.
>>> from zope.component import getUtility
>>> from canonical.launchpad.ftests import login, logout
>>> from lp.registry.interfaces.distribution import IDistributionSet
>>> from lp.registry.interfaces.person import IPersonSet
>>> from lp.services.worlddata.interfaces.language import ILanguageSet
>>> from lp.translations.interfaces.potemplate import IPOTemplateSet
>>> from lp.translations.interfaces.translator import ITranslatorSet
>>> login('foo.bar@canonical.com')
>>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
>>> spanish = getUtility(ILanguageSet)['es']
>>> carlos = getUtility(IPersonSet).getByName('carlos')
>>> ubuntu_spanish_reviewer = getUtility(ITranslatorSet).new(
... translationgroup=ubuntu.translationgroup, language=spanish,
... translator=carlos)
>>> utility = getUtility(IPOTemplateSet)
>>> dummy = utility.populateSuggestivePOTemplatesCache()
>>> logout()
Let's add a new suggestion as a person without privileges.
>>> browser.addHeader("Authorization", "Basic no-priv@canonical.com:test")
>>> browser.open(
... 'http://translations.launchpad.dev/'
... 'ubuntu/hoary/+source/evolution/'
... '+pots/evolution-2.2/es/+translate')
>>> browser.getControl(
... name='msgset_134_es_translation_0_new_checkbox').value = True
>>> browser.getControl(
... name='msgset_134_es_translation_0_new').value = 'new suggestion'
>>> browser.getControl(name='submit_translations').click()
>>> print browser.url
http://.../ubuntu/.../evolution/+pots/evolution-2.2/es/+translate?...
>>> browser.getLink('Previous').click()
Now, we can see the added suggestion + others from the sample data.
>>> print find_tag_by_id(
... browser.contents, "msgset_134_es_suggestion_703_0")
<...<samp> </samp>new suggestion...
>>> print find_tag_by_id(
... browser.contents, "msgset_134_es_suggestion_703_0_origin")
<...
...Suggested by...No Privileges Person...
These are old suggestions:
>>> print find_tag_by_id(
... browser.contents, "msgset_134_es_suggestion_698_0")
<...<samp> </samp>Srprise! (non-editor)...
>>> print find_tag_by_id(
... browser.contents, "msgset_134_es_suggestion_698_0_origin")
<...
...Suggested by...Valentina Commissari...2005-06-06...
>>> print find_tag_by_id(
... browser.contents, "msgset_134_es_suggestion_696_0")
<...<samp> </samp>bang bang in evo hoary...
>>> print find_tag_by_id(
... browser.contents, "msgset_134_es_suggestion_696_0_origin")
<...
...Suggested in...evolution-2.2 in Evolution trunk...
...Mark Shuttleworth</a>...2005-06-06...
And there's also a separate translation coming from upstream:
>>> print find_tag_by_id(browser.contents, "msgset_134_other")
<...<samp> </samp>tarjetas...
>>> print find_tag_by_id(browser.contents, "msgset_134_other_origin")
<...
...Suggested by...Carlos Perelló Marín...2005-05-06...
|