Ejemplo n.º 1
0
    def test_add_all_cards(self):
        d = decks.Deck(name="Testdeck")
        cb = Cards.LanguageBVocab(text="worte1")
        cb2 = Cards.LanguageBVocab(text="worte2")
        ca1 = Cards.LanguageAVocab(text="word1")
        cea1 = Cards.LanguageAExample(text="example1")
        ceb1 = Cards.LanguageBExample(text="Beispiel1")

        u = Cards.User(name="jack")

        self.sess.add_all([d, cb, cb2, ca1, cea1, ceb1, u])

        self.sess.commit()

        dks.add_all_cards(d, [cb, cb2, ca1, cea1, ceb1])

        self.sess.commit()

        probe = dks.get_examples_a(d)
        ans = [cea1]
        self.assertEqual(probe, ans)

        probe = dks.get_examples_b(d)
        ans = [ceb1]
        self.assertEqual(probe, ans)

        probe = dks.get_vocab_a(d)
        ans = [ca1]
        self.assertEqual(probe, ans)

        probe = dks.get_vocab_b(d)
        ans = [cb, cb2]
        self.assertEqual(probe, ans)
Ejemplo n.º 2
0
    def test_get_translations(self):
        c = Cards.LanguageAVocab(text="hello")
        v1 = Cards.LanguageBVocab(text="hallo")
        v2 = Cards.LanguageBVocab(text="gutentag")

        self.sess.add(c)
        self.sess.add(v1)
        self.sess.add(v2)

        self.sess.commit()

        c.translations.append(v1)
        c.translations.append(v2)

        self.sess.commit()

        ans = cds.get_translations(c)
        self.assertEqual(ans, [v1, v2])

        e = Cards.LanguageAExample(text="this is an example")
        t1 = Cards.LanguageBExample(text="Diese ist ein Beispiel")

        self.sess.add(e)
        self.sess.add(t1)
        e.translations.append(t1)
        self.sess.commit()

        ans = cds.get_translations(e)
        self.assertEqual(ans, [t1])
Ejemplo n.º 3
0
    def test_add_translations(self):
        c = Cards.LanguageBVocab(text="Morgen")
        tr1 = Cards.LanguageAVocab(text="Morning")
        tr2 = Cards.LanguageAVocab(text="tomorrow")
        tr3 = Cards.LanguageAExample(text="not supposed to be here")

        self.sess.add_all([c, tr1, tr2, tr3])
        self.sess.commit()

        cds.add_translation(c, tr1)

        probe = cds.get_translations(c)
        ans = [tr1]
        self.assertEqual(probe, ans)

        cds.add_translation(c, tr2)

        probe = cds.get_translations(c)
        ans = [tr1, tr2]
        self.assertEqual(probe, ans)

        try:
            cds.add_translation(c, tr3)
            self.assertTrue(False)
        except AssertionError:
            print("caught assertion error")
Ejemplo n.º 4
0
    def test_get_creation_date(self):
        c = Cards.LanguageAExample(text="dude, howdyeedoo!")

        self.sess.add(c)
        self.sess.commit()

        probe = cds.get_creation_date(c)
        ans = datetime.date.today()
        self.assertEqual(probe, ans)
Ejemplo n.º 5
0
    def test_remove_cards(self):
        d = decks.Deck(name="Testdeck")
        cb = Cards.LanguageBVocab(text="worte1")
        cb2 = Cards.LanguageBVocab(text="worte2")
        ca1 = Cards.LanguageAVocab(text="word1")
        cea1 = Cards.LanguageAExample(text="example1")
        ceb1 = Cards.LanguageBExample(text="Beispiel1")

        u = Cards.User(name="jack")

        self.sess.add_all([d, cb, cb2, ca1, cea1, u])

        self.sess.commit()

        dks.add_all_cards(d, [cb, cb2, ca1, cea1])

        self.sess.commit()

        dks.remove_card(d, cb)

        self.sess.commit()

        probe = dks.get_vocab_b(d)
        ans = [cb2]
        self.assertEqual(probe, ans)

        dks.remove_card(d, ca1)
        self.sess.commit()

        self.assertEqual(dks.get_vocab_a(d), [])

        dks.remove_card(d, cea1)
        self.sess.commit()

        self.assertEqual(dks.get_examples_a(d), [])

        try:
            dks.remove_card(d, ceb1)
            self.sess.commit()

            self.fail()

        except ValueError:

            print("value error caught")
