PMA-2020 / pma-api

The best way to programmatically access PMA2020 data.
http://api.pma2020.org
MIT License
1 stars 3 forks source link

Add unit test to check various database functionality #40

Open joeflack4 opened 6 years ago

joeflack4 commented 6 years ago

Description

Add unit test to check database functionality.

Example code

This is from: http://flask.pocoo.org/docs/0.12/testing/

class TestDB(unittest.TestCase):
    """Test database functionality."""

    def setUp(self):
        """Set up: (1) Put Flask app in test mode, (2) Create temp DB."""
        import tempfile
        from manage import initdb
        self.db_fd, app.config['DATABASE'] = tempfile.mkstemp()
        app.testing = True
        self.app = app.test_client()
        with app.app_context():
            initdb()

    def tearDown(self):
        """Tear down: (1) Close temp DB."""
        os.close(self.db_fd)
        os.unlink(app.config['DATABASE'])

    def test_empty_db(self):
        """Test empty database."""
        resp = self.app.get('/')
        assert b'No entries here so far' in resp.data