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 Answers
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()
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.
-
see github.com/keredson/boddle for said bottle syntax niceties :)– keredsonCommented Dec 23, 2016 at 21:16