Skip to content

Commit

Permalink
Simple test to start
Browse files Browse the repository at this point in the history
  • Loading branch information
pylover committed Jun 11, 2018
1 parent 9a0d29d commit d59c94e
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Toolchain to define and verify REST API in BDD.


[![Build Status](http://img.shields.io/pypi/v/bddrest.svg)](https://pypi.python.org/pypi/bddrest)

Table of Contents
Expand Down
76 changes: 76 additions & 0 deletions bddrest/tests/test_assertion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import cgi
import functools
import json
import tempfile
import unittest

from bddrest.authoring import given, when, then, composer, response, and_
from bddrest.exceptions import InvalidUrlParametersError, CallVerifyError
from bddrest.specification import Call, When
from bddrest.story import Story


def wsgi_application(environ, start_response):
form = cgi.FieldStorage(
fp=environ['wsgi.input'],
environ=environ,
strict_parsing=False,
keep_blank_values=True
)

try:
code = int(form['activationCode'].value) ^ 1234
except ValueError:
start_response('400 Bad Request', [('Content-Type', 'text/plain;utf-8')])
return

start_response('200 OK', [
('Content-Type', 'application/json;charset=utf-8'),
('X-Pagination-Count', '10')
])
result = json.dumps(dict(
secret='ABCDEF',
code=code,
query=environ['QUERY_STRING']
))
yield result.encode()


class AssertionTestCase(unittest.TestCase):

def test_equality(self):

call = dict(
title='Binding and registering the device after verifying the activation code',
description=\
'As a new visitor I have to bind my device with activation code and phone number',
url='/apiv1/devices/name: SM-12345678',
verb='POST',
as_='visitor',
query=dict(
a=1,
b=2
),
form=dict(
activationCode='746727',
phone='+9897654321'
)
)
with given(wsgi_application, **call):
then(
response.status == '200 OK',
response.status_code == 200
)
when(
'Trying invalid code',
form=dict(
activationCode='badCode'
)
)

then(response.status_code == 400)


if __name__ == '__main__': # pragma: no cover
unittest.main()

0 comments on commit d59c94e

Please sign in to comment.