Skip to content

Commit

Permalink
Feature/mockup (#61)
Browse files Browse the repository at this point in the history
* added easycli moudal to bddrest

* Edited import order!

* Migrated to easycli (#51)

* added easycli moudal to bddrest

* Edited import order!

* Deleted def main

* added command mockupserver.

* Add mockup controller

* Add mockupserver controller

* Resolve conflict

* Resolved  conflict

* v2.2.1

* Beautiful is better ugly.

* Beautiful is better ugly.

* Fix a conflict in rebase

* Fix a conflict in rebase

* Repr function added to call

* Repr function added to call

* Fix some bug

* Add mockup

* Fix a conflict in rebase

* Changed test in test_cli

* Changed test in test_cli

* Changed cli test

* Changed cli test
  • Loading branch information
mohadese-yousefi authored and pylover committed Mar 2, 2019
1 parent 516d778 commit b9a9084
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
26 changes: 25 additions & 1 deletion bddrest/mockupserver/__init__.py
@@ -1,7 +1,7 @@
import sys
import json

from easycli import SubCommand, Argument
#from bddrest.mockupserver.controller import MockupController


class MockupServer(SubCommand):
Expand All @@ -16,7 +16,31 @@ class MockupServer(SubCommand):
]

def __call__(self, args):
from nanohttp import Controller, HTTPNotFound, context
from ..authoring import Story
with open(args.story) as story_file:
story = Story.load(story_file)

class RootMockupController(Controller):

def __init__(self):
self.stories = []

def add_story(self, story):
self.stories.append(story)

def server(self, call):
for k, v in call.response.headers:
context.response_headers.add_header(k, v)
yield call.response.text.encode()

def __call__(self, *remaining_paths):
calls = [story.base_call] + story.calls
for call in calls:
url = call.url.replace(':', '')
if set(url.strip('/').split('/')) == set(remaining_paths) :
return self.server(call)
raise HTTPNotFound()

from nanohttp import quickstart
quickstart(RootMockupController())
14 changes: 0 additions & 14 deletions bddrest/mockupserver/controller.py
@@ -1,14 +0,0 @@
from nanohttp.controllers import Controller


class MockupController(Controller):

def __init__(self):
self.stories = []

def add_story(self, story):
self.stories.append(story)

def __call__(self, *remaining_paths):
raise NotImplementedError

17 changes: 5 additions & 12 deletions bddrest/tests/test_cli.py
@@ -1,5 +1,5 @@

from bddcli import Command, when, stdout, status, stderr, Application
from bddcli import Given, when, stdout, status, stderr, Application

from bddrest.tests.helpers import standard_files_mockup

Expand All @@ -8,21 +8,15 @@


def test_document_cli():
with Command(
app,
'Pass document for generate markdown',
stdin=yamlstory,
arguments=['document']
):
assert status == 0
with Given(app, ['document']):
when(stdin=yamlstory)
assert stderr == ''
assert status == 0
assert stdout == expected_markdown


def test_help():
with Command(app, 'Without any pramater for getting help.'):
assert status == 0
assert stderr == ''
with Given(app):
assert stdout == expected_help


Expand Down Expand Up @@ -55,7 +49,6 @@ def test_help():
id: None
'''


expected_markdown = '''\
## Posting a book
Expand Down
1 change: 1 addition & 0 deletions requirements-ci.txt
@@ -1,4 +1,5 @@
coverage
coveralls
pytest-cov
bddcli >= 2, < 3

1 change: 0 additions & 1 deletion requirements-dev.txt
@@ -1,5 +1,4 @@
-r requirements-ci.txt
bddcli
pytest-pudb
ipython

3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -13,7 +13,8 @@
'pyyaml',
'argcomplete',
'pytest >= 4.0.2',
'easycli'
'easycli',
'nanohttp'
]


Expand Down

0 comments on commit b9a9084

Please sign in to comment.