2

I am a newbie in python and currently learning how to write BDD tests using Lettuce (python). I have a very simple REST API based on Flask framework. I am bit stuck at the point in calling the functions under the app.route. For example my API looks like this

@app.route('/')
@app.route('/documentation')
def documentation():
    return auto.html()

My lettuce tests are in a folder called features. This folder features has two files called test.feature and steps.py. test.feature contains the following features.

   Feature: To test the root of API

   Scenario: Call the root of the API
      Given I have "/" or "/documentation" 
      When the user requests GET '/' 
      Then I response should be "GET HTTP/1.1 200".

definitions are written in steps.py file as follows.

   @step('I have "([^"]*)" or "([^"]*)"')
   def display_api(step, value, option):
      print ('Attempting to display the API docs..')
      -----

I am not sure how I can call @app.route('/') to run the tests and return the status 200 to lettuce or how will lettuce run the tests? I went through the lettuce documentation and I am still not able to figure out how to do a automated test to my REST API. Any suggestion or support will be much appreciated. Thanks in advance for your time.

divspec
  • 53
  • 1
  • 7

1 Answers1

0

Indeed you do not need to call @app.route('/') directly to run the tests, you only have to describe steps and test cases. Then you run lettuce tool, which goes through tests:

    $ lettuce test/features/

    Feature: .... # test/features/user.feature:1
    Scenario:  ...

and so on.

Here's more information: https://semaphoreci.com/community/tutorials/bdd-testing-a-restful-web-application-in-python

Eugene Lisitsky
  • 12,113
  • 5
  • 38
  • 59