Commit 0eaf64d6 authored by Michal Čihař's avatar Michal Čihař

Factor out message editing

parent 46f33003
...@@ -143,24 +143,30 @@ class EditTest(ViewTestCase): ...@@ -143,24 +143,30 @@ class EditTest(ViewTestCase):
''' '''
Tests for manipulating translation. Tests for manipulating translation.
''' '''
def test_edit(self): def edit_unit(self, source, target):
translation = self.subproject.translation_set.get(language_code='cs') translation = self.subproject.translation_set.get(language_code='cs')
unit = translation.unit_set.get(source='Hello, world!\n') unit = translation.unit_set.get(source=source)
translate_url = reverse('translate', kwargs={ translate_url = reverse('translate', kwargs={
'project': self.subproject.project.slug, 'project': self.subproject.project.slug,
'subproject': self.subproject.slug, 'subproject': self.subproject.slug,
'lang': 'cs', 'lang': 'cs',
}) })
response = self.client.post( return self.client.post(
translate_url, translate_url,
{ {
'checksum': unit.checksum, 'checksum': unit.checksum,
'target': 'Nazdar svete!\n', 'target': target,
'type': 'all', 'type': 'all',
'dir': 'forward', 'dir': 'forward',
'pos': '1', 'pos': '1',
} }
) )
def test_edit(self):
response = self.edit_unit(
'Hello, world!\n',
'Nazdar svete!\n'
)
# We should get to second message # We should get to second message
self.assertRedirects(response, translate_url + '?type=all&pos=1') self.assertRedirects(response, translate_url + '?type=all&pos=1')
unit = translation.unit_set.get(source='Hello, world!\n') unit = translation.unit_set.get(source='Hello, world!\n')
...@@ -168,22 +174,9 @@ class EditTest(ViewTestCase): ...@@ -168,22 +174,9 @@ class EditTest(ViewTestCase):
self.assertEqual(len(unit.checks()), 0) self.assertEqual(len(unit.checks()), 0)
def test_edit_check(self): def test_edit_check(self):
translation = self.subproject.translation_set.get(language_code='cs') response = self.edit_unit(
unit = translation.unit_set.get(source='Hello, world!\n') 'Hello, world!\n',
translate_url = reverse('translate', kwargs={ 'Nazdar svete!'
'project': self.subproject.project.slug,
'subproject': self.subproject.slug,
'lang': 'cs',
})
response = self.client.post(
translate_url,
{
'checksum': unit.checksum,
'target': 'Nazdar svete!',
'type': 'all',
'dir': 'forward',
'pos': '1',
}
) )
# We should stay on current message # We should stay on current message
self.assertRedirects(response, translate_url + '?type=all&pos=1&dir=stay') self.assertRedirects(response, translate_url + '?type=all&pos=1&dir=stay')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment