def setUp(self): self.voc = Vocabulary(name="voc") self.voc.save() self.user = User(username="******", password="******") self.user.save() self.up = UserProfile(user=self.user, current_vocabulary=self.voc, daily_words_amount=35) self.up.save() f = file("scripts/vocabulary.txt", "r") for lno, line in enumerate(f): word, exp = line.strip().split(" ", 1) w = Word(content=word, description=exp) w.save() w.vocabulary = [self.voc] w.save() if lno >= 49: # 只添加 50 个单词 break f.close()
class WordSelectingTests(TestCase): def setUp(self): self.voc = Vocabulary(name="voc") self.voc.save() self.user = User(username="******", password="******") self.user.save() self.up = UserProfile(user=self.user, current_vocabulary=self.voc, daily_words_amount=35) self.up.save() f = file("scripts/vocabulary.txt", "r") for lno, line in enumerate(f): word, exp = line.strip().split(" ", 1) w = Word(content=word, description=exp) w.save() w.vocabulary = [self.voc] w.save() if lno >= 49: # 只添加 50 个单词 break f.close() def test_select_words(self): u"""单词随机选择测试""" words = select_word(self.user) words_set = list(words) self.assertEqual(len(words_set), self.up.daily_words_amount) for w in words_set: # 将第一组单词添加到已掌握单词 self.up.memorized_words.add(w) words = select_word(self.user) words_set = list(words) # 共 50 单词,已掌握 35 个,第二组只能选出 15 个 self.assertEqual(len(words_set), 15)