Пример #1
0
    def test_potr_proj_lang(self):
        path = os.path.join(PATH, 'data/django.po')
        proj_type = ProjectType.objects.create(name='django')
        proj_lang_2 = Language.objects.create(name='Russian', code='ru')
        proj_2 = Project.objects.create(name='Project1',
                                        project_type=proj_type,
                                        lang=proj_lang_2)
        potr_set_2 = Set.objects.create(name='initial', project=proj_2)
        ProjectLanguage.objects.create(lang=proj_lang_2, project=proj_2)

        for message in ['message1', 'message2', 'message3', 'message4']:
            SetMessage.objects.create(
                message_set=potr_set_2,
                lang=proj_lang_2,
                msgid=message[-3:],
                msgstr=message,
                is_translated=False
            )
            SetList.objects.create(
                message_set=potr_set_2,
                msgid=message[-3:],
                msgstr=message)
        mes = get_message_list(self.project.id, self.project_language.id)
        self.assertEqual(len(mes), 4)
        mes = get_message_list(proj_2.id, proj_lang_2.id)
        self.assertEqual(len(mes), 4)
        import_po_file(path, self.project.id, self.project_language.id)
        self.assertEqual(SetMessage.objects.filter(
            message_set__project_id=self.project.id,
            lang__id=proj_lang_2.id).count(), 0)
Пример #2
0
    def test_export_po_file_with_empty_msgstr_in_target_lang(self):
        client = Client()
        user = User.objects.create(username='******')
        user.set_password('Admin')
        user.save()
        client.login(username='******', password='******')

        new_lang = Language.objects.create(name='Japan', code='jp')
        ProjectLanguage.objects.create(lang=new_lang, project=self.project)
        path = os.path.join(PATH, 'data/django1.po')
        import_po_file(path, self.project.id, self.project_language.id)
        SetMessage.objects.filter(msgid='test.empty', lang=self.project.lang.id).update(msgstr='NonEmpty')
        response = client.get('/project/%s/export/%s/' % (self.project.id, new_lang.id))
        po = polib.pofile(response.content)
        all_messages = SetMessage.objects.filter(
            message_set__project_id=self.project.id,
            lang=self.project.lang.id)
        self.assertFalse(SetMessage.objects.get(msgid='test.empty', lang=new_lang.id).msgstr)
        self.assertEqual(dict((i.msgid, unicode(i.msgstr, 'utf8')) for i in po)['test.empty'], 'NonEmpty')

        SetMessage.objects.filter(msgid='test.empty').update(is_translated=True)
        response = client.get('/project/%s/export/%s/' % (self.project.id, new_lang.id))
        po = polib.pofile(response.content)
        all_messages = SetMessage.objects.filter(message_set__project_id=self.project.id, lang=self.project.lang.id)
        self.assertFalse(SetMessage.objects.get(msgid='test.empty', lang=new_lang.id).msgstr)
        self.assertFalse(dict((i.msgid, unicode(i.msgstr, 'utf8')) for i in po)['test.empty'])
Пример #3
0
    def test_import_export_csv_file(self):
        import csv
        import cStringIO

        self._setup_project('csv_project', 'csv_file', dict(name='English', code='en'))
        path = os.path.join(PATH, 'data/csv.csv')
        with open(path, 'r') as data_file:
            import_po_file(data_file.read(), self.project.id, self.project_language.id)
        last_set = Set.objects.all().order_by('-id')[0]
        self.assertEqual(len(ImportMessage.objects.all()), 5)
        self.assertEqual(len(Set.objects.all()), 2)
        client = Client()
        user = User.objects.create(username='******')
        user.set_password('Admin')
        user.save()
        client.login(username='******', password='******')
        response = client.get('/project/%s/export/%s/' % (self.project.id,
                                                          self.project_language.id))
        messages = csv.reader(cStringIO.StringIO(response.content))
        fields = messages.next()
        messages = [{"msgid": i[0], "msgstr": i[1] or ''} for i in messages]

        self.assertEqual(len(messages), 5)
        mess_keys = [k['msgid'] for k in messages]
        for msg in SetMessage.objects.filter(message_set=last_set):
            self.assertTrue(msg.msgid in mess_keys)
