Skip to content

Commit

Permalink
Renaming Given -> FirstCall, When -> AlteredCAll, Composer -> Given, …
Browse files Browse the repository at this point in the history
…composer -> story
  • Loading branch information
pylover committed Jul 13, 2018
1 parent 84d6c1b commit ead528e
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 75 deletions.
2 changes: 1 addition & 1 deletion bddrest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from .specification import Call, FirstCall, AlteredCall
from .specification import Call, FirstCall, AlteredCall, HeaderSet, HTTPStatus
from .authoring import Given, when, story, response, Story
from .exceptions import InvalidUrlParametersError, CallVerifyError

Expand Down
8 changes: 7 additions & 1 deletion bddrest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def launch(self, args=None):
super().launch()


root_launcher = None


def main():
return MainLauncher()
global root_launcher
if root_launcher is None:
root_launcher = MainLauncher()
return root_launcher()

2 changes: 1 addition & 1 deletion bddrest/documentary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def create_parser(cls, subparsers):
return parser

def convert_file(self, source, destination):
from ..story import Story
from ..authoring import Story
story = Story.load(source)
story.document(destination, formatter_factory=self.formatters[self.args.format])

Expand Down
44 changes: 44 additions & 0 deletions bddrest/tests/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,50 @@ def test_altered_call():
)


def test_alteredcall_setters_deleters():
basecall = FirstCall(
'Base call for testing When class',
url='/apiv1/devices/id: 1',
)

when = AlteredCall(
basecall,
title='Testing the When class',
url='/apiv1/books/isbn: abc/pages/page: 3?highlight=false',
verb='POST',
form=dict(a='b'),
headers=['A: B'],
content_type='text/plain',
as_='Admin',
extra_environ=dict(A='B')
)
assert '/apiv1/books/:isbn/pages/:page' == when.url
assert dict(isbn='abc', page='3') == when.url_parameters
assert dict(highlight='false') == when.query
assert dict(a='b') == when.form
assert 'POST' == when.verb
assert 'A' in when.headers
assert 'text/plain' == when.content_type
assert 'Admin' == when.as_
del when.url_parameters
del when.verb
del when.headers
del when.query
del when.content_type
del when.as_
del when.extra_environ
del when.form

assert dict(id='1') == when.url_parameters
assert 'GET' == when.verb
assert when.headers is None
assert when.query is None
assert when.form is None
assert when.content_type is None
assert when.as_ is None
assert when.extra_environ is None


def test_call_verify():
call = FirstCall('Testing FirstCall contractor', url='/id: 1', query=dict(a=1))
call.conclude(wsgi_application)
Expand Down
3 changes: 1 addition & 2 deletions bddrest/tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from bddrest import main
from bddrest.cli import main
from bddrest.tests.helpers import standard_files_mockup


Expand Down Expand Up @@ -115,4 +115,3 @@ def test_help():
document Generates REST API Documentation from standard input to standard
output.
'''

2 changes: 1 addition & 1 deletion bddrest/tests/test_documentary.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import io

from bddrest.story import Story
from bddrest import Story


def test_markdown():
Expand Down
48 changes: 0 additions & 48 deletions bddrest/tests/test_given.py

This file was deleted.

2 changes: 1 addition & 1 deletion bddrest/tests/test_headers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import re

from bddrest.specification.headerset import HeaderSet
from bddrest import HeaderSet


def test_constructor():
Expand Down
38 changes: 18 additions & 20 deletions bddrest/tests/test_story.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import pytest

from bddrest.authoring import given, when, composer, response
from bddrest.exceptions import InvalidUrlParametersError, CallVerifyError
from bddrest.specification import Call, When
from bddrest.story import Story
from bddrest import Given, when, story, response, InvalidUrlParametersError, \
CallVerifyError, Call, AlteredCall, Story


def wsgi_application(environ, start_response):
Expand Down Expand Up @@ -58,8 +56,8 @@ def test_given_when():
phone='+9897654321'
)
)
with given(wsgi_application, **call) as r:
assert r is response
with Given(wsgi_application, **call) as s:
assert s.response is response._resolver()
assert response.status == '200 OK'
assert response.status == 200
assert 'secret' in response.json
Expand Down Expand Up @@ -94,7 +92,7 @@ def test_url_parameters():
),
)

with given(wsgi_application, **call):
with Given(wsgi_application, **call):
assert response.status == '200 OK'

with pytest.raises(InvalidUrlParametersError):
Expand Down Expand Up @@ -131,7 +129,7 @@ def test_url_parameters():
),
)

with given(wsgi_application, **call):
with Given(wsgi_application, **call):
assert response.status == '200 OK'

def test_to_dict():
Expand All @@ -147,7 +145,7 @@ def test_to_dict():
),
headers=[('X-H1', 'Header Value')]
)
with given(wsgi_application, **call):
with Given(wsgi_application, **call):
assert response.status == '200 OK'
when(
'Trying invalid code',
Expand All @@ -158,7 +156,7 @@ def test_to_dict():
)
assert response.status == 400

story_dict = composer.to_dict()
story_dict = story.to_dict()
assert story_dict['base_call'] == dict(
title='Binding',
description='Awesome given description',
Expand Down Expand Up @@ -231,7 +229,7 @@ def test_from_dict():
loaded_story = Story.from_dict(data)
assert loaded_story is not None
assert isinstance(loaded_story.base_call, Call)
assert isinstance(loaded_story.calls[0], When)
assert isinstance(loaded_story.calls[0], AlteredCall)
assert loaded_story.base_call.response.status == 200
assert data == loaded_story.to_dict()

Expand All @@ -248,7 +246,7 @@ def test_dump_load():
),
headers=[('X-H1', 'Header Value')]
)
with given(wsgi_application, **call):
with Given(wsgi_application, **call):
assert response.status == '200 OK'
when(
'Trying invalid code',
Expand All @@ -258,9 +256,9 @@ def test_dump_load():
)
assert response.status == 400

dumped_story = composer.dumps()
dumped_story = story.dumps()
loaded_story = Story.loads(dumped_story)
assert composer.to_dict() == loaded_story.to_dict()
assert story.to_dict() == loaded_story.to_dict()
loaded_story.validate()


Expand All @@ -276,15 +274,15 @@ def test_verify():
),
headers=[('X-H1', 'Header Value')]
)
with given(wsgi_application, **call):
with Given(wsgi_application, **call):
assert response.status == '200 OK'
when(
'Trying invalid code',
form=dict(
activationCode='badCode'
)
)
dumped_story = composer.dumps()
dumped_story = story.dumps()

loaded_story = Story.loads(dumped_story)
loaded_story.verify(wsgi_application)
Expand All @@ -308,15 +306,15 @@ def test_dump_load_file():
),
headers=[('X-H1', 'Header Value')]
)
with given(wsgi_application, **call):
with Given(wsgi_application, **call):
assert response.status == '200 OK'
when(
'Trying invalid code',
form=dict(
activationCode='badCode'
)
)
composer.dump(temp_file)
story.dump(temp_file)

temp_file.seek(0)
loaded_story = Story.load(temp_file)
Expand All @@ -334,7 +332,7 @@ def test_url_overriding():
),
)

with given(wsgi_application, **call):
with Given(wsgi_application, **call):
assert response.status == '200 OK'

modified_call = when(
Expand All @@ -359,7 +357,7 @@ def wsgi_application(environ, start_response):
yield json.dumps(result).encode()


with given(
with Given(
wsgi_application, title='Testing authorization header',
url='/',
authorization='testuser'
Expand Down

0 comments on commit ead528e

Please sign in to comment.