Skip to content

Commit

Permalink
Fix bug 1556680: Create instead of delete a TM entry on approve (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
mathjazz committed Jun 11, 2019
1 parent 783aee4 commit 58d4630
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion pontoon/base/models.py
Expand Up @@ -2885,7 +2885,16 @@ def approve(self, user):

self.save()

TranslationMemoryEntry.objects.filter(translation=self).delete()
if not self.memory_entries.exists():
TranslationMemoryEntry.objects.create(
source=self.entity.string,
target=self.string,
entity=self.entity,
translation=self,
locale=self.locale,
project=self.entity.resource.project,
)

self.entity.mark_changed(self.locale)

def unapprove(self, user):
Expand Down
8 changes: 5 additions & 3 deletions pontoon/base/tests/views/test_translation.py
Expand Up @@ -39,6 +39,7 @@ def test_approve_translation_basic(translation_a, client_superuser):
'paths': [],
'ignore_warnings': 'true',
}

response = client_superuser.post(url, params)
assert response.status_code == 400
assert response.content == 'Bad Request: Request must be AJAX'
Expand All @@ -48,9 +49,11 @@ def test_approve_translation_basic(translation_a, client_superuser):
HTTP_X_REQUESTED_WITH='XMLHttpRequest',
)
assert response.status_code == 200, response.content

translation_a.refresh_from_db()
assert translation_a.approved is True
assert translation_a.approved_user == response.wsgi_request.user
assert translation_a.memory_entries.exists() is True


@pytest.mark.django_db
Expand All @@ -59,7 +62,7 @@ def test_approve_translation_rejects_previous_approved(
translation_a,
client_superuser,
):
"""Check if approve view works properly."""
"""Check if previously approved translations get rejected on approve."""
url = reverse('pontoon.approve_translation')
params = {
'translation': translation_a.pk,
Expand All @@ -73,10 +76,9 @@ def test_approve_translation_rejects_previous_approved(
)

assert response.status_code == 200, response.content

approved_translation.refresh_from_db()
translation_a.refresh_from_db()

translation_a.refresh_from_db()
assert translation_a.approved is True
assert translation_a.active is True
assert approved_translation.approved is False
Expand Down

0 comments on commit 58d4630

Please sign in to comment.