Merge lp:~henninge/launchpad/db-devel-bug-611668-filtermethods-2 into lp:launchpad/db-devel

Proposed by Henning Eggers
Status: Merged
Approved by: Henning Eggers
Approved revision: no longer in the source branch.
Merged at revision: 10047
Proposed branch: lp:~henninge/launchpad/db-devel-bug-611668-filtermethods-2
Merge into: lp:launchpad/db-devel
Prerequisite: lp:~henninge/launchpad/db-devel-bug-611668-filtermethods-1
Diff against target: 1133 lines (+590/-22) (has conflicts)
5 files modified
lib/lp/translations/browser/pofile.py (+10/-0)
lib/lp/translations/doc/pofile.txt (+4/-0)
lib/lp/translations/interfaces/pofile.py (+5/-0)
lib/lp/translations/model/pofile.py (+70/-5)
lib/lp/translations/tests/test_pofile.py (+501/-17)
Text conflict in lib/lp/translations/browser/pofile.py
Text conflict in lib/lp/translations/browser/tests/test_pofile_view.py
Text conflict in lib/lp/translations/doc/pofile.txt
Text conflict in lib/lp/translations/interfaces/pofile.py
Text conflict in lib/lp/translations/model/pofile.py
Text conflict in lib/lp/translations/tests/test_pofile.py
Text conflict in lib/lp/translations/tests/test_translations_to_review.py
To merge this branch: bzr merge lp:~henninge/launchpad/db-devel-bug-611668-filtermethods-2
Reviewer Review Type Date Requested Status
Leonard Richardson (community) Approve
Review via email: mp+42293@code.launchpad.net

Description of the change

== Details ==

This branch continues the quest for the transformation of the messsage filter methods to the new translations model. It contains the following changes:

 * Create TestUpstreamFilters and TestUbuntuFilters from
   the scenario created in the previous branch.
 * Rename getPOTMsgSetChangedInUbuntu to
   getPOTMsgSetDifferentTranslations because the old name
   was specific to the old model.
 * Make the getPOTMsgSet* methods side-aware,
   i.e. convert them to the new model.
 * Convert all of test_pofile.py to the new model (i.e.
   use makeCurrentTranslationMessage). Part of this was
   needed to make the tests pass again.

== Tests ==

bin/test -vvcm lp.translations.tests.test_pofile

pofile.txt ist still failng that will be fixed in the next branch.

To post a comment you must log in.
Revision history for this message
Leonard Richardson (leonardr) wrote :

I approve with what are hopefully minor changes. Specifically, I found test_getPOTMsgSetDifferentTranslations very confusing. The comments and sample code are talking about "one side" and "both sides"--it would be easier for me to understand if you specified "upstream side but not Ubuntu side" and "both upstream and ubuntu sides", especially since the things you're testing are .is_current_ubuntu and .is_current_upstream.

You also use "diverged" vs. "changed" in that test without explaining the difference. I can almost figure out what you mean by looking at the test, but not quite because a) you never explained what "changed" means (on IRC you said it was an old term, so why still use it?)--what has changed? And it's not clear why setting diverged=True makes is_current_upstream True and is_current_ubuntu False, instead of vice versa.

This is the change that might not be minor: what would happen if I passed in both current_other=True and diverged=True? Would I get an error, or would one of those arguments win? It seems like there should be a single 'status' argument which can take on different values like (just making these up) 'current', 'ubuntu_diverged' or 'upstream_diverged'. Maybe it's too late to change the method signature like this, but that would make this whole system a lot more comprehensible.

review: Approve
Revision history for this message
Henning Eggers (henninge) wrote :

Thank you for the review. I did not get to work on this any further because we reverted the recife branch from db-devel again, so this change got less urgent. I am finishing this now but will merge it into the recife branch (which will soon be merged into db-devel again, I expect).

> I approve with what are hopefully minor changes. Specifically, I found
> test_getPOTMsgSetDifferentTranslations very confusing. The comments and sample
> code are talking about "one side" and "both sides"--it would be easier for me
> to understand if you specified "upstream side but not Ubuntu side" and "both
> upstream and ubuntu sides", especially since the things you're testing are
> .is_current_ubuntu and .is_current_upstream.

I can see how this is confusing. I did two things: I added a note explaining about the situation in this test and I also added method that pick the right flag for "this side" and "other side" so that the whole test only uses those terms.

>
> You also use "diverged" vs. "changed" in that test without explaining the
> difference. I can almost figure out what you mean by looking at the test, but
> not quite because a) you never explained what "changed" means (on IRC you said
> it was an old term, so why still use it?)--what has changed?

I removed the term "changed" from the code, so this should be less confusing now.

> And it's not
> clear why setting diverged=True makes is_current_upstream True and
> is_current_ubuntu False, instead of vice versa.

Diverging a translation makes it the current translation on "this side" which in this case is "upstream". As mentioned earlier I made that clearer by removing direct references to "is_current_upstream" and "is_current_ubuntu".

> This is the change that might not be minor: what would happen if I passed in
> both current_other=True and diverged=True? Would I get an error, or would one
> of those arguments win?

No, that combination makes no sense and the factory method has an assertion for it.

> It seems like there should be a single 'status'
> argument which can take on different values like (just making these up)
> 'current', 'ubuntu_diverged' or 'upstream_diverged'. Maybe it's too late to
> change the method signature like this, but that would make this whole system a
> lot more comprehensible.

Well, maybe not too late but certainly not for this branch. Changing the factory signature would mean also changing a lot of tests that use it. Maybe we are missing some good documentation that explains the different states and such? This may be a Good Thing to improve in light of what is coming...

