Exemplo n.º 1
0
 def get_context_data(self):
     user = self.request.user
     qs = get_words_qs(user)
     words_data_list = []
     for word in qs:
         words_data_list.append(serialize_learning_state(word))
     return {"words": words_data_list}
Exemplo n.º 2
0
 def test_assigns_first_audio_as_best_for_new_learning_state(self):
     test_word = Word.objects.create(value='test_word',
                                     spelling='spelling',
                                     raw_od_article='raw_od_article')
     test_word.pronunciation_set.create(audio='test_1_mp3')
     test_word.pronunciation_set.create(audio='test_2_mp3')
     test_word.meaning_set.create(value='test_value')
     user = User.objects.create_user(
         username='******',
         email='{}@debugmail.io'.format('test_username'),
         password='******')
     ls = test_word.wordlearningstate_set.create(user=user)
     test_word_dict = serialize_learning_state(ls)
     self.assertEqual(test_word_dict['audio'][0]['best'], True)
Exemplo n.º 3
0
 def test_assigns_first_audio_as_best_for_new_learning_state(
         self, fake_meta, fake_sounds):
     fake_meta.expects_call().returns(FAKE_FORVO_DATA)
     fake_sounds.expects_call().returns(['sound1.mp3', 'sound2.mp3'])
     test_word = Word.objects.create(value='test_word',
                                     spelling='spelling',
                                     raw_od_article='raw_od_article')
     test_word.meaning_set.create(value='test_value')
     user = User.objects.create_user(
         username='******',
         email='{}@debugmail.io'.format('test_username'),
         password='******')
     ls = test_word.wordlearningstate_set.create(user=user)
     test_word_dict = serialize_learning_state(ls)
     self.assertEqual(test_word_dict['audio'][0]['best'], True)
Exemplo n.º 4
0
 def test_converts_learning_state_to_dict(self):
     test_word = Word.objects.create(value='test_word',
                                     spelling='spelling',
                                     raw_od_article='raw_od_article')
     test_word.pronunciation_set.create(audio='test_mp3')
     test_word.meaning_set.create(value='test_value')
     user = User.objects.create_user(
         username='******',
         email='{}@debugmail.io'.format('test_username'),
         password='******')
     ls = test_word.wordlearningstate_set.create(user=user)
     test_word_dict = serialize_learning_state(ls)
     self.assertEqual(test_word_dict['value'], 'test_word')
     self.assertEqual(test_word_dict['audio'][0]['src'], '/media/test_mp3')
     self.assertEqual(test_word_dict['audio'][0]['id'], 'audio_1')
     self.assertEqual(test_word_dict['meanings'][0]['value'], 'test_value')
     self.assertEqual(test_word_dict['meanings'][0]['id'], 'meaning_1')
     self.assertEqual(len(test_word_dict['audio']), 1)
     self.assertEqual(len(test_word_dict['meanings']), 1)
Exemplo n.º 5
0
    def test_converts_learning_state_to_dict(self, fake_meta, fake_sounds):
        fake_meta.expects_call().returns(FAKE_FORVO_DATA)
        fake_sounds.expects_call().returns(['sound1.mp3', 'sound2.mp3'])

        test_word = Word.objects.create(value='test_word',
                                        spelling='spelling',
                                        raw_od_article='raw_od_article')
        test_word.meaning_set.create(value='test_value')
        user = User.objects.create_user(
            username='******',
            email='{}@debugmail.io'.format('test_username'),
            password='******')
        ls = test_word.wordlearningstate_set.create(user=user)
        test_word_dict = serialize_learning_state(ls)
        self.assertEqual(test_word_dict['value'], 'test_word')
        self.assertEqual(test_word_dict['audio'][0]['src'], 'sound1.mp3')
        self.assertEqual(test_word_dict['audio'][0]['id'], 'audio_2625')
        self.assertEqual(test_word_dict['meanings'][0]['value'], 'test_value')
        self.assertEqual(test_word_dict['meanings'][0]['id'], 'meaning_1')
        self.assertEqual(len(test_word_dict['audio']), 2)
        self.assertEqual(len(test_word_dict['meanings']), 1)