Ejemplo n.º 6
0
    def test_decks(self):
        user = Cards.User(name="Samuel")
        decka = decks.Deck(name="decka")

        vocabaa = Cards.LanguageAVocab(text="howdy")
        vocabba = Cards.LanguageBVocab(text="gutentag")
        vocabbb = Cards.LanguageBVocab(text="wie geht's")
        exampleaa = Cards.LanguageAExample(text="dude, I'm an example")
        exampleba = Cards.LanguageBExample(text="Je, Ich bin ein Beispiel")

        self.sess.add(user)
        self.sess.add(decka)
        self.sess.add(vocabaa)
        self.sess.add(vocabba)
        self.sess.add(vocabbb)
        self.sess.add(exampleaa)
        self.sess.add(exampleba)

        decka.user_id = user.id
        decka.vocab_a.append(vocabaa)
        decka.vocab_b.append(vocabba)
        decka.vocab_b.append(vocabbb)
        decka.examples_a.append(exampleaa)
        decka.examples_b.append(exampleba)

        self.sess.commit()

        d = self.sess.query(type(decka)).filter_by(id=1).one()
        self.assertEqual(len(d.vocab_a), 1)
        self.assertEqual(len(d.vocab_b), 2)
        self.assertEqual(len(d.examples_a), 1)
        self.assertEqual(len(d.examples_b), 1)

        self.sess.delete(vocabbb)
        self.sess.commit()

        self.assertEqual(len(d.vocab_b), 1)

        self.sess.delete(decka)
        self.sess.commit()

        self.assertEqual(vocabaa.text, "howdy")
Ejemplo n.º 7
0
    def test_add_card(self):
        d = decks.Deck(name="Testdeck")
        cb = Cards.LanguageBVocab(text="worte1")
        cb2 = Cards.LanguageBVocab(text="worte2")
        ca1 = Cards.LanguageAVocab(text="word1")
        cea1 = Cards.LanguageAExample(text="example1")
        ceb1 = Cards.LanguageBExample(text="Beispiel1")

        self.sess.add_all([d, cb, cb2, ca1, cea1, ceb1])

        self.sess.commit()

        self.assertEqual(d.examples_a, [])
        self.assertEqual(d.examples_b, [])
        self.assertEqual(d.vocab_a, [])
        self.assertEqual(d.vocab_b, [])

        dks.add_card(d, cb)
        self.sess.commit()

        self.assertEqual(d.examples_a, [])
        self.assertEqual(d.examples_b, [])
        self.assertEqual(d.vocab_a, [])
        self.assertEqual(d.vocab_b, [cb])

        dks.add_card(d, cb2)
        dks.add_card(d, ca1)
        dks.add_card(d, cea1)
        dks.add_card(d, ceb1)

        self.sess.commit()

        self.assertEqual(d.examples_a, [cea1])
        self.assertEqual(d.examples_b, [ceb1])
        self.assertEqual(d.vocab_a, [ca1])
        self.assertEqual(d.vocab_b, [cb, cb2])

        try:
            dks.add_card(d, 4)
            self.fail("assertion error was not caught")
        except AssertionError:
            print("assertion error caught")
Ejemplo n.º 8
0
    def test_get_low_scores(self):
        d = decks.Deck(name="Testdeck")
        cb = Cards.LanguageBVocab(text="worte1")
        cb2 = Cards.LanguageBVocab(text="worte2")
        ca1 = Cards.LanguageAVocab(text="word1")
        cea1 = Cards.LanguageAExample(text="example1")
        ceb1 = Cards.LanguageBExample(text="Beispiel1")

        u = Cards.User(name="jack")

        self.sess.add_all([d, cb, cb2, ca1, cea1, ceb1, u])

        self.sess.commit()

        dks.add_card(d, cb)
        dks.add_card(d, cb2)
        dks.add_card(d, ca1)
        dks.add_card(d, cea1)
        dks.add_card(d, ceb1)

        cds.edit_score(self.sess, cb, u, 5)
        cds.edit_score(self.sess, cb2, u, 10)
        cds.edit_score(self.sess, ceb1, u, 8)

        u.decks.append(d)

        self.sess.commit()

        probe = dks.get_low_scores(self.sess, d, 3)
        ans = []
        self.assertEqual(probe, ans)

        probe = dks.get_low_scores(self.sess, d, 7)
        ans = [cb]

        self.assertEqual(probe, ans)

        probe = dks.get_low_scores(self.sess, d, 9)
        ans = [cb, ceb1]
        self.assertEqual(probe, ans)