Cheers,
Henning

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/translations/browser/pofile.py'
--- lib/lp/translations/browser/pofile.py 2010-12-01 11:26:57 +0000
+++ lib/lp/translations/browser/pofile.py 2010-12-07 19:31:29 +0000
@@ -436,8 +436,13 @@
436 'translated': self.context.getPOTMsgSetTranslated,436 'translated': self.context.getPOTMsgSetTranslated,
437 'untranslated': self.context.getPOTMsgSetUntranslated,437 'untranslated': self.context.getPOTMsgSetUntranslated,
438 'new_suggestions': self.context.getPOTMsgSetWithNewSuggestions,438 'new_suggestions': self.context.getPOTMsgSetWithNewSuggestions,
439<<<<<<< TREE
439 'changed_in_launchpad':440 'changed_in_launchpad':
440 self.context.getPOTMsgSetChangedInLaunchpad,441 self.context.getPOTMsgSetChangedInLaunchpad,
442=======
443 'changed_in_ubuntu':
444 self.context.getPOTMsgSetDifferentTranslations,
445>>>>>>> MERGE-SOURCE
441 }446 }
442447
443 if self.show not in get_functions:448 if self.show not in get_functions:
@@ -964,8 +969,13 @@
964 'translated': self.context.getPOTMsgSetTranslated,969 'translated': self.context.getPOTMsgSetTranslated,
965 'untranslated': self.context.getPOTMsgSetUntranslated,970 'untranslated': self.context.getPOTMsgSetUntranslated,
966 'new_suggestions': self.context.getPOTMsgSetWithNewSuggestions,971 'new_suggestions': self.context.getPOTMsgSetWithNewSuggestions,
972<<<<<<< TREE
967 'changed_in_launchpad':973 'changed_in_launchpad':
968 self.context.getPOTMsgSetChangedInLaunchpad,974 self.context.getPOTMsgSetChangedInLaunchpad,
975=======
976 'changed_in_ubuntu':
977 self.context.getPOTMsgSetDifferentTranslations,
978>>>>>>> MERGE-SOURCE
969 }979 }
970980
971 if self.show not in get_functions:981 if self.show not in get_functions:
972982
=== modified file 'lib/lp/translations/doc/pofile.txt'
--- lib/lp/translations/doc/pofile.txt 2010-12-07 19:31:22 +0000
+++ lib/lp/translations/doc/pofile.txt 2010-12-07 19:31:29 +0000
@@ -46,7 +46,11 @@
46 >>> dummy_pofile.getPOTMsgSetTranslated().count()46 >>> dummy_pofile.getPOTMsgSetTranslated().count()
47 047 0
4848
49<<<<<<< TREE
49 >>> dummy_pofile.getPOTMsgSetChangedInLaunchpad().count()50 >>> dummy_pofile.getPOTMsgSetChangedInLaunchpad().count()
51=======
52 >>> dummy_pofile.getPOTMsgSetDifferentTranslations().count()
53>>>>>>> MERGE-SOURCE
50 054 0
5155
52 >>> dummy_pofile.getPOTMsgSetWithNewSuggestions().count()56 >>> dummy_pofile.getPOTMsgSetWithNewSuggestions().count()
5357
=== modified file 'lib/lp/translations/interfaces/pofile.py'
--- lib/lp/translations/interfaces/pofile.py 2010-12-01 11:26:57 +0000
+++ lib/lp/translations/interfaces/pofile.py 2010-12-07 19:31:29 +0000
@@ -181,11 +181,16 @@
181 """Get pot message sets with suggestions submitted after last review.181 """Get pot message sets with suggestions submitted after last review.
182 """182 """
183183
184<<<<<<< TREE
184 def getPOTMsgSetChangedInLaunchpad():185 def getPOTMsgSetChangedInLaunchpad():
185 """Get pot message sets changed through Launchpad in this PO file.186 """Get pot message sets changed through Launchpad in this PO file.
186187
187 'Changed in Launchpad' are only those which were translated when188 'Changed in Launchpad' are only those which were translated when
188 initially imported, but then got overridden in Launchpad.189 initially imported, but then got overridden in Launchpad.
190=======
191 def getPOTMsgSetDifferentTranslations():
192 """Get pot message sets with different translations on both sides.
193>>>>>>> MERGE-SOURCE
189 """194 """
190195
191 def getPOTMsgSetWithErrors():196 def getPOTMsgSetWithErrors():
192197
=== modified file 'lib/lp/translations/model/pofile.py'
--- lib/lp/translations/model/pofile.py 2010-12-07 19:31:22 +0000
+++ lib/lp/translations/model/pofile.py 2010-12-07 19:31:29 +0000
@@ -691,9 +691,15 @@
691 Return a tuple of SQL (clauses, clause_tables) to be used with691 Return a tuple of SQL (clauses, clause_tables) to be used with
692 POTMsgSet.select().692 POTMsgSet.select().
693 """693 """
694 flag_name = getUtility(ITranslationSideTraitsSet).getForTemplate(
695 self.potemplate).flag_name
694 clause_tables = ['TranslationTemplateItem', 'TranslationMessage']696 clause_tables = ['TranslationTemplateItem', 'TranslationMessage']
695 clauses = self._getClausesForPOFileMessages()697 clauses = self._getClausesForPOFileMessages()
698<<<<<<< TREE
696 clauses.append('TranslationMessage.is_current IS TRUE')699 clauses.append('TranslationMessage.is_current IS TRUE')
700=======
701 clauses.append('TranslationMessage.%s IS TRUE' % flag_name)
702>>>>>>> MERGE-SOURCE
697 self._appendCompletePluralFormsConditions(clauses)703 self._appendCompletePluralFormsConditions(clauses)
698704
699 # A message is current in this pofile if:705 # A message is current in this pofile if:
@@ -712,11 +718,19 @@
712 SELECT * FROM TranslationMessage AS diverged718 SELECT * FROM TranslationMessage AS diverged
713 WHERE719 WHERE
714 diverged.potemplate=%(potemplate)s AND720 diverged.potemplate=%(potemplate)s AND
721<<<<<<< TREE
715 diverged.is_current IS TRUE AND722 diverged.is_current IS TRUE AND
723=======
724 diverged.%(flag_name)s IS TRUE AND
725>>>>>>> MERGE-SOURCE
716 diverged.language = %(language)s AND726 diverged.language = %(language)s AND
717 diverged.potmsgset=TranslationMessage.potmsgset)''' % (727 diverged.potmsgset=TranslationMessage.potmsgset)''' % (
718 dict(language=quote(self.language),728 dict(
719 potemplate=quote(self.potemplate))),729 flag_name=flag_name,
730 language=quote(self.language),
731 potemplate=quote(self.potemplate),
732 )
733 ),
720 ]734 ]
721 shared_translation_query = ' AND '.join(shared_translation_clauses)735 shared_translation_query = ' AND '.join(shared_translation_clauses)
722736
@@ -768,23 +782,35 @@
768782
769 def getPOTMsgSetWithNewSuggestions(self):783 def getPOTMsgSetWithNewSuggestions(self):
770 """See `IPOFile`."""784 """See `IPOFile`."""
785 flag_name = getUtility(ITranslationSideTraitsSet).getForTemplate(
786 self.potemplate).flag_name
771 clauses = self._getClausesForPOFileMessages()787 clauses = self._getClausesForPOFileMessages()
772 msgstr_clause = make_plurals_sql_fragment(788 msgstr_clause = make_plurals_sql_fragment(
773 "TranslationMessage.msgstr%(form)d IS NOT NULL", "OR")789 "TranslationMessage.msgstr%(form)d IS NOT NULL", "OR")
774 clauses.extend([790 clauses.extend([
775 'TranslationTemplateItem.potmsgset = POTMsgSet.id',791 'TranslationTemplateItem.potmsgset = POTMsgSet.id',
792<<<<<<< TREE
776 'TranslationMessage.is_current IS NOT TRUE',793 'TranslationMessage.is_current IS NOT TRUE',
777 "(%s)" % msgstr_clause,794 "(%s)" % msgstr_clause,
795=======
796 'TranslationMessage.%s IS NOT TRUE' % flag_name,
797 "(%s)" % msgstr_clause
798>>>>>>> MERGE-SOURCE
778 ])799 ])
779800
780 diverged_translation_query = (801 diverged_translation_query = (
781 '''(SELECT COALESCE(diverged.date_reviewed, diverged.date_created)802 '''(SELECT COALESCE(diverged.date_reviewed, diverged.date_created)
782 FROM TranslationMessage AS diverged803 FROM TranslationMessage AS diverged
783 WHERE804 WHERE
805<<<<<<< TREE
784 diverged.is_current IS TRUE AND806 diverged.is_current IS TRUE AND
807=======
808 diverged.%(flag_name)s IS TRUE AND
809>>>>>>> MERGE-SOURCE
785 diverged.potemplate = %(potemplate)s AND810 diverged.potemplate = %(potemplate)s AND
786 diverged.language = %(language)s AND811 diverged.language = %(language)s AND
787 diverged.potmsgset=POTMsgSet.id)''' % dict(812 diverged.potmsgset=POTMsgSet.id)''' % dict(
813 flag_name=flag_name,
788 potemplate=quote(self.potemplate),814 potemplate=quote(self.potemplate),
789 language=quote(self.language)))815 language=quote(self.language)))
790816
@@ -792,10 +818,15 @@
792 '''(SELECT COALESCE(shared.date_reviewed, shared.date_created)818 '''(SELECT COALESCE(shared.date_reviewed, shared.date_created)
793 FROM TranslationMessage AS shared819 FROM TranslationMessage AS shared
794 WHERE820 WHERE
821<<<<<<< TREE
795 shared.is_current IS TRUE AND822 shared.is_current IS TRUE AND
823=======
824 shared.%(flag_name)s IS TRUE AND
825>>>>>>> MERGE-SOURCE
796 shared.potemplate IS NULL AND826 shared.potemplate IS NULL AND
797 shared.language = %(language)s AND827 shared.language = %(language)s AND
798 shared.potmsgset=POTMsgSet.id)''' % dict(828 shared.potmsgset=POTMsgSet.id)''' % dict(
829 flag_name=flag_name,
799 language=quote(self.language)))830 language=quote(self.language)))
800 beginning_of_time = "TIMESTAMP '1970-01-01 00:00:00'"831 beginning_of_time = "TIMESTAMP '1970-01-01 00:00:00'"
801 newer_than_query = (832 newer_than_query = (
@@ -818,41 +849,71 @@
818 return self._getOrderedPOTMsgSets(849 return self._getOrderedPOTMsgSets(
819 [POTMsgSet, TranslationTemplateItem], query)850 [POTMsgSet, TranslationTemplateItem], query)
820851
852<<<<<<< TREE
821 def getPOTMsgSetChangedInLaunchpad(self):853 def getPOTMsgSetChangedInLaunchpad(self):
854=======
855 def getPOTMsgSetDifferentTranslations(self):
856>>>>>>> MERGE-SOURCE
822 """See `IPOFile`."""857 """See `IPOFile`."""
858<<<<<<< TREE
823 # POT set has been changed in Launchpad if it contains active859 # POT set has been changed in Launchpad if it contains active
824 # translation which didn't come from a published package860 # translation which didn't come from a published package
825 # (iow, it's different from a published translation: this only861 # (iow, it's different from a published translation: this only
826 # lists translations which have actually changed in LP, not862 # lists translations which have actually changed in LP, not
827 # translations which are 'new' and only exist in LP).863 # translations which are 'new' and only exist in LP).
864=======
865 # A `POTMsgSet` has different translations if both sides have a
866 # translation. If one of them is empty, the POTMsgSet is not included
867 # in this list.
868>>>>>>> MERGE-SOURCE
828869
870<<<<<<< TREE
829 # TranslationMessage is changed if:871 # TranslationMessage is changed if:
830 # is_current IS TRUE, is_imported IS FALSE,872 # is_current IS TRUE, is_imported IS FALSE,
831 # (diverged AND not empty) OR (shared AND not empty AND no diverged)873 # (diverged AND not empty) OR (shared AND not empty AND no diverged)
832 # exists imported (is_imported AND not empty AND (diverged OR shared))874 # exists imported (is_imported AND not empty AND (diverged OR shared))
875=======
876>>>>>>> MERGE-SOURCE
833 clauses, clause_tables = self._getTranslatedMessagesQuery()877 clauses, clause_tables = self._getTranslatedMessagesQuery()
878 other_side_flag_name = getUtility(
879 ITranslationSideTraitsSet).getForTemplate(
880 self.potemplate).other_side_traits.flag_name
834 clauses.extend([881 clauses.extend([
835 'TranslationTemplateItem.potmsgset = POTMsgSet.id',882 'TranslationTemplateItem.potmsgset = POTMsgSet.id',
883<<<<<<< TREE
836 'TranslationMessage.is_imported IS FALSE',884 'TranslationMessage.is_imported IS FALSE',
885=======
886 'TranslationMessage.%s IS FALSE' % other_side_flag_name,
887>>>>>>> MERGE-SOURCE
837 ])888 ])
838889
839 imported_no_diverged = (890 imported_no_diverged = (
840 '''NOT EXISTS (891 '''NOT EXISTS (
841 SELECT * FROM TranslationMessage AS diverged892 SELECT * FROM TranslationMessage AS diverged
842 WHERE893 WHERE
894<<<<<<< TREE
843 diverged.is_imported IS TRUE AND895 diverged.is_imported IS TRUE AND
896=======
897 diverged.%(flag_name)s IS TRUE AND
898>>>>>>> MERGE-SOURCE
844 diverged.id <> imported.id AND899 diverged.id <> imported.id AND
845 diverged.potemplate = %(potemplate)s AND900 diverged.potemplate = %(potemplate)s AND
846 diverged.language = %(language)s AND901 diverged.language = %(language)s AND
847 diverged.potmsgset=TranslationMessage.potmsgset)''' % (902 diverged.potmsgset=TranslationMessage.potmsgset)''' % (
848 dict(potemplate=quote(self.potemplate),903 dict(
849 language=quote(self.language))))904 flag_name=other_side_flag_name,
850905 potemplate=quote(self.potemplate),
906 language=quote(self.language))
907 ))
851 imported_clauses = [908 imported_clauses = [
852 'imported.id <> TranslationMessage.id',909 'imported.id <> TranslationMessage.id',
853 'imported.potmsgset = POTMsgSet.id',910 'imported.potmsgset = POTMsgSet.id',
854 'imported.language = %s' % sqlvalues(self.language),911 'imported.language = %s' % sqlvalues(self.language),
912<<<<<<< TREE
855 'imported.is_imported IS TRUE',913 'imported.is_imported IS TRUE',
914=======
915 'imported.%s IS TRUE' % other_side_flag_name,
916>>>>>>> MERGE-SOURCE
856 '(imported.potemplate=%s OR ' % sqlvalues(self.potemplate) +917 '(imported.potemplate=%s OR ' % sqlvalues(self.potemplate) +
857 ' (imported.potemplate IS NULL AND ' + imported_no_diverged918 ' (imported.potemplate IS NULL AND ' + imported_no_diverged
858 + ' ))',919 + ' ))',
@@ -1506,11 +1567,15 @@
1506 """See `IPOFile`."""1567 """See `IPOFile`."""
1507 return EmptyResultSet()1568 return EmptyResultSet()
15081569
1570<<<<<<< TREE
1509 def getPOTMsgSetChangedInLaunchpad(self):1571 def getPOTMsgSetChangedInLaunchpad(self):
1510 """See `IPOFile`."""1572 """See `IPOFile`."""
1511 return EmptyResultSet()1573 return EmptyResultSet()
15121574
1513 def getPOTMsgSetWithErrors(self):1575 def getPOTMsgSetWithErrors(self):
1576=======
1577 def getPOTMsgSetDifferentTranslations(self):
1578>>>>>>> MERGE-SOURCE
1514 """See `IPOFile`."""1579 """See `IPOFile`."""
1515 return EmptyResultSet()1580 return EmptyResultSet()
15161581
15171582
=== modified file 'lib/lp/translations/tests/test_pofile.py'
--- lib/lp/translations/tests/test_pofile.py 2010-12-07 19:31:22 +0000
+++ lib/lp/translations/tests/test_pofile.py 2010-12-07 19:31:29 +0000
@@ -54,6 +54,175 @@
54 ITranslationsPerson(person).translations_relicensing_agreement = choice54 ITranslationsPerson(person).translations_relicensing_agreement = choice
5555
5656
57<<<<<<< TREE
58=======
59class TestTranslationSharedPOFileSourcePackage(TestCaseWithFactory):
60 """Test behavior of PO files with shared POTMsgSets on a source package.
61 """
62
63 layer = ZopelessDatabaseLayer
64
65 def setUp(self):
66 # Create a product with two series and a shared POTemplate
67 # in different series ('devel' and 'stable').
68 super(TestTranslationSharedPOFileSourcePackage, self).setUp()
69 self.foo = self.factory.makeDistribution()
70 self.foo_devel = self.factory.makeDistroSeries(
71 name='devel', distribution=self.foo)
72 self.foo_stable = self.factory.makeDistroSeries(
73 name='stable', distribution=self.foo)
74 self.foo.official_rosetta = True
75 self.sourcepackagename = self.factory.makeSourcePackageName()
76
77 # Two POTemplates share translations if they have the same name,
78 # in this case 'messages'.
79 self.devel_potemplate = self.factory.makePOTemplate(
80 distroseries=self.foo_devel,
81 sourcepackagename=self.sourcepackagename,
82 name="messages")
83 self.stable_potemplate = self.factory.makePOTemplate(
84 distroseries=self.foo_stable,
85 sourcepackagename=self.sourcepackagename,
86 name="messages")
87
88 # We'll use two PO files, one for each series.
89 self.devel_pofile = self.factory.makePOFile(
90 'sr', self.devel_potemplate)
91 self.stable_pofile = self.factory.makePOFile(
92 'sr', self.stable_potemplate)
93
94 # The POTMsgSet is added to only one of the POTemplates.
95 self.potmsgset = self.factory.makePOTMsgSet(
96 self.devel_potemplate, sequence=1)
97
98 def test_getPOTMsgSetWithNewSuggestions_shared(self):
99 # Test listing of suggestions for POTMsgSets with a shared
100 # translation.
101
102 # A POTMsgSet has a shared, current translation created 5 days ago.
103 date_created = datetime.now(pytz.UTC) - timedelta(5)
104 translation = self.factory.makeSuggestion(
105 pofile=self.devel_pofile, potmsgset=self.potmsgset,
106 translations=[u"Translation"], date_created=date_created)
107 translation.is_current_ubuntu = True
108
109 # When there are no suggestions, nothing is returned.
110 found_translations = list(
111 self.devel_pofile.getPOTMsgSetWithNewSuggestions())
112 self.assertEquals(found_translations, [])
113
114 # When a suggestion is added one day after, the potmsgset is returned.
115 suggestion_date = date_created + timedelta(1)
116 suggestion = self.factory.makeSuggestion(
117 pofile=self.devel_pofile, potmsgset=self.potmsgset,
118 translations=[u"Suggestion"], date_created=suggestion_date)
119 self.assertEquals(suggestion.is_current_ubuntu, False)
120
121 found_translations = list(
122 self.devel_pofile.getPOTMsgSetWithNewSuggestions())
123 self.assertEquals(found_translations, [self.potmsgset])
124
125 # Setting a suggestion as current makes it have no unreviewed
126 # suggestions.
127 # XXX henninge 2010-08-17: It looks like this test passes by
128 # accident as the suggestion already is the newest translation
129 # available. Other tests may be passing just by accident, too.
130 # This will have to be investigated when all bits and pieces are in
131 # place.
132 translation.is_current_ubuntu = False
133 suggestion.is_current_ubuntu = True
134 found_translations = list(
135 self.devel_pofile.getPOTMsgSetWithNewSuggestions())
136 self.assertEquals(found_translations, [])
137
138 # And adding another suggestion 2 days later, the potmsgset is
139 # again returned.
140 suggestion_date += timedelta(2)
141 translation = self.factory.makeSuggestion(
142 pofile=self.devel_pofile, potmsgset=self.potmsgset,
143 translations=[u"New suggestion"], date_created=suggestion_date)
144 self.assertEquals(translation.is_current_ubuntu, False)
145
146 found_translations = list(
147 self.devel_pofile.getPOTMsgSetWithNewSuggestions())
148 self.assertEquals(found_translations, [self.potmsgset])
149
150 def test_getPOTMsgSetWithNewSuggestions_diverged(self):
151 # Test listing of suggestions for POTMsgSets with a shared
152 # translation and a later diverged one.
153
154 # First we create a shared translation (5 days old), a diverged
155 # translation 1 day later.
156 # Then we make sure that getting unreviewed messages works when:
157 # * A suggestion is added 1 day after (shows as unreviewed).
158 # * A new diverged translation is added another day later (nothing).
159 # * A new suggestion is added after another day (shows).
160 # * Suggestion is made active (nothing).
161
162 # A POTMsgSet has a shared, current translation created 5 days ago.
163 date_created = datetime.now(pytz.UTC) - timedelta(5)
164 translation = self.factory.makeSuggestion(
165 pofile=self.devel_pofile, potmsgset=self.potmsgset,
166 translations=[u"Shared translation"], date_created=date_created)
167 translation.is_current_ubuntu = True
168
169 # And we also have a diverged translation created a day after a shared
170 # current translation.
171 diverged_date = date_created + timedelta(1)
172 diverged_translation = self.factory.makeSuggestion(
173 pofile=self.devel_pofile, potmsgset=self.potmsgset,
174 translations=[u"Old translation"], date_created=diverged_date)
175 diverged_translation.potemplate = self.devel_potemplate
176 diverged_translation.is_current_ubuntu = True
177
178 # There is also a suggestion against the shared translation
179 # created 2 days after the shared translation.
180 suggestion_date = date_created + timedelta(2)
181 suggestion = self.factory.makeSuggestion(
182 pofile=self.devel_pofile, potmsgset=self.potmsgset,
183 translations=[u"Shared suggestion"], date_created=suggestion_date)
184 self.assertEquals(suggestion.is_current_ubuntu, False)
185
186 # A suggestion is shown since diverged_date < suggestion_date.
187 found_translations = list(
188 self.devel_pofile.getPOTMsgSetWithNewSuggestions())
189 self.assertEquals(found_translations, [self.potmsgset])
190
191 # When a diverged translation is added after the shared suggestion,
192 # there are no unreviewed suggestions.
193 diverged_date = suggestion_date + timedelta(1)
194 diverged_translation_2 = self.factory.makeCurrentTranslationMessage(
195 pofile=self.devel_pofile, potmsgset=self.potmsgset,
196 translations=[u"Translation"], date_created=diverged_date,
197 date_reviewed=diverged_date, diverged=True)
198 diverged_translation.is_current_ubuntu = False
199 diverged_translation_2.potemplate = self.devel_potemplate
200 diverged_translation_2.is_current_ubuntu = True
201 found_translations = list(
202 self.devel_pofile.getPOTMsgSetWithNewSuggestions())
203 self.assertEquals(found_translations, [])
204
205 # When a suggestion is added one day after, the potmsgset is returned.
206 suggestion_date = diverged_date + timedelta(1)
207 suggestion = self.factory.makeSuggestion(
208 pofile=self.devel_pofile, potmsgset=self.potmsgset,
209 translations=[u"Suggestion"], date_created=suggestion_date)
210 self.assertEquals(suggestion.is_current_ubuntu, False)
211
212 found_translations = list(
213 self.devel_pofile.getPOTMsgSetWithNewSuggestions())
214 self.assertEquals(found_translations, [self.potmsgset])
215
216 # Setting a suggestion as current makes it have no unreviewed
217 # suggestions.
218 translation.is_current_ubuntu = False
219 suggestion.is_current_ubuntu = True
220 found_translations = list(
221 self.devel_pofile.getPOTMsgSetWithNewSuggestions())
222 self.assertEquals(found_translations, [])
223
224
225>>>>>>> MERGE-SOURCE
57class TestTranslationSharedPOFile(TestCaseWithFactory):226class TestTranslationSharedPOFile(TestCaseWithFactory):
58 """Test behaviour of PO files with shared POTMsgSets."""227 """Test behaviour of PO files with shared POTMsgSets."""
59228
@@ -134,16 +303,26 @@
134 self.assertEquals(found_potmsgsets, [plural_potmsgset])303 self.assertEquals(found_potmsgsets, [plural_potmsgset])
135304
136 # Search translations as well.305 # Search translations as well.
306<<<<<<< TREE
137 self.factory.makeTranslationMessage(307 self.factory.makeTranslationMessage(
138 pofile=self.devel_sr_pofile, potmsgset=potmsgset,308 pofile=self.devel_sr_pofile, potmsgset=potmsgset,
309=======
310 self.factory.makeCurrentTranslationMessage(
311 pofile=self.devel_pofile, potmsgset=potmsgset,
312>>>>>>> MERGE-SOURCE
139 translations=[u"One translation message"])313 translations=[u"One translation message"])
140 found_potmsgsets = list(314 found_potmsgsets = list(
141 self.devel_sr_pofile.findPOTMsgSetsContaining(u"translation"))315 self.devel_sr_pofile.findPOTMsgSetsContaining(u"translation"))
142 self.assertEquals(found_potmsgsets, [potmsgset])316 self.assertEquals(found_potmsgsets, [potmsgset])
143317
144 # Search matches all plural forms.318 # Search matches all plural forms.
319<<<<<<< TREE
145 self.factory.makeTranslationMessage(320 self.factory.makeTranslationMessage(
146 pofile=self.devel_sr_pofile, potmsgset=plural_potmsgset,321 pofile=self.devel_sr_pofile, potmsgset=plural_potmsgset,
322=======
323 self.factory.makeCurrentTranslationMessage(
324 pofile=self.devel_pofile, potmsgset=plural_potmsgset,
325>>>>>>> MERGE-SOURCE
147 translations=[u"One translation message",326 translations=[u"One translation message",
148 u"Plural translation message",327 u"Plural translation message",
149 u"Third translation message"])328 u"Third translation message"])
@@ -183,8 +362,13 @@
183 self.assertEquals(found_translations, [])362 self.assertEquals(found_translations, [])
184363
185 # If 'submitter' provides a translation, it's returned in a list.364 # If 'submitter' provides a translation, it's returned in a list.
365<<<<<<< TREE
186 translation = self.factory.makeTranslationMessage(366 translation = self.factory.makeTranslationMessage(
187 pofile=self.devel_sr_pofile, potmsgset=potmsgset,367 pofile=self.devel_sr_pofile, potmsgset=potmsgset,
368=======
369 translation = self.factory.makeCurrentTranslationMessage(
370 pofile=self.devel_pofile, potmsgset=potmsgset,
371>>>>>>> MERGE-SOURCE
188 translations=[u"Translation message"],372 translations=[u"Translation message"],
189 translator=submitter)373 translator=submitter)
190 found_translations = list(374 found_translations = list(
@@ -194,8 +378,13 @@
194 # If somebody else provides a translation, it's not added to the378 # If somebody else provides a translation, it's not added to the
195 # list of submitter's translations.379 # list of submitter's translations.
196 someone_else = self.factory.makePerson()380 someone_else = self.factory.makePerson()
381<<<<<<< TREE
197 self.factory.makeTranslationMessage(382 self.factory.makeTranslationMessage(
198 pofile=self.devel_sr_pofile, potmsgset=potmsgset,383 pofile=self.devel_sr_pofile, potmsgset=potmsgset,
384=======
385 self.factory.makeCurrentTranslationMessage(
386 pofile=self.devel_pofile, potmsgset=potmsgset,
387>>>>>>> MERGE-SOURCE
199 translations=[u"Another translation"],388 translations=[u"Another translation"],
200 translator=someone_else)389 translator=someone_else)
201 found_translations = list(390 found_translations = list(
@@ -210,7 +399,7 @@
210399
211 self.devel_sr_latin_pofile = self.factory.makePOFile(400 self.devel_sr_latin_pofile = self.factory.makePOFile(
212 'sr@latin', potemplate=self.devel_potemplate)401 'sr@latin', potemplate=self.devel_potemplate)
213 self.factory.makeTranslationMessage(402 self.factory.makeCurrentTranslationMessage(
214 pofile=self.devel_sr_latin_pofile, potmsgset=potmsgset,403 pofile=self.devel_sr_latin_pofile, potmsgset=potmsgset,
215 translations=[u"Yet another translation"],404 translations=[u"Yet another translation"],
216 translator=submitter)405 translator=submitter)
@@ -238,17 +427,29 @@
238 self.assertEquals(found_translations, [])427 self.assertEquals(found_translations, [])
239428
240 # When a diverged translation is added, the potmsgset is returned.429 # When a diverged translation is added, the potmsgset is returned.
430<<<<<<< TREE
241 self.factory.makeTranslationMessage(431 self.factory.makeTranslationMessage(
242 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,432 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
243 translations=[u"Translation"])433 translations=[u"Translation"])
434=======
435 self.factory.makeCurrentTranslationMessage(
436 pofile=self.devel_pofile, potmsgset=self.potmsgset,
437 translations=[u"Translation"], diverged=True)
438>>>>>>> MERGE-SOURCE
244 found_translations = list(439 found_translations = list(
245 self.devel_sr_pofile.getPOTMsgSetTranslated())440 self.devel_sr_pofile.getPOTMsgSetTranslated())
246 self.assertEquals(found_translations, [self.potmsgset])441 self.assertEquals(found_translations, [self.potmsgset])
247442
248 # If diverged translation is empty, POTMsgSet is not listed.443 # If diverged translation is empty, POTMsgSet is not listed.
444<<<<<<< TREE
249 self.factory.makeTranslationMessage(445 self.factory.makeTranslationMessage(
250 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,446 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
251 translations=[u""])447 translations=[u""])
448=======
449 self.factory.makeCurrentTranslationMessage(
450 pofile=self.devel_pofile, potmsgset=self.potmsgset,
451 translations=[u""], diverged=True)
452>>>>>>> MERGE-SOURCE
252 found_translations = list(453 found_translations = list(
253 self.devel_sr_pofile.getPOTMsgSetTranslated())454 self.devel_sr_pofile.getPOTMsgSetTranslated())
254 self.assertEquals(found_translations, [])455 self.assertEquals(found_translations, [])
@@ -258,8 +459,13 @@
258 # translation for the POTMsgSet as well.459 # translation for the POTMsgSet as well.
259460
260 # We create a shared translation first.461 # We create a shared translation first.
462<<<<<<< TREE
261 self.factory.makeSharedTranslationMessage(463 self.factory.makeSharedTranslationMessage(
262 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,464 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
465=======
466 self.factory.makeCurrentTranslationMessage(
467 pofile=self.devel_pofile, potmsgset=self.potmsgset,
468>>>>>>> MERGE-SOURCE
263 translations=[u"Shared translation"])469 translations=[u"Shared translation"])
264470
265 # When there is no diverged translation, shared one is returned.471 # When there is no diverged translation, shared one is returned.
@@ -268,17 +474,29 @@
268 self.assertEquals(found_translations, [self.potmsgset])474 self.assertEquals(found_translations, [self.potmsgset])
269475
270 # When an empty diverged translation is added, nothing is listed.476 # When an empty diverged translation is added, nothing is listed.
477<<<<<<< TREE
271 self.factory.makeTranslationMessage(478 self.factory.makeTranslationMessage(
272 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,479 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
273 translations=[u""])480 translations=[u""])
481=======
482 self.factory.makeCurrentTranslationMessage(
483 pofile=self.devel_pofile, potmsgset=self.potmsgset,
484 translations=[u""], diverged=True)
485>>>>>>> MERGE-SOURCE
274 found_translations = list(486 found_translations = list(
275 self.devel_sr_pofile.getPOTMsgSetTranslated())487 self.devel_sr_pofile.getPOTMsgSetTranslated())
276 self.assertEquals(found_translations, [])488 self.assertEquals(found_translations, [])
277489
278 # If diverged translation is non-empty, POTMsgSet is listed.490 # If diverged translation is non-empty, POTMsgSet is listed.
491<<<<<<< TREE
279 self.factory.makeTranslationMessage(492 self.factory.makeTranslationMessage(
280 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,493 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
281 translations=[u"Translation"])494 translations=[u"Translation"])
495=======
496 self.factory.makeCurrentTranslationMessage(
497 pofile=self.devel_pofile, potmsgset=self.potmsgset,
498 translations=[u"Translation"], diverged=True)
499>>>>>>> MERGE-SOURCE
282 found_translations = list(500 found_translations = list(
283 self.devel_sr_pofile.getPOTMsgSetTranslated())501 self.devel_sr_pofile.getPOTMsgSetTranslated())
284 self.assertEquals(found_translations, [self.potmsgset])502 self.assertEquals(found_translations, [self.potmsgset])
@@ -288,8 +506,13 @@
288 # empty shared translation for the POTMsgSet as well.506 # empty shared translation for the POTMsgSet as well.
289507
290 # We create an empty shared translation first.508 # We create an empty shared translation first.
509<<<<<<< TREE
291 self.factory.makeSharedTranslationMessage(510 self.factory.makeSharedTranslationMessage(
292 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,511 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
512=======
513 self.factory.makeCurrentTranslationMessage(
514 pofile=self.devel_pofile, potmsgset=self.potmsgset,
515>>>>>>> MERGE-SOURCE
293 translations=[u""])516 translations=[u""])
294517
295 # When there is no diverged translation, shared one is returned,518 # When there is no diverged translation, shared one is returned,
@@ -299,17 +522,29 @@
299 self.assertEquals(found_translations, [])522 self.assertEquals(found_translations, [])
300523
301 # When an empty diverged translation is added, nothing is listed.524 # When an empty diverged translation is added, nothing is listed.
525<<<<<<< TREE
302 self.factory.makeTranslationMessage(526 self.factory.makeTranslationMessage(
303 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,527 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
304 translations=[u""])528 translations=[u""])
529=======
530 self.factory.makeCurrentTranslationMessage(
531 pofile=self.devel_pofile, potmsgset=self.potmsgset,
532 translations=[u""], diverged=True)
533>>>>>>> MERGE-SOURCE
305 found_translations = list(534 found_translations = list(
306 self.devel_sr_pofile.getPOTMsgSetTranslated())535 self.devel_sr_pofile.getPOTMsgSetTranslated())
307 self.assertEquals(found_translations, [])536 self.assertEquals(found_translations, [])
308537
309 # If diverged translation is non-empty, POTMsgSet is listed.538 # If diverged translation is non-empty, POTMsgSet is listed.
539<<<<<<< TREE
310 self.factory.makeTranslationMessage(540 self.factory.makeTranslationMessage(
311 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,541 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
312 translations=[u"Translation"])542 translations=[u"Translation"])
543=======
544 self.factory.makeCurrentTranslationMessage(
545 pofile=self.devel_pofile, potmsgset=self.potmsgset,
546 translations=[u"Translation"], diverged=True)
547>>>>>>> MERGE-SOURCE
313 found_translations = list(548 found_translations = list(
314 self.devel_sr_pofile.getPOTMsgSetTranslated())549 self.devel_sr_pofile.getPOTMsgSetTranslated())
315 self.assertEquals(found_translations, [self.potmsgset])550 self.assertEquals(found_translations, [self.potmsgset])
@@ -319,17 +554,28 @@
319 # translated message.554 # translated message.
320555
321 # Add a diverged translation on the included POTMsgSet...556 # Add a diverged translation on the included POTMsgSet...
557<<<<<<< TREE
322 self.factory.makeTranslationMessage(558 self.factory.makeTranslationMessage(
323 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,559 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
324 translations=[u"Diverged translation"])560 translations=[u"Diverged translation"])
561=======
562 self.factory.makeCurrentTranslationMessage(
563 pofile=self.devel_pofile, potmsgset=self.potmsgset,
564 translations=[u"Diverged translation"], diverged=True)
565>>>>>>> MERGE-SOURCE
325566
326 # and a shared translation on newly added POTMsgSet...567 # and a shared translation on newly added POTMsgSet...
327 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate,568 potmsgset = self.factory.makePOTMsgSet(self.devel_potemplate,
328 u"Translated text")569 u"Translated text")
329 potmsgset.setSequence(self.devel_potemplate, 2)570 potmsgset.setSequence(self.devel_potemplate, 2)
330571
572<<<<<<< TREE
331 self.factory.makeSharedTranslationMessage(573 self.factory.makeSharedTranslationMessage(
332 pofile=self.devel_sr_pofile, potmsgset=potmsgset,574 pofile=self.devel_sr_pofile, potmsgset=potmsgset,
575=======
576 self.factory.makeCurrentTranslationMessage(
577 pofile=self.devel_pofile, potmsgset=potmsgset,
578>>>>>>> MERGE-SOURCE
333 translations=[u"Shared translation"])579 translations=[u"Shared translation"])
334580
335 # Both POTMsgSets are listed.581 # Both POTMsgSets are listed.
@@ -347,17 +593,29 @@
347 self.assertEquals(found_translations, [self.potmsgset])593 self.assertEquals(found_translations, [self.potmsgset])
348594
349 # When a diverged translation is added, the potmsgset is returned.595 # When a diverged translation is added, the potmsgset is returned.
596<<<<<<< TREE
350 self.factory.makeTranslationMessage(597 self.factory.makeTranslationMessage(
351 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,598 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
352 translations=[u"Translation"])599 translations=[u"Translation"])
600=======
601 self.factory.makeCurrentTranslationMessage(
602 pofile=self.devel_pofile, potmsgset=self.potmsgset,
603 translations=[u"Translation"], diverged=True)
604>>>>>>> MERGE-SOURCE
353 found_translations = list(605 found_translations = list(
354 self.devel_sr_pofile.getPOTMsgSetUntranslated())606 self.devel_sr_pofile.getPOTMsgSetUntranslated())
355 self.assertEquals(found_translations, [])607 self.assertEquals(found_translations, [])
356608
357 # If diverged translation is empty, POTMsgSet is not listed.609 # If diverged translation is empty, POTMsgSet is not listed.
610<<<<<<< TREE
358 self.factory.makeTranslationMessage(611 self.factory.makeTranslationMessage(
359 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,612 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
360 translations=[u""])613 translations=[u""])
614=======
615 self.factory.makeCurrentTranslationMessage(
616 pofile=self.devel_pofile, potmsgset=self.potmsgset,
617 translations=[u""], diverged=True)
618>>>>>>> MERGE-SOURCE
361 found_translations = list(619 found_translations = list(
362 self.devel_sr_pofile.getPOTMsgSetUntranslated())620 self.devel_sr_pofile.getPOTMsgSetUntranslated())
363 self.assertEquals(found_translations, [self.potmsgset])621 self.assertEquals(found_translations, [self.potmsgset])
@@ -367,8 +625,13 @@
367 # translation for the POTMsgSet as well.625 # translation for the POTMsgSet as well.
368626
369 # We create a shared translation first.627 # We create a shared translation first.
628<<<<<<< TREE
370 self.factory.makeSharedTranslationMessage(629 self.factory.makeSharedTranslationMessage(
371 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,630 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
631=======
632 self.factory.makeCurrentTranslationMessage(
633 pofile=self.devel_pofile, potmsgset=self.potmsgset,
634>>>>>>> MERGE-SOURCE
372 translations=[u"Shared translation"])635 translations=[u"Shared translation"])
373636
374 # When there is no diverged translation, shared one is returned.637 # When there is no diverged translation, shared one is returned.
@@ -377,17 +640,29 @@
377 self.assertEquals(found_translations, [])640 self.assertEquals(found_translations, [])
378641
379 # When an empty diverged translation is added, nothing is listed.642 # When an empty diverged translation is added, nothing is listed.
643<<<<<<< TREE
380 self.factory.makeTranslationMessage(644 self.factory.makeTranslationMessage(
381 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,645 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
382 translations=[u""])646 translations=[u""])
647=======
648 self.factory.makeCurrentTranslationMessage(
649 pofile=self.devel_pofile, potmsgset=self.potmsgset,
650 translations=[u""], diverged=True)
651>>>>>>> MERGE-SOURCE
383 found_translations = list(652 found_translations = list(
384 self.devel_sr_pofile.getPOTMsgSetUntranslated())653 self.devel_sr_pofile.getPOTMsgSetUntranslated())
385 self.assertEquals(found_translations, [self.potmsgset])654 self.assertEquals(found_translations, [self.potmsgset])
386655
387 # If diverged translation is non-empty, POTMsgSet is listed.656 # If diverged translation is non-empty, POTMsgSet is listed.
657<<<<<<< TREE
388 self.factory.makeTranslationMessage(658 self.factory.makeTranslationMessage(
389 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,659 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
390 translations=[u"Translation"])660 translations=[u"Translation"])
661=======
662 self.factory.makeCurrentTranslationMessage(
663 pofile=self.devel_pofile, potmsgset=self.potmsgset,
664 translations=[u"Translation"], diverged=True)
665>>>>>>> MERGE-SOURCE
391 found_translations = list(666 found_translations = list(
392 self.devel_sr_pofile.getPOTMsgSetUntranslated())667 self.devel_sr_pofile.getPOTMsgSetUntranslated())
393 self.assertEquals(found_translations, [])668 self.assertEquals(found_translations, [])
@@ -397,8 +672,13 @@
397 # empty shared translation for the POTMsgSet as well.672 # empty shared translation for the POTMsgSet as well.
398673
399 # We create an empty shared translation first.674 # We create an empty shared translation first.
675<<<<<<< TREE
400 self.factory.makeSharedTranslationMessage(676 self.factory.makeSharedTranslationMessage(
401 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,677 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
678=======
679 self.factory.makeCurrentTranslationMessage(
680 pofile=self.devel_pofile, potmsgset=self.potmsgset,
681>>>>>>> MERGE-SOURCE
402 translations=[u""])682 translations=[u""])
403683
404 # When there is no diverged translation, shared one is returned,684 # When there is no diverged translation, shared one is returned,
@@ -408,17 +688,29 @@
408 self.assertEquals(found_translations, [self.potmsgset])688 self.assertEquals(found_translations, [self.potmsgset])
409689
410 # When an empty diverged translation is added, nothing is listed.690 # When an empty diverged translation is added, nothing is listed.
691<<<<<<< TREE
411 self.factory.makeTranslationMessage(692 self.factory.makeTranslationMessage(
412 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,693 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
413 translations=[u""])694 translations=[u""])
695=======
696 self.factory.makeCurrentTranslationMessage(
697 pofile=self.devel_pofile, potmsgset=self.potmsgset,
698 translations=[u""], diverged=True)
699>>>>>>> MERGE-SOURCE
414 found_translations = list(700 found_translations = list(
415 self.devel_sr_pofile.getPOTMsgSetUntranslated())701 self.devel_sr_pofile.getPOTMsgSetUntranslated())
416 self.assertEquals(found_translations, [self.potmsgset])702 self.assertEquals(found_translations, [self.potmsgset])
417703
418 # If diverged translation is non-empty, POTMsgSet is listed.704 # If diverged translation is non-empty, POTMsgSet is listed.
705<<<<<<< TREE
419 self.factory.makeTranslationMessage(706 self.factory.makeTranslationMessage(
420 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,707 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
421 translations=[u"Translation"])708 translations=[u"Translation"])
709=======
710 self.factory.makeCurrentTranslationMessage(
711 pofile=self.devel_pofile, potmsgset=self.potmsgset,
712 translations=[u"Translation"], diverged=True)
713>>>>>>> MERGE-SOURCE
422 found_translations = list(714 found_translations = list(
423 self.devel_sr_pofile.getPOTMsgSetUntranslated())715 self.devel_sr_pofile.getPOTMsgSetUntranslated())
424 self.assertEquals(found_translations, [])716 self.assertEquals(found_translations, [])
@@ -428,8 +720,13 @@
428 # untranslated message.720 # untranslated message.
429721
430 # Add an empty translation to the included POTMsgSet...722 # Add an empty translation to the included POTMsgSet...
723<<<<<<< TREE
431 self.factory.makeTranslationMessage(724 self.factory.makeTranslationMessage(
432 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,725 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
726=======
727 self.factory.makeCurrentTranslationMessage(
728 pofile=self.devel_pofile, potmsgset=self.potmsgset,
729>>>>>>> MERGE-SOURCE
433 translations=[u""])730 translations=[u""])
434731
435 # ...and a new untranslated POTMsgSet.732 # ...and a new untranslated POTMsgSet.
@@ -589,9 +886,16 @@
589 u"Translated text")886 u"Translated text")
590 potmsgset.setSequence(self.devel_potemplate, 2)887 potmsgset.setSequence(self.devel_potemplate, 2)
591 date_created = datetime.now(pytz.UTC) - timedelta(5)888 date_created = datetime.now(pytz.UTC) - timedelta(5)
889<<<<<<< TREE
592 self.factory.makeTranslationMessage(890 self.factory.makeTranslationMessage(
593 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,891 pofile=self.devel_sr_pofile, potmsgset=self.potmsgset,
594 translations=[u"Translation"], date_updated=date_created)892 translations=[u"Translation"], date_updated=date_created)
893=======
894 self.factory.makeCurrentTranslationMessage(
895 pofile=self.devel_pofile, potmsgset=self.potmsgset,
896 translations=[u"Translation"],
897 date_created=date_created, date_reviewed=date_created)
898>>>>>>> MERGE-SOURCE
595 suggestion_date = date_created + timedelta(1)899 suggestion_date = date_created + timedelta(1)
596 self.factory.makeTranslationMessage(900 self.factory.makeTranslationMessage(
597 pofile=self.devel_sr_pofile, potmsgset=potmsgset,901 pofile=self.devel_sr_pofile, potmsgset=potmsgset,
@@ -638,6 +942,7 @@
638 self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())942 self.devel_sr_pofile.getPOTMsgSetWithNewSuggestions())
639 self.assertEquals([], found_translations)943 self.assertEquals([], found_translations)
640944
945<<<<<<< TREE
641 def test_getPOTMsgSetChangedInLaunchpad(self):946 def test_getPOTMsgSetChangedInLaunchpad(self):
642 # Test listing of POTMsgSets which contain changes from imports.947 # Test listing of POTMsgSets which contain changes from imports.
643948
@@ -779,6 +1084,73 @@
779 found_translations = list(1084 found_translations = list(
780 self.devel_sr_pofile.getPOTMsgSetWithErrors())1085 self.devel_sr_pofile.getPOTMsgSetWithErrors())
781 self.assertEquals(found_translations, [self.potmsgset])1086 self.assertEquals(found_translations, [self.potmsgset])
1087=======
1088 def _getThisSideFlag(self, translation_message):
1089 """Return the value of the "is_current_*" flag on this side."""
1090 traits = getUtility(ITranslationSideTraitsSet).getForTemplate(
1091 self.devel_potemplate)
1092 return traits.getFlag(translation_message)
1093
1094 def _getOtherSideFlag(self, translation_message):
1095 """Return the value of the "is_current_*" flag on the other side."""
1096 traits = getUtility(ITranslationSideTraitsSet).getForTemplate(
1097 self.devel_potemplate).other_side_traits
1098 return traits.getFlag(translation_message)
1099
1100 def test_getPOTMsgSetDifferentTranslations(self):
1101 # Test listing of POTMsgSets which have different translations on
1102 # both sides.
1103 # This test case is set up with templates and pofiles linked to
1104 # product series, therefore they are "upstream" files. As a
1105 # consequence "this side" in this test refers to "upstream" and
1106 # "other side" refers to "ubuntu" translations. We keep the generic
1107 # terms, though, because the behavior is symmetrical.
1108
1109 # If there are no translations on either side, nothing is listed.
1110 found_translations = list(
1111 self.devel_pofile.getPOTMsgSetDifferentTranslations())
1112 self.assertEquals(found_translations, [])
1113
1114 # Adding a current translation on one side doesn't change anything.
1115 translation = self.factory.makeCurrentTranslationMessage(
1116 pofile=self.devel_pofile, potmsgset=self.potmsgset,
1117 translations=[u"This side translation"])
1118 self.assertEquals(self._getThisSideFlag(translation), True)
1119 self.assertEquals(self._getOtherSideFlag(translation), False)
1120 found_translations = list(
1121 self.devel_pofile.getPOTMsgSetDifferentTranslations())
1122 self.assertEquals(found_translations, [])
1123
1124 # Adding a translation on both sides does not introduce a difference.
1125 translation = self.factory.makeCurrentTranslationMessage(
1126 pofile=self.devel_pofile, potmsgset=self.potmsgset,
1127 translations=[u"Both sides translation"], current_other=True)
1128 self.assertEquals(self._getThisSideFlag(translation), True)
1129 self.assertEquals(self._getOtherSideFlag(translation), True)
1130 found_translations = list(
1131 self.devel_pofile.getPOTMsgSetDifferentTranslations())
1132 self.assertEquals(found_translations, [])
1133
1134 # Adding a different translation on one side to creates a difference
1135 # between this side and the other side.
1136 translation = self.factory.makeCurrentTranslationMessage(
1137 pofile=self.devel_pofile, potmsgset=self.potmsgset,
1138 translations=[u"Different translation"])
1139 self.assertEquals(self._getThisSideFlag(translation), True)
1140 self.assertEquals(self._getOtherSideFlag(translation), False)
1141 found_translations = list(
1142 self.devel_pofile.getPOTMsgSetDifferentTranslations())
1143 self.assertEquals(found_translations, [self.potmsgset])
1144
1145 # A diverged translation is different, too.
1146 translation = self.factory.makeCurrentTranslationMessage(
1147 pofile=self.devel_pofile, potmsgset=self.potmsgset,
1148 translations=[u"Diverged translation"], diverged=True)
1149 self.assertEquals(self._getThisSideFlag(translation), True)
1150 self.assertEquals(self._getOtherSideFlag(translation), False)
1151 found_translations = list(
1152 self.devel_pofile.getPOTMsgSetDifferentTranslations())
1153 self.assertEquals(found_translations, [self.potmsgset])
7821154
783 def test_messageCount(self):1155 def test_messageCount(self):
784 # POFile.messageCount just forwards to POTmeplate.messageCount.1156 # POFile.messageCount just forwards to POTmeplate.messageCount.
@@ -789,6 +1161,7 @@
789 def test_initial_statistics_consistency(self):1161 def test_initial_statistics_consistency(self):
790 # A `POFile` starts out with consistent statistics.1162 # A `POFile` starts out with consistent statistics.
791 self.assertTrue(self.factory.makePOFile().testStatistics())1163 self.assertTrue(self.factory.makePOFile().testStatistics())
1164>>>>>>> MERGE-SOURCE
7921165
793 def test_updateStatistics(self):1166 def test_updateStatistics(self):
794 # Test that updating statistics keeps working.1167 # Test that updating statistics keeps working.
@@ -1107,12 +1480,22 @@
1107 def test_getPOTMsgSetTranslated_ordering(self):1480 def test_getPOTMsgSetTranslated_ordering(self):
1108 # Translate both POTMsgSets in devel_sr_pofile, so1481 # Translate both POTMsgSets in devel_sr_pofile, so
1109 # they are returned with getPOTMsgSetTranslated() call.1482 # they are returned with getPOTMsgSetTranslated() call.
1483<<<<<<< TREE
1110 self.factory.makeSharedTranslationMessage(1484 self.factory.makeSharedTranslationMessage(
1111 pofile=self.devel_sr_pofile,1485 pofile=self.devel_sr_pofile,
1486=======
1487 self.factory.makeCurrentTranslationMessage(
1488 pofile=self.devel_pofile,
1489>>>>>>> MERGE-SOURCE
1112 potmsgset=self.potmsgset1,1490 potmsgset=self.potmsgset1,
1113 translations=["Shared translation"])1491 translations=["Shared translation"])
1492<<<<<<< TREE
1114 self.factory.makeSharedTranslationMessage(1493 self.factory.makeSharedTranslationMessage(
1115 pofile=self.devel_sr_pofile,1494 pofile=self.devel_sr_pofile,
1495=======
1496 self.factory.makeCurrentTranslationMessage(
1497 pofile=self.devel_pofile,
1498>>>>>>> MERGE-SOURCE
1116 potmsgset=self.potmsgset2,1499 potmsgset=self.potmsgset2,
1117 translations=["Another shared translation"])1500 translations=["Another shared translation"])
11181501
@@ -1162,6 +1545,7 @@
1162 self.assertEquals(untranslated_potmsgsets,1545 self.assertEquals(untranslated_potmsgsets,
1163 [self.potmsgset1, self.potmsgset2])1546 [self.potmsgset1, self.potmsgset2])
11641547
1548<<<<<<< TREE
1165 def test_getPOTMsgSetChangedInLaunchpad_ordering(self):1549 def test_getPOTMsgSetChangedInLaunchpad_ordering(self):
1166 # Suggest a translation on both POTMsgSets in devel_sr_pofile,1550 # Suggest a translation on both POTMsgSets in devel_sr_pofile,
1167 # so they are returned with getPOTMsgSetWithNewSuggestions() call.1551 # so they are returned with getPOTMsgSetWithNewSuggestions() call.
@@ -1247,6 +1631,51 @@
1247 self.devel_sr_pofile.getPOTMsgSetWithErrors())1631 self.devel_sr_pofile.getPOTMsgSetWithErrors())
1248 self.assertEquals(potmsgsets,1632 self.assertEquals(potmsgsets,
1249 [self.potmsgset1, self.potmsgset2])1633 [self.potmsgset1, self.potmsgset2])
1634=======
1635 def test_getPOTMsgSetDifferentTranslations_ordering(self):
1636 # Suggest a translation on both POTMsgSets in devel_pofile,
1637 # so they are returned with getPOTMsgSetDifferentTranslations() call.
1638 self.factory.makeCurrentTranslationMessage(
1639 pofile=self.devel_pofile,
1640 potmsgset=self.potmsgset1,
1641 translations=["Both sides"],
1642 current_other=True)
1643 self.factory.makeCurrentTranslationMessage(
1644 pofile=self.devel_pofile,
1645 potmsgset=self.potmsgset1,
1646 translations=["This side"])
1647 self.factory.makeCurrentTranslationMessage(
1648 pofile=self.devel_pofile,
1649 potmsgset=self.potmsgset2,
1650 translations=["Both sides 2"],
1651 current_other=True)
1652 self.factory.makeCurrentTranslationMessage(
1653 pofile=self.devel_pofile,
1654 potmsgset=self.potmsgset2,
1655 translations=["This side 2"])
1656
1657 potmsgsets = list(
1658 self.devel_pofile.getPOTMsgSetDifferentTranslations())
1659 self.assertEquals(
1660 [self.potmsgset1, self.potmsgset2], potmsgsets)
1661
1662 # Insert these two POTMsgSets into self.stable_potemplate in reverse
1663 # order.
1664 self.potmsgset2.setSequence(self.stable_potemplate, 1)
1665 self.potmsgset1.setSequence(self.stable_potemplate, 2)
1666
1667 # And they are returned in the new order as desired.
1668 potmsgsets = list(
1669 self.stable_pofile.getPOTMsgSetDifferentTranslations())
1670 self.assertEquals(
1671 [self.potmsgset2, self.potmsgset1], potmsgsets)
1672
1673 # Order is unchanged for the previous template.
1674 potmsgsets = list(
1675 self.devel_pofile.getPOTMsgSetDifferentTranslations())
1676 self.assertEquals(
1677 [self.potmsgset1, self.potmsgset2], potmsgsets)
1678>>>>>>> MERGE-SOURCE
12501679
1251 def test_getPOTMsgSets_ordering(self):1680 def test_getPOTMsgSets_ordering(self):
1252 # Both POTMsgSets in devel_potemplate are untranslated.1681 # Both POTMsgSets in devel_potemplate are untranslated.
@@ -1278,12 +1707,22 @@
1278 # This test will go away when potmsgset.sequence goes away.1707 # This test will go away when potmsgset.sequence goes away.
12791708
1280 # Give the method something to search for.1709 # Give the method something to search for.
1710<<<<<<< TREE
1281 self.factory.makeSharedTranslationMessage(1711 self.factory.makeSharedTranslationMessage(
1282 pofile=self.devel_sr_pofile,1712 pofile=self.devel_sr_pofile,
1713=======
1714 self.factory.makeCurrentTranslationMessage(
1715 pofile=self.devel_pofile,
1716>>>>>>> MERGE-SOURCE
1283 potmsgset=self.potmsgset1,1717 potmsgset=self.potmsgset1,
1284 translations=["Shared translation"])1718 translations=["Shared translation"])
1719<<<<<<< TREE
1285 self.factory.makeSharedTranslationMessage(1720 self.factory.makeSharedTranslationMessage(
1286 pofile=self.devel_sr_pofile,1721 pofile=self.devel_sr_pofile,
1722=======
1723 self.factory.makeCurrentTranslationMessage(
1724 pofile=self.devel_pofile,
1725>>>>>>> MERGE-SOURCE
1287 potmsgset=self.potmsgset2,1726 potmsgset=self.potmsgset2,
1288 translations=["Another shared translation"])1727 translations=["Another shared translation"])
12891728
@@ -1854,23 +2293,23 @@
18542293
1855 def test_getTranslationMessages_current_shared(self):2294 def test_getTranslationMessages_current_shared(self):
1856 # A shared message is included in this POFile's messages.2295 # A shared message is included in this POFile's messages.
1857 message = self.factory.makeTranslationMessage(2296 message = self.factory.makeCurrentTranslationMessage(
1858 potmsgset=self.potmsgset, pofile=self.pofile, force_shared=True)2297 potmsgset=self.potmsgset, pofile=self.pofile)
18592298
1860 self.assertEqual(2299 self.assertEqual(
1861 [message], list(self.pofile.getTranslationMessages()))2300 [message], list(self.pofile.getTranslationMessages()))
18622301
1863 def test_getTranslationMessages_current_diverged(self):2302 def test_getTranslationMessages_current_diverged(self):
1864 # A diverged message is included in this POFile's messages.2303 # A diverged message is included in this POFile's messages.
1865 message = self.factory.makeTranslationMessage(2304 message = self.factory.makeCurrentTranslationMessage(
1866 potmsgset=self.potmsgset, pofile=self.pofile, force_diverged=True)2305 potmsgset=self.potmsgset, pofile=self.pofile, diverged=True)
18672306
1868 self.assertEqual(2307 self.assertEqual(
1869 [message], list(self.pofile.getTranslationMessages()))2308 [message], list(self.pofile.getTranslationMessages()))
18702309
1871 def test_getTranslationMessages_suggestion(self):2310 def test_getTranslationMessages_suggestion(self):
1872 # A suggestion is included in this POFile's messages.2311 # A suggestion is included in this POFile's messages.
1873 message = self.factory.makeTranslationMessage(2312 message = self.factory.makeSuggestion(
1874 potmsgset=self.potmsgset, pofile=self.pofile)2313 potmsgset=self.potmsgset, pofile=self.pofile)
18752314
1876 self.assertEqual(2315 self.assertEqual(
@@ -1880,8 +2319,8 @@
1880 # A message on an obsolete POTMsgSEt is included in this2319 # A message on an obsolete POTMsgSEt is included in this
1881 # POFile's messages.2320 # POFile's messages.
1882 potmsgset = self.factory.makePOTMsgSet(self.potemplate, sequence=0)2321 potmsgset = self.factory.makePOTMsgSet(self.potemplate, sequence=0)
1883 message = self.factory.makeTranslationMessage(2322 message = self.factory.makeCurrentTranslationMessage(
1884 potmsgset=potmsgset, pofile=self.pofile, force_shared=True)2323 potmsgset=potmsgset, pofile=self.pofile)
18852324
1886 self.assertEqual(2325 self.assertEqual(
1887 [message], list(self.pofile.getTranslationMessages()))2326 [message], list(self.pofile.getTranslationMessages()))
@@ -1889,7 +2328,7 @@
1889 def test_getTranslationMessages_other_pofile(self):2328 def test_getTranslationMessages_other_pofile(self):
1890 # A message from another POFiles is not included.2329 # A message from another POFiles is not included.
1891 other_pofile = self.factory.makePOFile('de')2330 other_pofile = self.factory.makePOFile('de')
1892 self.factory.makeTranslationMessage(2331 self.factory.makeCurrentTranslationMessage(
1893 potmsgset=self.potmsgset, pofile=other_pofile)2332 potmsgset=self.potmsgset, pofile=other_pofile)
18942333
1895 self.assertEqual([], list(self.pofile.getTranslationMessages()))2334 self.assertEqual([], list(self.pofile.getTranslationMessages()))
@@ -1897,8 +2336,8 @@
1897 def test_getTranslationMessages_condition_matches(self):2336 def test_getTranslationMessages_condition_matches(self):
1898 # A message matching the given condition is included.2337 # A message matching the given condition is included.
1899 # Diverged messages are linked to a specific POTemplate.2338 # Diverged messages are linked to a specific POTemplate.
1900 message = self.factory.makeTranslationMessage(2339 message = self.factory.makeCurrentTranslationMessage(
1901 potmsgset=self.potmsgset, pofile=self.pofile, force_diverged=True)2340 potmsgset=self.potmsgset, pofile=self.pofile, diverged=True)
19022341
1903 self.assertContentEqual(2342 self.assertContentEqual(
1904 [message],2343 [message],
@@ -1908,8 +2347,8 @@
1908 def test_getTranslationMessages_condition_matches_not(self):2347 def test_getTranslationMessages_condition_matches_not(self):
1909 # A message not matching the given condition is excluded.2348 # A message not matching the given condition is excluded.
1910 # Shared messages are not linked to a POTemplate.2349 # Shared messages are not linked to a POTemplate.
1911 self.factory.makeTranslationMessage(2350 self.factory.makeCurrentTranslationMessage(
1912 potmsgset=self.potmsgset, pofile=self.pofile, force_shared=True)2351 potmsgset=self.potmsgset, pofile=self.pofile)
19132352
1914 self.assertContentEqual(2353 self.assertContentEqual(
1915 [],2354 [],
@@ -1920,9 +2359,9 @@
1920 # A message matching given condition but located in another POFile2359 # A message matching given condition but located in another POFile
1921 # is not included.2360 # is not included.
1922 other_pofile = self.factory.makePOFile('de')2361 other_pofile = self.factory.makePOFile('de')
1923 self.factory.makeTranslationMessage(2362 self.factory.makeCurrentTranslationMessage(
1924 potmsgset=self.potmsgset, pofile=other_pofile,2363 potmsgset=self.potmsgset, pofile=other_pofile,
1925 force_diverged=True)2364 diverged=True)
19262365
1927 self.assertContentEqual(2366 self.assertContentEqual(
1928 [],2367 [],
@@ -1940,9 +2379,9 @@
1940 other_pofile = other_template.getPOFileByLang(2379 other_pofile = other_template.getPOFileByLang(
1941 self.pofile.language.code)2380 self.pofile.language.code)
1942 self.potmsgset.setSequence(other_template, 1)2381 self.potmsgset.setSequence(other_template, 1)
1943 self.factory.makeTranslationMessage(2382 self.factory.makeCurrentTranslationMessage(
1944 potmsgset=self.potmsgset, pofile=other_pofile,2383 potmsgset=self.potmsgset, pofile=other_pofile,
1945 force_diverged=True)2384 diverged=True)
19462385
1947 self.assertEqual([], list(self.pofile.getTranslationMessages()))2386 self.assertEqual([], list(self.pofile.getTranslationMessages()))
19482387
@@ -2687,3 +3126,48 @@
2687 potemplate=self.factory.makePOTemplate(3126 potemplate=self.factory.makePOTemplate(
2688 distroseries=package.distroseries,3127 distroseries=package.distroseries,
2689 sourcepackagename=package.sourcepackagename))3128 sourcepackagename=package.sourcepackagename))
3129
3130
3131class StatistcsFiltersTestScenario(StatisticsTestScenario):
3132 """Test the filter functions in `POFile`s compared to statistics."""
3133
3134 def exerciseFunction(self, pofile):
3135 """Run the function under test."""
3136 pofile.updateStatistics()
3137
3138 def getCurrentCount(self, pofile):
3139 return pofile.currentCount()
3140
3141 def getRosettaCount(self, pofile):
3142 return pofile.rosettaCount()
3143
3144 def getTranslatedCount(self, pofile):
3145 return pofile.getPOTMsgSetTranslated().count()
3146
3147 def getUnreviewedCount(self, pofile):
3148 return pofile.getPOTMsgSetWithNewSuggestions().count()
3149
3150 def getUntranslatedCount(self, pofile):
3151 return pofile.getPOTMsgSetUntranslated().count()
3152
3153 def getUpdatesCount(self, pofile):
3154 return pofile.getPOTMsgSetDifferentTranslations().count()
3155
3156
3157class TestUpstreamFilters(StatistcsFiltersTestScenario, TestCaseWithFactory):
3158 """Test filters on upstream `POFile`s."""
3159
3160 def makePOFile(self):
3161 return self.factory.makePOFile()
3162
3163
3164class TestUbuntuFilters(StatistcsFiltersTestScenario, TestCaseWithFactory):
3165 """Test filters on Ubuntu `POFile`s."""
3166
3167 def makePOFile(self):
3168 package = self.factory.makeSourcePackage()
3169 return self.factory.makePOFile(
3170 potemplate=self.factory.makePOTemplate(
3171 distroseries=package.distroseries,
3172 sourcepackagename=package.sourcepackagename))
3173

Subscribers

People subscribed via source and target branches

to status/vote changes: