How to unit test using Bottle system

I have some API endpoints that I need to test and I'm not sure where to start. I am using the Bottle environment and one of the methods I am testing reads a parameter from a request. How can I simulate this in a test environment?

+3


source to share


2 answers


The bottle lacks some of the testing subtleties that Flask has (see here) . But Bottle recommends using the WSGI Testing Tools along with the regular unit testing framework ( http://bottlepy.org/docs/dev/recipes.html#functional-testing-bottle-applications ). You won't have access to bottle syntax or parameters passed to templates, etc., but you won't need to run a separate server either.



+1


source


Use boddle for unit testing if you want to access the syntax of a regular bottle. Example:



import bottle, unittest
from boddle import boddle


@bottle.get('/woot')
def woot():
  return bottle.request.params['name']


class TestIt(unittest.TestCase):
  def testWoot(self):
    with boddle(params={'name':'derek'}):
      self.assertEqual(woot(), 'derek')


if __name__=='__main__':
  unittest.main()

      

0


source







All Articles