コード例 #1
0
 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])
コード例 #2
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')
コード例 #3
0
 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')
コード例 #4
0
 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 = {}
コード例 #5
0
 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')
コード例 #6
0
 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)
コード例 #7
0
ファイル: register.py プロジェクト: stPhoenix/project_osirius
 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')
コード例 #8
0
 def test_search_word(self):
     l_hq = LinguistHQ(student=self.user)
     words = l_hq.search_word('ありがとう')
     self.assertEqual(words['words'][0].translation, 'thank you')
コード例 #9
0
 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()
コード例 #10
0
 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])
コード例 #11
0
 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)
コード例 #12
0
ファイル: utils.py プロジェクト: stPhoenix/project_osirius
 def initial(self, request, *args, **kwargs):
     super(LinguistInitializer, self).initial(request, *args, **kwargs)
     student = request.user
     self.linguist = LinguistHQ(student)