Пример #4
0
    def test_export_po_file_with_two_lang_check_record_number(self):
        client = Client()
        user = User.objects.create(username='******')
        user.set_password('Admin')
        user.save()
        client.login(username='******', password='******')

        response = client.get('/project/%s/export/%s/' % (self.project.id, self.project_language.id))
        self.assertEqual(response.status_code, 200)
        po = polib.pofile(response.content)
        self.assertEqual(
            len(SetMessage.objects.filter(
                message_set__project_id=self.project.id,
                lang=self.project_language.id)),
            len(po.translated_entries()))
        new_lang = Language.objects.create(name='Russian', code='ru')
        ProjectLanguage.objects.create(lang=new_lang, project=self.project)
        path = os.path.join(PATH, 'data/django.po')
        import_po_file(path, self.project.id, self.project_language.id)
        response = client.get('/project/%s/export/%s/' % (self.project.id, new_lang.id))
        po = polib.pofile(response.content)
        all_messages = SetMessage.objects.filter(
            message_set__project_id=self.project.id,
            lang=new_lang.id)
        self.assertEqual(len(all_messages), len(po.translated_entries()))
        self.assertTrue(
            dict((i.msgid, unicode(i.msgstr, 'utf8')) for i in po) ==
            dict((i.msgid, i.msgstr) for i in all_messages))
        self.assertTrue(
            set(i.msgid for i in all_messages) == set(i.msgid for i in po))
Пример #5
0
 def test_import_target_lang(self):
     path = os.path.join(PATH, 'data/django.po')
     new_lang = Language.objects.create(name='Russian', code='ru')
     ProjectLanguage.objects.create(lang=new_lang, project=self.project)
     import_po_file(path, self.project.id, new_lang.id)
     self.assertEqual(len(ImportMessage.objects.all()), 10)
     self.assertEqual(len(Set.objects.all()), 1)
Пример #6
0
    def test_delete_last_set(self):
        path = os.path.join(PATH, 'data/django.po')
        proj_type = ProjectType.objects.create(name='django')
        new_proj = Project.objects.create(name='Project2', project_type=proj_type, lang=self.project_language)
        import_po_file(path, new_proj.id, self.project_language.id)

        self.assertEqual(len(Set.objects.all()), 3)
        self.assertEqual(SetMessage.objects.filter(message_set__project_id=self.project.id).count(), 10)
        self.assertEqual(
            SetMessage.objects.filter(message_set__project_id=self.project.id, lang=self.project.lang).count(), 5)
        self.assertEqual(SetList.objects.filter(message_set__project_id=self.project.id).count(), 6)
        response = delete_last(self.project.id)

        self.assertEqual(len(Set.objects.all()), 2)

        self.assertEqual(SetMessage.objects.filter(message_set__project_id=self.project.id).count(), 6)
        self.assertEqual(
            SetMessage.objects.filter(message_set__project_id=self.project.id, lang=self.project.lang).count(), 3)
        self.assertEqual(SetList.objects.filter(
            message_set__project_id=self.project.id).count(), 3)

        response = delete_last(self.project.id)
        self.assertEqual(len(Set.objects.filter(project=self.project.id)), 0)
        self.assertEqual(SetList.objects.filter(
            message_set__project_id=self.project.id).count(), 0)
        self.assertEqual(len(Set.objects.all()), 1)
Пример #7
0
 def test_import_source_lang_2(self):
     path = os.path.join(PATH, 'data/django.po')
     import_po_file(path, self.project.id, self.project_language.id)
     last_set = Set.objects.all().order_by('-id')[0]
     self.assertEqual(len(Set.objects.all()), 2)
     self.assertEqual(len(SetList.objects.filter(message_set=last_set)), 10)
     project_source_messages = SetMessage.objects.filter(message_set__project_id=self.project.id)
     self.assertEqual(project_source_messages.filter(lang=self.project.lang).count(), 14)
     self.assertEqual(project_source_messages.filter(
         lang=self.project.lang,
         message_set=last_set).count(), 10)
     for i in project_source_messages.filter(lang=self.project.lang, message_set=last_set):
         self.assertTrue(i.is_translated)
Пример #8
0
    def test_change_value_after_import_in_one_project(self):
        path = os.path.join(PATH, 'data/mess.po')
        source_messages = SetMessage.objects.filter(
            msgstr='message1',
            lang=self.project_language.id)
        self.assertEqual(source_messages.count(), 2)

        import_po_file(path, self.project.id, self.project_language.id)
        import_po_file(path, self.new_project.id, self.project_language.id)
        source_messages = SetMessage.objects.filter(
            msgstr='title_title',
            lang=self.project_language.id)
        self.assertEqual(source_messages.count(), 2)
        message_to_edit = SetMessage.objects.get(
            message_set__project_id=self.project.id,
            msgid='1.Title',
            lang=self.project_language.id)

        #Check same meaning update
        new_value = 'message1 new'
        response = save_same(message_to_edit.id, new_value)
        source_messages = SetMessage.objects.filter(
            msgstr='message1 new',
            lang=self.project_language.id)
        self.assertEqual(source_messages.count(), 1)

        first_mes = get_message_list(self.project.id, self.project_language.id)
        second_mes = get_message_list(self.new_project.id, self.project_language.id)

        src_msg_list = {i['msg_id']: i['msg_source'] for i in first_mes}
        self.assertEqual(src_msg_list['1.Title'], 'message1 new')

        src_msg_list = {i['msg_id']: i['msg_source'] for i in second_mes}
        self.assertEqual(src_msg_list['1.Title'], 'title_title')

        #Check new meaning update
        new_value = 'message1 new2'
        response = save_new(message_to_edit.id, new_value)
        source_messages = SetMessage.objects.filter(
            msgstr='message1 new2',
            lang=self.project_language.id)
        self.assertEqual(source_messages.count(), 1)
        first_mes = get_message_list(self.project.id, self.project_language.id)
        second_mes = get_message_list(self.new_project.id, self.project_language.id)

        src_msg_list = {i['msg_id']: i['msg_source'] for i in first_mes}
        self.assertEqual(src_msg_list['1.Title'], 'message1 new2')

        src_msg_list = {i['msg_id']: i['msg_source'] for i in second_mes}
        self.assertEqual(src_msg_list['1.Title'], 'title_title')
