Example #1
0
    def test_get_score(self):
        c = Cards.LanguageBExample(text="hallo, bob")
        u1 = Cards.User(name="user1")
        u2 = Cards.User(name="user2")

        self.sess.add_all([c, u1, u2])
        self.sess.commit()

        s1 = associations.LanguageBExampleScore(user_id=u1.id,
                                                card_id=c.id,
                                                score=3)
        s2 = associations.LanguageBExampleScore(user_id=u2.id,
                                                card_id=c.id,
                                                score=1)

        self.sess.add_all([s1, s2])
        self.sess.commit()

        self.assertEqual(c.scores, [s1, s2])

        probe = cds.get_score(self.sess, u1, c)
        ans = 3
        self.assertEqual(probe, ans)

        probe = cds.get_score(self.sess, u2, c)
        ans = 1
        self.assertEqual(probe, ans)
Example #2
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)
Example #3
0
    def test_edit_score(self):
        import LanguageDeck.session_tools.session_scope as scp

        c = Cards.LanguageBVocab(text="Es sieht aus, wie du errungen hast.")
        u1 = Cards.User(name="dude")
        self.sess.add_all([c, u1])
        self.sess.commit()

        with scp.session_scope(self.session) as sess:
            cds.edit_score(sess, c, u1, 8)

        with scp.session_scope(self.session) as sess:
            probe = cds.get_score(sess, u1, c)
            ans = 8
            self.assertEqual(probe, ans)

        with scp.session_scope(self.session) as sess:
            cds.edit_score(sess, c, u1, 3)

        with scp.session_scope(self.session) as sess:

            c = sess.query(Cards.LanguageBVocab).filter_by(id=c.id).one()
            probe = cds.get_score(self.sess, u1, c)
            ans = 3
            self.assertEqual(probe, ans)
Example #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")
    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")
Example #6
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)
Example #7
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)
    def test_deletions(self):

        worda = Cards.LanguageAVocab(text="word1",
                                     date_created=datetime.date.today())
        self.sess.add(worda)

        wordb = Cards.LanguageAVocab()
        wordb.text = "word2"
        wordb.date_created = datetime.date.today()
        self.sess.add(wordb)

        fwordc = Cards.LanguageBVocab()
        fwordc.text = "translation11"
        fwordc.date_created = datetime.date.today()
        fwordc.translations.append(worda)
        self.sess.add(fwordc)

        fwordd = Cards.LanguageBVocab()
        fwordd.text = "translation12"
        fwordd.date_created = datetime.date.today()
        fwordd.translations.append(worda)
        fwordd.translations.append(wordb)

        self.sess.add(fwordd)
        self.sess.commit()

        self.sess.delete(fwordc)
        self.sess.commit()

        self.assertTrue(
            len(
                self.sess.query(Cards.LanguageAVocab).filter_by(
                    id=worda.id).one().translations) == 1)
        self.assertEqual(
            self.sess.query(Cards.LanguageAVocab).filter_by(
                id=worda.id).one().translations[0], fwordd)

        self.sess.delete(worda)
        self.sess.commit()

        self.assertTrue(
            len(
                self.sess.query(Cards.LanguageAVocab).filter_by(
                    id=wordb.id).one().translations) == 1)

        user = Cards.User(name="bob")
        user2 = Cards.User(name="sally")
        self.sess.add(user)
        self.sess.add(user2)
        self.sess.commit()

        las = associations.LanguageAVocabScore(user_id=1, card_id=2, score=3)
        las2 = associations.LanguageAVocabScore(user_id=2, card_id=2, score=5)

        wordb.scores.append(las)
        wordb.scores.append(las2)

        self.sess.commit()

        self.assertEqual(
            self.sess.query(associations.LanguageAVocabScore).filter_by(
                card_id=2, user_id=1).one().score, 3)

        self.sess.delete(user2)
        self.sess.commit()

        self.assertEqual(
            len(self.sess.query(associations.LanguageAVocabScore).all()), 1)

        self.sess.delete(wordb)
        self.sess.commit()

        self.assertEqual(
            len(self.sess.query(associations.LanguageAVocabScore).all()), 0)