Example #1
0
    def test_len_studyset(self):
        # Should return the number of cards in this study set
        card0 = StudyCard('What is my name?', 'Jonathan')
        card1 = StudyCard("What is bird's name ?", "Gandalf")
        card2 = StudyCard("What is the meaning of life ?", "42")
        self.set_instance.add(card0)
        self.set_instance.add(card1)
        self.set_instance.add(card2)

        self.assertEqual(len(self.set_instance), 3)
Example #2
0
    def test_create_from_dict(self):
        card = StudyCard('2+2=?', '4')

        data = {'title': 'Maths', 'description': 'Math-145'}
        data['cards'] = [card.to_dict()]

        study_set = sets.create_from_dict(data)

        self.assertEqual(study_set.title, 'Maths')
        self.assertEqual(study_set.description, 'Math-145')
        self.assertEqual(len(study_set), 1)
        self.assertEqual(study_set._cards[0].question, '2+2=?')
        self.assertEqual(study_set._cards[0].answer, '4')
Example #3
0
    def test_iter_cards(self):
        card0 = StudyCard('What is my name?', 'Jonathan')
        card1 = StudyCard("What is bird's name ?", "Gandalf")
        card2 = StudyCard("What is the meaning of life ?", "42")
        self.set_instance.add(card0)
        self.set_instance.add(card1)
        self.set_instance.add(card2)

        index = 0
        for card in self.set_instance:
            index += 1
            self.assertIsInstance(card, StudyCard)

        self.assertEqual(index, 3)
Example #4
0
class TestQuestionCards(unittest.TestCase):
    def setUp(self):
        self.card = StudyCard('what is PI ?', '3.14159265359')

    def test_Card_class_exists(self):
        self.assertIsNotNone(StudyCard('meaning of life?', '42'))

    def test_card_get_question(self):
        self.assertEqual('what is PI ?', self.card.question)

    def test_card_get_answer(self):
        self.assertEqual('3.14159265359', self.card.answer)

    def test_card_set_question(self):
        new_question = 'What is e ?'
        self.card.question = new_question
        self.assertEqual(new_question, self.card.question)

    def test_card_set_question_error(self):
        bad_question = 4123451
        self.assertRaises(TypeError, setattr, self.card.question, bad_question)

    def test_card_set_answer(self):
        new_answer = '2.71828'
        self.card.answer = new_answer
        self.assertEqual(new_answer, self.card.answer)

    def test_card_set_answer_error(self):
        bad_answer = 2.71828
        self.assertRaises(TypeError, setattr, self.card.answer, bad_answer)

    def test_to_dict(self):
        data = self.card.to_dict()
        expected = {'question': 'what is PI ?', 'answer': '3.14159265359'}
        self.assertEqual(expected, data)
Example #5
0
    def test_to_dict(self):
        card = StudyCard('What is my name?', 'Jonathan')
        self.set_instance.add(card)

        data = self.set_instance.to_dict()
        expected = {'title': 'Maths', 'description': 'A study set about maths'}

        # List of serialized cards in this set
        cards = [c.to_dict() for c in self.set_instance]
        expected['cards'] = cards

        self.assertEqual(expected, data)
Example #6
0
    def test_rename_filename(self, mock_rename):

        stored_set = StudySetStorage('/home/usr/.flashcards/set01.json')

        study_set = StudySet('maths145', 'Maths questions')
        study_set.add(StudyCard('2+2=?', '4'))

        newname = storageUtils.generate_filename_from_str(study_set.title)
        stored_set._rename_filename(newname)

        expected = '/home/usr/.flashcards/maths145.json'
        self.assertEqual(expected, stored_set._filepath)
Example #7
0
 def test_set_add(self):
     card = StudyCard('What is my name?', 'Jonathan')
     self.set_instance.add(card)
     self.assertEqual(len(self.set_instance._cards), 1)
     self.assertIn(card, self.set_instance._cards)
Example #8
0
 def test_Card_class_exists(self):
     self.assertIsNotNone(StudyCard('meaning of life?', '42'))
Example #9
0
 def setUp(self):
     self.card = StudyCard('what is PI ?', '3.14159265359')