def test_get_learned_words(self): l_hq = LinguistHQ(student=self.user) words = self.user.word_set.filter( viewed=True, language=Language.objects.get(name=self.user.current_language), played_match=True, played_reversed_match=True, played_typing=True, played_reversed_typing=True, category=self.category) self.assertEqual(l_hq.get_learned_words(self.category)[0], words[0])
def test_play_typing(self): l_hq = LinguistHQ(student=self.user) word = l_hq.play_typing() self.assertIn(word, self.user.word_set.all()) # Let's test reverse case word = l_hq.play_typing(reverse=True) self.assertIn(word, self.user.word_set.all()) # Let's test when all words played for w in self.user.word_set.all(): w.played_typing = True w.save() error = l_hq.play_typing() self.assertEqual(error, 'No word to play typing')
def test_play_matching(self): l_hq = LinguistHQ(student=self.user) words = l_hq.play_matching() self.assertIn(words['answer'], self.user.word_set.all()) # Let's test reverse case words = l_hq.play_matching(reverse=True) self.assertIn(words['answer'], self.user.word_set.all()) # Let's test when all words played for w in self.user.word_set.all(): w.played_match = True w.save() error = l_hq.play_matching() self.assertEqual(error, 'No words to play matching')
def __init__(self, student=None): # Register case: self.HQ = LinguistHQ(student=student) if student is not None else None self.destination = None self.student = student self.temp_data = {} self.callback_data = {}
def test_add_custom_word(self): l_hq = LinguistHQ(student=self.user) l_hq.add_custom_word(word_name='あいさつ', translation='Greetings', pronunciation='arigato', category=self.category) word = self.user.word_set.filter( name='あいさつ', language=Language.objects.get(name=self.user.current_language)) self.assertEqual(word[0].name, 'あいさつ') # Let's test error error = l_hq.add_custom_word(word_name=None, translation=None, pronunciation=None, category=None) self.assertEqual(error, 'You did not choose word or translation or category')
def test_add_global_word(self): l_hq = LinguistHQ(student=self.user) l_hq.add_from_global_word(global_word=self.global_word, alternative_translation=None) word = self.user.word_set.filter(name=self.global_word.name, language=self.current_language) self.assertEqual(self.global_word.name, word[0].name) word[0].delete() # Let's test alternative arg l_hq.add_from_global_word(global_word=self.global_word, alternative_translation='Alternative') word2 = self.user.word_set.filter(name=self.global_word.name, language=self.current_language) self.assertEqual('Alternative', word2[0].translation)
def create_user(self, update, context, student): password = Student.objects.make_random_password() user = Student.objects.create_user( username=str(student.temp_data['username']), password=password, first_name=student.temp_data['first_name'], home_language=student.temp_data['home_language'], current_language=student.temp_data['current_language'], telegram=student.temp_data['username'], terms_check=student.temp_data['terms_check']) learn_language = self.langs.get( name=student.temp_data['current_language']) learn_language.students.add(user) student.HQ = LinguistHQ(student=student) student.student = user update.message.edit_text( 'Your username: %s \n' 'Your password: %s \n' 'You will need it to use at https://linguint.pro . So write it somewhere in safe place. \n' 'And DELETE this message for security purposes.' % (user.username, password), reply_markup=None) self.dispatch_destination(update, context, student, 'Menu')
def test_search_word(self): l_hq = LinguistHQ(student=self.user) words = l_hq.search_word('ありがとう') self.assertEqual(words['words'][0].translation, 'thank you')
def test_init(self): l_hq = LinguistHQ(student=self.user) self.assertIsInstance(l_hq.student, Student) # Let's test non existing student check with self.assertRaises(ValueError): l_hq = LinguistHQ()
def test_get_all_words(self): l_hq = LinguistHQ(student=self.user) self.assertEqual( l_hq.get_all_words(self.category)[1], self.user.word_set.filter(category=self.category)[1])
def create_user_words(self): user = Student.objects.get(username='******') hq = LinguistHQ(user) word = GlobalWord.objects.filter(name='ありがとう')[1] for i in range(10): hq.add_from_global_word(word)
def initial(self, request, *args, **kwargs): super(LinguistInitializer, self).initial(request, *args, **kwargs) student = request.user self.linguist = LinguistHQ(student)