O'Reilly logo

Python Requests Essentials by Bala Subrahmanyam Varanasi, Rakesh Vidya Chandra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing unit tests to survey applications

Creating an application without test cases is half done. Even though you take a lot of care while developing the application, there might be a chance of encountering errors at some point. Writing test cases will always leave us at a safe point.

In this section, we are going to write unit test cases for some tasks in our survey application. Add the following test case code to survey/tests.py file:

import unittest import requests from bs4 import BeautifulSoup from survey import db from survey.models import Question class TestSurveyApp(unittest.TestCase): def setUp(self): db.drop_all() db.create_all() def test_defaults(self): question = Question('Are you from India?') db.session.add(question) db.session.commit() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required