Ejemplo n.º 9
0
    def test_delete_deck(self):
        d = decks.Deck(name="Testdeck")
        self.sess.add(d)
        self.sess.commit()

        alldecks = self.sess.query(decks.Deck).all()
        self.assertEqual(alldecks, [d])

        dks.delete_deck(self.sess, d)
        self.sess.commit()

        alldecks = self.sess.query(decks.Deck).all()
        self.assertEqual(alldecks, [])

        # Deletion of decks should not delete cards
        cb = Cards.LanguageBVocab(text="worte1")
        cb2 = Cards.LanguageBVocab(text="worte2")
        ca1 = Cards.LanguageAVocab(text="word1")
        cea1 = Cards.LanguageAExample(text="example1")
        ceb1 = Cards.LanguageBExample(text="Beispiel1")
        self.sess.add_all([cb, cb2, ca1, cea1, ceb1])
        self.sess.commit()

        d = decks.Deck(name="Testdeck")
        self.sess.add(d)
        self.sess.commit()

        dks.add_all_cards(d, [cb, cb2, ca1, cea1, ceb1])
        self.sess.commit()

        dks.delete_deck(self.sess, d)
        self.sess.commit()

        bvocab = self.sess.query(Cards.LanguageBVocab).all()

        self.assertTrue(cb in bvocab)
        self.assertTrue(cb2 in bvocab)
        self.assertEqual(len(bvocab), 2)
Ejemplo n.º 10
0
    def test_new_deck(self):
        cb = Cards.LanguageBVocab(text="worte1")
        cb2 = Cards.LanguageBVocab(text="worte2")
        ca1 = Cards.LanguageAVocab(text="word1")
        cea1 = Cards.LanguageAExample(text="example1")
        ceb1 = Cards.LanguageBExample(text="Beispiel1")

        u = Cards.User(name="jack")

        self.sess.add_all([cb, cb2, ca1, cea1, ceb1, u])

        self.sess.commit()

        d = dks.new_deck(self.sess, [cb, cb2, ca1, cea1, ceb1], u, "test_deck")

        self.sess.commit()

        probe = dks.get_examples_a(d)
        ans = [cea1]
        self.assertEqual(probe, ans)

        probe = dks.get_examples_b(d)
        ans = [ceb1]
        self.assertEqual(probe, ans)

        probe = dks.get_vocab_a(d)
        ans = [ca1]
        self.assertEqual(probe, ans)

        probe = dks.get_vocab_b(d)
        ans = [cb, cb2]
        self.assertEqual(probe, ans)

        probe = d.user_id
        ans = u.id
        self.assertEqual(probe, ans)
Ejemplo n.º 11
0
    def test_add_examples(self):
        import LanguageDeck.session_tools.session_scope as scp
        with scp.session_scope(self.session) as sess:
            cvb = Cards.LanguageBVocab(text="lbv")
            cvb2 = Cards.LanguageBVocab(text="lbv2")
            cva = Cards.LanguageAVocab(text="lav")
            ceb = Cards.LanguageBExample(text="example lbv")
            cea = Cards.LanguageAExample(text="example lav")

            sess.add_all([cvb, cvb2, cva, ceb, cea])
            sess.commit()

            cds.add_example(cvb, ceb)
            sess.commit()
            probe = cds.get_examples(cvb)
            ans = [ceb]
            self.assertEqual(probe, ans)

            cds.add_example(cvb2, ceb)
            sess.commit()
            probe = cds.get_examples(cvb2)
            ans = [ceb]
            self.assertEqual(probe, ans)

            cds.add_example(cva, cea)
            sess.commit()
            probe = cds.get_examples(cva)
            ans = [cea]
            self.assertEqual(probe, ans)

            cds.add_example(cvb, ceb)
            cds.add_example(cvb, ceb)
            sess.commit()
            probe = cds.get_examples(cvb)
            ans = [ceb]
            self.assertEqual(probe, ans)