コード例 #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)
コード例 #2
0
def clone_deck(session, deck, user, name):
    assert type(deck) == dks.Deck, "deck must by a Deck type"
    ret = dks.Deck(name=name)

    add_all_cards(
        ret, deck.vocab_b + deck.vocab_a + deck.examples_a + deck.examples_b)
    ret.user = user
    session.add(ret)

    return ret
コード例 #3
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)
コード例 #4
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")
コード例 #5
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")
コード例 #6
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")
コード例 #7
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)
コード例 #8
0
def new_deck(session, cards, user, name):
    ret = dks.Deck(name=name, date_created=datetime.date.today())
    ret.user = user
    add_all_cards(ret, cards)
    session.add(ret)
    return ret