def test_save_new_meaning_new_set(self): last_set = Set.objects.all().order_by('-id')[0] message_to_edit = SetMessage.objects.get( message_set__project_id=self.project.id, msgid='message1', lang=self.project_language.id) new_value = 'message1 new' previous_set = message_to_edit.message_set last_set = self.project.set.order_by('-id')[0] response = save_new(message_to_edit.id, new_value) source_messages = SetMessage.objects.filter( message_set__project_id=self.project.id, msgid='message1', lang=self.project_language.id) self.assertEqual(source_messages.count(), 2) self.assertEqual(source_messages.order_by('-id')[1].message_set, previous_set) self.assertEqual(source_messages.order_by('-id')[0].message_set, last_set) target_messages = SetMessage.objects.filter( message_set__project_id=self.project.id, msgid='message1', lang=self.new_lang) self.assertEqual(target_messages.count(), 2) self.assertEqual(target_messages.order_by('-id')[1].message_set, previous_set) self.assertEqual(target_messages.order_by('-id')[0].message_set, last_set) message_list = get_message_list(self.project.id, self.project_language.id) for mes in message_list: if mes['msg_id'] == message_to_edit.msgid: self.assertEqual(mes['msg_source'], new_value) break self.assertTrue(False) message_to_edit = mes new_value = 'message1 new1' response = save_new(message_to_edit['id'], new_value) message_list = get_message_list(self.project.id, self.project_language.id) for mes in message_list: if mes['msg_id'] == message_to_edit['msg_id']: self.assertEqual(mes['msg_source'], new_value) break self.assertTrue(False) message_to_edit = mes new_value = 'message1 new2' response = save_new(message_to_edit['id'], new_value) message_list = get_message_list(self.project.id, self.project_language.id) for mes in message_list: if mes['msg_id'] == message_to_edit['msg_id']: self.assertEqual(mes['msg_source'], new_value) break self.assertTrue(False)
def test_save_new_meaning(self): last_set = Set.objects.all().order_by('-id')[0] message_to_edit = SetMessage.objects.filter( message_set__project_id=self.project.id, lang=self.project_language.id, message_set=last_set)[0] new_value = 'test' new_lang = Language.objects.create(name='Russian', code='ru') new_lang_2 = Language.objects.create(name='Spanish', code='sp') ProjectLanguage.objects.create(lang=new_lang, project=self.project) ProjectLanguage.objects.create(lang=new_lang_2, project=self.project) for item in SetMessage.objects.filter(lang=self.project_language.id): SetMessage.objects.create( message_set=item.message_set, lang=new_lang, msgid=item.msgid, msgstr=item.msgstr, is_translated=True ) response = save_new(message_to_edit.id, new_value) self.assertEqual(SetMessage.objects.filter( msgid=message_to_edit.msgid, lang=message_to_edit.lang ).order_by('-id')[0].msgstr, new_value) self.assertEqual(SetMessage.objects.filter( msgid=message_to_edit.msgid ).order_by('-id')[0].message_set, last_set) self.assertFalse(SetMessage.objects.filter( msgid=message_to_edit.msgid, lang=new_lang)[0].is_translated) self.assertFalse(SetMessage.objects.filter( msgid=message_to_edit.msgid, lang=new_lang_2)[0].is_translated)
def test_save_new_meaning_for_old_set_message(self): messages = SetMessage.objects.filter( message_set__project_id=self.project.id, msgid='message3') src_message_versions = messages.filter(lang=self.project_language.id) self.assertEqual(messages.count(), 2) self.assertEqual(src_message_versions.count(), 1) new_value = 'message3_new' response = save_new(src_message_versions[0].id, new_value) self.assertTrue(response['saved']) self.assertEqual(messages.all().count(), 4) target_message_versions = messages.filter(lang=self.new_lang.id) self.assertEqual(target_message_versions.count(), 2) self.assertEqual(set(i.msgstr for i in target_message_versions), set(['ru_message3']))
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')
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)