Skip to content

Commit

Permalink
add post scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
sunForest committed May 12, 2015
1 parent 56ff244 commit 1e9bd9a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions e2e/features/postcards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ Feature: /postcards

Scenario: GET
Given server has 5 postcards
When GET "/postcards"
When GET "/postcards/"
Then request will success(200)
And return 5 items
And is like
"""
[{
"message" : "Hello",
"cover": "http://world.com/0.png",
"sender" : "me"
"sender": "someone"
}]
"""

Scenario: POST
Given server has 3 postcards
When POST "/postcards/" with params {"message":"Hello with image"} and file "test_image.jpg"
Then request will success(201)

15 changes: 15 additions & 0 deletions e2e/features/steps/crud.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from urlparse import urljoin

from behave import given, when, then
Expand Down Expand Up @@ -31,6 +32,20 @@ def step_impl(context, url):
context.response = requests.get(urljoin(base_url, url))
print(context.response.text)

@when('POST "{url:S}" with params {params} and file "{image}"')
def step_impl(context, url, params, image):
# refactory this
base_url = context.config.userdata.get('base_url')
attrs = json.loads(params)
headers = {'Content-Type': 'multipart/form-data'}
with open(image) as fp:
files = {
'cover': fp
}
context.response = requests.post(urljoin(base_url, url),
files=files, data=attrs)



@then('request will {:w}({code:d})')
def step_impl(context, _, code):
Expand Down
Binary file added e2e/features/test_image.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ psycopg2==2.6
requests==2.6.0
wsgiref==0.1.2
Unipath==1.1
behave==1.2.5
sure==1.2.12
inflection==0.3.1
json-schema-generator==0.3
jsonschema==0.8.0
django-autofixture==0.10.0

0 comments on commit 1e9bd9a

Please sign in to comment.