5

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

2

2 Answers 2

5

Use boddle for unit testing if you want access to the normal bottle syntax. 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()
1

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.