def test_shouldGiveARandomChanceOf_OneOnAHundred(self): # Given random_mock = MagicMock(random) # When rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=random_mock) # Then random_mock.randint.assert_called_with(1, 100)
def test_shouldContinueChoice_WhenNoWellKnownWordAvailable(self, time_mock): # Given random_mock = MagicMock(random) random_mock.randint.return_value = 1 self.database.get_random_well_known_word.return_value = None # When rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=random_mock) # Then self.database.get_ordered_scheduled_words_to_learn_before_date \ .assert_called_once_with(time_mock.return_value, self.dictionary, self.user)
def choose_rythm_notation_exercise(request, dictionary_pk): if request.user.is_authenticated(): translation = rythm_choice(dictionary_pk, request.user) else: translation = random_choice(dictionary_pk) if not translation: return redirect('learn:come_back', dictionary_pk=dictionary_pk) return redirect('learn:exercise', dictionary_pk=dictionary_pk, translation_pk=translation.id)
def test_shouldContinueChoice_WhenNoWellKnownWordAvailable( self, time_mock): # Given random_mock = MagicMock(random) random_mock.randint.return_value = 1 self.database.get_random_well_known_word.return_value = None # When rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=random_mock) # Then self.database.get_ordered_scheduled_words_to_learn_before_date \ .assert_called_once_with(time_mock.return_value, self.dictionary, self.user)
def test_shouldReturnNone_WhenNoWordForToday_AndNoNewWordCanBeAdded(self): # Given self.conf.get_configuration.return_value = 2 self.database.get_ordered_scheduled_words_to_learn_before_date._mock_return_value = list() self.database.get_unseen_words._mock_return_value = list() # When result = rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=MagicMock(random)) # Then self.assertIsNone(result)
def test_shouldUseRandomChoice_ToReturnCurrentWord(self): # Given self.conf.get_configuration.return_value = 1 translations = create_translations(1, self.dictionary, self.user) self.database.get_ordered_scheduled_words_to_learn_before_date.return_value = translations create_autospec("learn.services.choice.random.choice", translations[0]) # When result = rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=MagicMock(random)) # Then self.assertEqual(result, translations[0])
def test_shouldReturnWord_FromDatabase(self): # Given translations = create_translations(1, self.dictionary, self.user) self.conf.get_configuration.return_value = 1 self.database.get_ordered_scheduled_words_to_learn_before_date.return_value = translations # When result = rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=MagicMock(random)) # Then self.assertIn(result, translations)
def test_shouldReturnWellKnownWordWhenHasTheChance(self): # Given random_mock = MagicMock(random) random_mock.randint.return_value = 1 translations = create_translations(1, self.dictionary, self.user) self.database.get_random_well_known_word.return_value = translations[0] # When result = rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=random_mock) # Then self.assertEqual(result, translations[0])
def test_shouldReturnWord(self): # Given user = User.objects.create() dictionary = Dictionary.objects.create(language='TestLang') translation = Translation.objects.create(known_word='test_known', word_to_learn='test_learn', dictionary=dictionary) # When result = rythm_choice(dictionary, user) # Then self.assertEqual(result, translation)
def test_shouldReturnNone_WhenNoWordForToday_AndNoNewWordCanBeAdded(self): # Given self.conf.get_configuration.return_value = 2 self.database.get_ordered_scheduled_words_to_learn_before_date._mock_return_value = list( ) self.database.get_unseen_words._mock_return_value = list() # When result = rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=MagicMock(random)) # Then self.assertIsNone(result)
def test_shouldPrepareNeverSeenWords_ToCompleteCurrentWords_UpToMaxWordsToLearn(self): # Given translations = create_translations(2, self.dictionary, self.user) self.conf.get_configuration.return_value = 2 self.database.get_ordered_scheduled_words_to_learn_before_date._mock_return_value = list() self.database.get_unseen_words._mock_return_value = translations # When result = rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=MagicMock(random)) # Then self.assertIn(result, translations) words_to_complete_the_list = self.database.get_unseen_words.call_args_list[0][0][1] self.assertEqual(words_to_complete_the_list, 2) self.assertEqual(self.database.schedule_words.call_args_list[0][0][0], translations)
def test_shouldPrepareNeverSeenWords_ToCompleteCurrentWords_UpToMaxWordsToLearn( self): # Given translations = create_translations(2, self.dictionary, self.user) self.conf.get_configuration.return_value = 2 self.database.get_ordered_scheduled_words_to_learn_before_date._mock_return_value = list( ) self.database.get_unseen_words._mock_return_value = translations # When result = rythm_choice(self.dictionary, self.user, database=self.database, conf=self.conf, rand=MagicMock(random)) # Then self.assertIn(result, translations) words_to_complete_the_list = self.database.get_unseen_words.call_args_list[ 0][0][1] self.assertEqual(words_to_complete_the_list, 2) self.assertEqual(self.database.schedule_words.call_args_list[0][0][0], translations)