Exemplo n.º 1
0
def database(app):
    with app.app_context():
        db.init_app(app)
        db.create_all()
        yield app
        db.session.close()
        db.drop_all()
Exemplo n.º 2
0
    def test_creating_bucketlist(self):
        """Tests successfully creating a bucketlist"""

        # this test would conflict with bucketlist defined in the setup
        # clear everythin before running it
        db.drop_all()
        db.create_all()

        # Instantiating a bucketlist object
        bucketlist = Bucketlist("Cook")
        # save the object to database
        db.session.add(bucketlist)
        db.session.commit()

        # asssert the attributes
        self.assertEqual(bucketlist.id, 1)
        self.assertEqual(bucketlist.name, "Cook")
        self.assertEqual(bucketlist.created_by, None)
        year = str(datetime.today().year)
        self.assertIn(year, str(bucketlist.date_created))
        self.assertIn(year, str(bucketlist.date_modified))
        self.assertEqual(len(bucketlist.items), 0)

        # test querying bucketlists
        bucketlist_query = Bucketlist.query.all()
        self.assertIn("<Bucketlist 'Cook'>", str(bucketlist_query))
        self.assertFalse("<Bucketlist 'Random'>" in str(bucketlist_query))
Exemplo n.º 3
0
    def test_creating_bucketlist_with_a_missing_name(self):
        """Tests successfully creating a bucketlist"""

        # this test would conflict with bucketlist defined in the setup
        # clear everythin before running it
        db.drop_all()
        db.create_all()

        with self.assertRaises(Exception) as context:

            # Instantiating a bucketlist object
            bucketlist = Bucketlist()
            # save the object to database
            db.session.add(bucketlist)
            db.session.commit()
            self.assertEqual('kjfdjkgf', 'nndnnv')
Exemplo n.º 4
0
def reset_db():
    db.drop_all()
    db.create_all()
Exemplo n.º 5
0
 def init_db():
     db.drop_all()
     db.create_all()
Exemplo n.º 6
0
 def tearDown(self):
     db.session.remove()
     db.drop_all()
Exemplo n.º 7
0
 def tearDown(self):
     db.drop_all()