Skip to content

Unit Tests

agrov edited this page Feb 14, 2020 · 4 revisions

Unit tests for my Flask Application can be found under FlaskWithMongoDB-master/unit_test.py. I used Python's famous unittest library for writing the unit tests for my project.The unittest module provides a rich set of tools for constructing and running tests.I also used MockupDB to test my application. It is a Mock server for testing MongoDB clients and creating MongoDB Wire Protocol servers.I set up the tests using the below function:

def setUp(self):
    app.config['TESTING'] = True
    app.config['WTF_CSRF_ENABLED'] = False
    app.config['DEBUG'] = False
    self.app = app.test_client()
    app.config['MONGO_URI'] = environ.get('MONGO_URI')
    self.app = app.test_client()
    self.server = MockupDB(auto_ismaster=True, verbose=True)
    self.server.run()
    pass

One of the tests that I implemented was to validate the values in Gender Variable. I wrote the below mentioned function for the same:

def test_valid_gender_values(self):
    cursor=stu_col.find({})
    stu_col1=stu_col.find({})
    for i in stu_col1:
        self.assertIn(i['Gender'],'M|F')

All other unit tests which I used can be found in file unit_test.py

Clone this wiki locally