예제 #1
0
    def test_send_book_list_email(self):
        u = User(username='******', email='*****@*****.**')
        b1title = 'hello'
        b2title = 'world'
        b1 = Book(title=b1title,
                  author='b',
                  date_of_purchase=datetime.utcnow(),
                  notes='Test Notes')
        b2 = Book(title=b2title,
                  author='d',
                  date_of_purchase=datetime.utcnow(),
                  notes='Test Notes')

        db.session.add(u)
        db.session.add(b1)
        db.session.add(b2)
        db.session.commit()
        u.add_book_owned(b1)
        u.add_book_owned(b2)
        db.session.commit()
        b = u.owned_books()
        subject = 'test'
        sender = '*****@*****.**'
        recipients = '*****@*****.**'
        text_body = 'text mctest'
        html_body = '<div>testing</div>'
        mail = Mail(self.app)
        with mail.record_messages() as outbox:
            send_book_list_email(u, recipients, b)
            assert len(outbox) == 1
            book1 = outbox[0].body.find('hello')
            book2 = outbox[0].body.find('world')
            assert book1 > 0
            assert book2 > 0
예제 #2
0
    def test_add_book_owned(self):
        u = User(username='******', email='*****@*****.**')
        b = Book(title='The Brothers\' War',
                 author='Grubb, Jeff',
                 date_of_purchase=datetime.utcnow(),
                 notes='Test Notes')
        db.session.add(u)
        db.session.add(b)
        db.session.commit()
        self.assertEqual(u.owned.all(), [])

        u.add_book_owned(b)
        db.session.commit()
        self.assertTrue(u.owns_book(b))
        self.assertEqual(u.owned.count(), 1)
        self.assertEqual(u.owned.first().author, 'Grubb, Jeff')

        u.remove_book_owned(b)
        db.session.commit()
        self.assertFalse(u.owns_book(b))
        self.assertEqual(u.owned.count(), 0)