Пример #9
0
 def test_import_source_lang_with_two_lang(self):
     path = os.path.join(PATH, 'data/django.po')
     new_lang = Language.objects.create(name='Russian', code='ru')
     ProjectLanguage.objects.create(lang=new_lang, project=self.project)
     import_po_file(path, self.project.id, self.project_language.id)
     self.assertEqual(len(Set.objects.all()), 2)
     last_set = Set.objects.all().order_by('-id')[0]
     self.assertEqual(
         len(SetMessage.objects.filter(
             message_set__project_id=self.project.id, lang=new_lang.id)), 10)
     for i in SetMessage.objects.filter(
             message_set__project_id=self.project.id,
             message_set=last_set,
             lang=new_lang.id):
         self.assertFalse(i.is_translated)
         self.assertTrue(len(i.msgstr) > 0)
Пример #10
0
    def test_show_prev(self):
        path = os.path.join(PATH, 'data/django.po')
        new_lang = Language.objects.create(name='Russian', code='ru')
        ProjectLanguage.objects.create(lang=new_lang, project=self.project)
        import_po_file(path, self.project.id, self.project_language.id)
        last_set = Set.objects.all().order_by('-id')[0]
        message_to_edit = SetMessage.objects.filter(lang=self.project_language.id,
                                                    message_set=last_set,
                                                    msgid='Submitted')[0]
        path = os.path.join(PATH, 'data/django1.po')
        import_po_file(path, self.project.id, self.project_language.id)
        new_value = 'test'
        response = save_new(message_to_edit.id, new_value)

        last_set = Set.objects.all().order_by('-id')[0]
        message_to_edit2 = SetMessage.objects.filter(
            lang=new_lang.id,
            message_set=last_set,
            msgid=message_to_edit.msgid)[0]
        response = show_prev(message_to_edit2.id)
        self.assertEqual(response['prev_source'], message_to_edit.msgstr)
        self.assertEqual(response['prev_target'], message_to_edit.msgstr)
Пример #11
0
    def test_import_export_android_file(self):
        from xml.etree import ElementTree as ET

        self._setup_project('android_project', 'android', dict(name='English', code='en'))
        path = os.path.join(PATH, 'data/android.xml')
        with open(path, 'r') as data_file:
            import_po_file(data_file.read(), self.project.id, self.project_language.id)
        last_set = Set.objects.all().order_by('-id')[0]
        self.assertEqual(len(ImportMessage.objects.all()), 5)
        self.assertEqual(len(Set.objects.all()), 2)
        client = Client()
        user = User.objects.create(username='******')
        user.set_password('Admin')
        user.save()
        client.login(username='******', password='******')
        response = client.get('/project/%s/export/%s/' % (self.project.id,
                                                          self.project_language.id))
        messages = [{"msgid": i.attrib['name'], "msgstr": i.text or ''}
                    for i in ET.fromstring(
                response.content).findall('.//string')]
        self.assertEqual(len(messages), 5)
        mess_keys = [k['msgid'] for k in messages]
        for msg in SetMessage.objects.filter(message_set=last_set):
            self.assertTrue(msg.msgid in mess_keys)
Пример #12
0
 def test_double_import_source_lang(self):
     path = os.path.join(PATH, 'data/django1.po')
     import_po_file(path, self.project.id, self.project_language.id)
     import_po_file(path, self.project.id, self.project_language.id)
     last_set = Set.objects.all().order_by('-id')[0]
Пример #13
0
 def test_import_source_lang(self):
     path = os.path.join(PATH, 'data/django.po')
     import_po_file(path, self.project.id, self.project_language.id)
     self.assertEqual(len(ImportMessage.objects.all()), 10)
     self.assertEqual(len(Set.objects.all()), 2)