Repository: translate/pootle

Issue:
Own suggestions are not accepted via submission of 100% match translations
Own suggestions are not counted when calculating similarity (refs. #3989). This causes the issue: own suggestion is not accepted when a user submits 100% match of the suggestion.

100% match suggestion is not highlighted on the screenshot below:
![image](https://cloud.githubusercontent.com/assets/682845/17446102/6565e00c-5b50-11e6-8475-5139f7758727.png)



Discussion:

Resolving patch:
diff --git a/pootle/apps/pootle_store/forms.py b/pootle/apps/pootle_store/forms.py
--- a/pootle/apps/pootle_store/forms.py
+++ b/pootle/apps/pootle_store/forms.py
@@ -318,6 +318,11 @@ def clean(self):
             if self.cleaned_data['suggestion']:
                 old_state = TRANSLATED
 
+                # Skip `TARGET` field submission if suggestion value is equal
+                # to submitted translation
+                if new_target == self.cleaned_data['suggestion'].target_f:
+                    self._updated_fields = []
+
             if (self.request is not None and
                 not check_permission('administrate', self.request) and
                 is_fuzzy):


Test patch:
diff --git a/tests/views/unit.py b/tests/views/unit.py
--- a/tests/views/unit.py
+++ b/tests/views/unit.py
@@ -17,6 +17,7 @@
 from pootle_comment import get_model as get_comment_model
 from pootle_store.models import (QualityCheck, Suggestion, Unit, TRANSLATED,
                                  UNTRANSLATED)
+from pootle_statistics.models import Submission, SubmissionTypes
 from pootle_store.views import get_units, toggle_qualitycheck
 
 
@@ -95,6 +96,48 @@ def test_submit_with_suggestion_and_comment(client, request_users, settings):
         assert response.status_code == 403
 
 
+@pytest.mark.django_db
+def test_submit_with_suggestion(client, request_users, settings):
+    """Tests translation can be applied after suggestion is accepted."""
+    settings.POOTLE_CAPTCHA_ENABLED = False
+    unit = Unit.objects.filter(suggestion__state='pending',
+                               state=UNTRANSLATED).first()
+    unit_submissions = Submission.objects.filter(unit=unit)
+    unit_submissions_count = unit_submissions.count()
+    sugg = Suggestion.objects.filter(unit=unit, state='pending').first()
+    user = request_users["user"]
+    if user.username != "nobody":
+        client.login(
+            username=user.username,
+            password=request_users["password"])
+
+    url = '/xhr/units/%d/' % unit.id
+
+    response = client.post(
+        url,
+        {
+            'state': False,
+            'target_f_0': sugg.target_f,
+            'suggestion': sugg.id,
+        },
+        HTTP_X_REQUESTED_WITH='XMLHttpRequest'
+    )
+
+    if check_permission('translate', response.wsgi_request):
+        assert response.status_code == 200
+        accepted_suggestion = Suggestion.objects.get(id=sugg.id)
+        updated_unit = Unit.objects.get(id=unit.id)
+        assert accepted_suggestion.state == 'accepted'
+        assert str(updated_unit.target) == sugg.target_f
+        unit_submissions = unit_submissions.exclude(
+            type=SubmissionTypes.SUGG_ACCEPT
+        )
+        assert (unit_submissions.count() - unit_submissions_count == 0)
+
+    else:
+        assert response.status_code == 403
+
+
 @pytest.mark.django_db
 def test_accept_suggestion_with_comment(client, request_users, settings):
     """Tests suggestion can be accepted with a comment."""