Repository: translate/pootle

Issue:
Unmuting checks doesn't work
1. Open some unit that has muted checks
2. Unmute the check (the background will turn pink)
3. Reload the page

Expected: the unit will have the check unmuted

Observed: the unit has the check muted, and there's no record about unmuting the check in the history. Basically, it's a data loss issue.



Discussion:

Resolving patch:
diff --git a/pootle/apps/pootle_store/views.py b/pootle/apps/pootle_store/views.py
--- a/pootle/apps/pootle_store/views.py
+++ b/pootle/apps/pootle_store/views.py
@@ -720,8 +720,7 @@ def accept_suggestion(request, unit, suggid):
 @get_unit_context('review')
 def toggle_qualitycheck(request, unit, check_id):
     try:
-        unit.toggle_qualitycheck(check_id, bool(request.POST.get('mute')),
-                                 request.user)
+        unit.toggle_qualitycheck(check_id, 'mute' in request.POST, request.user)
     except ObjectDoesNotExist:
         raise Http404
 
diff --git a/pytest_pootle/utils.py b/pytest_pootle/utils.py
--- a/pytest_pootle/utils.py
+++ b/pytest_pootle/utils.py
@@ -95,13 +95,16 @@ def items_equal(left, right):
         return False
 
 
-def create_api_request(rf, method='get', url='/', data='', user=None):
+def create_api_request(rf, method='get', url='/', data='', user=None,
+                       encode_as_json=True):
     """Convenience function to create and setup fake requests."""
-    if data:
+    content_type = 'application/x-www-form-urlencoded'
+    if data and encode_as_json:
+        content_type = 'application/json'
         data = json.dumps(data)
 
     request_method = getattr(rf, method)
-    request = request_method(url, data=data, content_type='application/json')
+    request = request_method(url, data=data, content_type=content_type)
     request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
 
     if user is not None:


Test patch:
diff --git a/tests/views/unit.py b/tests/views/unit.py
--- a/tests/views/unit.py
+++ b/tests/views/unit.py
@@ -15,8 +15,9 @@
 from pootle.core.exceptions import Http400
 from pootle_app.models.permissions import check_permission
 from pootle_comment import get_model as get_comment_model
-from pootle_store.models import Suggestion, Unit, UNTRANSLATED
-from pootle_store.views import get_units
+from pootle_store.models import (QualityCheck, Suggestion, Unit, TRANSLATED,
+                                 UNTRANSLATED)
+from pootle_store.views import get_units, toggle_qualitycheck
 
 
 @pytest.mark.django_db
@@ -167,3 +168,29 @@ def test_reject_suggestion_with_comment(client, request_users):
                        .get().comment == comment)
     else:
         assert response.status_code == 403
+
+
+@pytest.mark.django_db
+def test_toggle_quality_check(rf, admin):
+    """Tests the view that mutes/unmutes quality checks."""
+    qc_filter = dict(
+        false_positive=False,
+        unit__state=TRANSLATED,
+        unit__store__translation_project__project__disabled=False,
+    )
+    qc = QualityCheck.objects.filter(**qc_filter).first()
+    unit = qc.unit
+
+    # Explicit POST data present, mute
+    data = 'mute='
+    request = create_api_request(rf, method='post', user=admin, data=data,
+                                 encode_as_json=False)
+    response = toggle_qualitycheck(request, unit.id, qc.id)
+    assert response.status_code == 200
+    assert QualityCheck.objects.get(id=qc.id).false_positive is True
+
+    # No POST data present, unmute
+    request = create_api_request(rf, method='post', user=admin)
+    response = toggle_qualitycheck(request, unit.id, qc.id)
+    assert response.status_code == 200
+    assert QualityCheck.objects.get(id=qc.id).false_positive is False