コード例 #1
0
    def test_model(self):
        """Creates some new objects in the database and tries to query
        them.

        """

        # Creates some authors
        author1 = Author()
        author1.first_name = "Pascal"
        author1.last_name = "Hartig"

        author2 = Author()
        author2.first_name = "Ali"
        author2.last_name = "Afshar"

        session.add_all([author1, author2])
        session.commit()

        # Catch unique constraint failures
        author3 = Author()
        author3.first_name = "Pascal"
        author3.last_name = "Hartig"
        session.add(author3)

        assert_raises(IntegrityError, lambda: session.commit())
        session.rollback()

        self._test_author_queries()
コード例 #2
0
 def test_objects(self):
     assert session.query(self.Note).count() == 0
     for t in 'abcdef':
         n = self.Note()
         n.title = n.note = n.importance = t
         session.add(n)
     session.commit()
     assert session.query(self.Note).count() == 6
コード例 #3
0
ファイル: notes.py プロジェクト: passy/glashammer-rdrei
def edit_submit_view(req, nid):
    # find note
    note = session.query(Note).get(nid)
    # TODO: check if note exists
    note.title = req.form.get('title')
    note.note = req.form.get('text')
    note.importance = req.form.get('importance')
    session.add(note)
    session.commit()
    return render_response('notes_success.jinja')
コード例 #4
0
ファイル: notes.py プロジェクト: passy/glashammer-rdrei
def add_view(req):
    # validate form
    title = req.form.get('title', 'kT')
    text = req.form.get('text')
    prio = req.form.get('importance')
    if not text:
        text = "kT"
    note = Note(title, text, prio)
    session.add(note)
    session.commit()
    return render_response('notes_success.jinja')