cybertk / abao

REST API automated testing tool based on RAML
MIT License
354 stars 59 forks source link

Test with POST data #149

Open AndreaCrotti opened 8 years ago

AndreaCrotti commented 8 years ago

I'm trying to test a simple API that takes an email in the POST data and return something else. So I defined my raml file like this:

/abao-check/:
  post:
    body:
      application/x-www-form-urlencoded:
        example: |
          {"email": "email@mail.com"}

    responses:
      201:
        body:
          application/json:
            schema: |
              {
                "$schema": "http://json-schema.org/draft-03/schema",
                "type": "object",
                "required": ["email"],
                "properties": {"email": {"type": "string"}}
              }

but no matter what I do it doesn't seem it's never putting any body in request.POST. Any idea why?

Am I missing something obvious? by the way I think it would be great to have some examples of RAML files to test in this project, would make it easy to see what it can be done.. Thanks a lot!

plroebuck commented 8 years ago

Abao doesn't currently support form-based submissions (a.k.a. application/x-www-form-urlencoded), only JSON-based media types.

As far as examples go, there are RAML/schema files in the test/fixtures folder.

plroebuck commented 8 years ago

Sorry. I wrote response yesterday, but left without posting it.

AndreaCrotti commented 8 years ago

Ah ok thanks no problem @plroebuck I'll close the issue, is it a feature you want to implement anyway?

coltonlw commented 8 years ago

@AndreaCrotti Abao support for url-encoded form data is something I hope to see added eventually as well, and I will contribute to that feature if I can. However I think in your case the problem is with the way you defined your specification. The data in your request example is clearly JSON, so I would recommend changing your specification to use a content-type of application/json:

/abao-check/:
  post:
    body:
      application/json:
        example: |
          {"email": "email@mail.com"}

If that endpoint actually does accept a url-encoded form with an "email" field, putting JSON as the example for the request body is confusing. This tutorial on raml.org gives an example of how to document a form (using formParameters directive). http://raml.org/developers/raml-200-tutorial#body-parameters

AndreaCrotti commented 7 years ago

This is still an open issue right @coltonlw ?

coltonlw commented 7 years ago

@AndreaCrotti I believe so, we are using Postman collections run via newman CLI runner for postman to test url encoded or multipart form data and file uploads