コード例 #1
0
ファイル: test_story.py プロジェクト: yasfatft/bddrest
def test_from_dict():
    data = dict(base_call=dict(
        title='Binding',
        url='/apiv1/devices/:name',
        verb='POST',
        as_='visitor',
        url_parameters=dict(name='SM-12345678'),
        form=dict(activationCode='746727', phone='+9897654321'),
        headers=['X-H1: Header Value'],
        response=dict(status='200 OK',
                      headers=[
                          'Content-Type: application/json;charset=utf-8',
                          'X-Pagination-Count: 10'
                      ],
                      json={
                          'secret': 'ABCDEF',
                          'code': 745525,
                          'query': ''
                      })),
                calls=[
                    dict(title='Trying invalid code',
                         form=dict(activationCode='badCode'),
                         response=dict(
                             headers=['Content-Type: text/plain;utf-8'],
                             status='400 Bad Request',
                         ))
                ])
    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], AlteredCall)
    assert loaded_story.base_call.response.status == 200
    assert data == loaded_story.to_dict()
コード例 #2
0
def test_markdown():
    def get_field_info(resource, verb, name):
        return dict(f1=dict(required=True, not_none=True,
                            type='str'), ).get(name)

    story = Story.loads(provided_story)
    outfile = io.StringIO()
    story.document(outfile, fieldinfo=get_field_info)
    outputstring = outfile.getvalue()
    assert expected_markdown == outputstring
コード例 #3
0
ファイル: test_story.py プロジェクト: yasfatft/bddrest
def test_dump_load_file():
    with tempfile.TemporaryFile(mode='w+', encoding='utf-8') as temp_file:
        call = dict(title='Binding',
                    url='/apiv1/devices/name: SM-12345678',
                    verb='POST',
                    as_='visitor',
                    form=dict(activationCode='746727', phone='+9897654321'),
                    headers=[('X-H1', 'Header Value')])
        with Given(wsgi_application, **call):
            assert response.status == '200 OK'
            when('Trying invalid code', form=dict(activationCode='badCode'))
            story.dump(temp_file)

        temp_file.seek(0)
        loaded_story = Story.load(temp_file)
        assert loaded_story.verify(wsgi_application) is None
コード例 #4
0
ファイル: test_story.py プロジェクト: yasfatft/bddrest
def test_dump_load():
    call = dict(title='Binding',
                url='/apiv1/devices/name: SM-12345678',
                verb='POST',
                as_='visitor',
                form=dict(activationCode='746727', phone='+9897654321'),
                headers=[('X-H1', 'Header Value')])
    with Given(wsgi_application, **call):
        assert response.status == '200 OK'
        when('Trying invalid code', form=dict(activationCode='badCode'))
        assert response.status == 400

        dumped_story = story.dumps()
        loaded_story = Story.loads(dumped_story)
        assert story.to_dict() == loaded_story.to_dict()
        loaded_story.validate()
コード例 #5
0
ファイル: test_story.py プロジェクト: yasfatft/bddrest
def test_verify():
    call = dict(title='Binding',
                url='/apiv1/devices/name: SM-12345678',
                verb='POST',
                as_='visitor',
                form=dict(activationCode='746727', phone='+9897654321'),
                headers=[('X-H1', 'Header Value')])
    with Given(wsgi_application, **call):
        assert response.status == '200 OK'
        when('Trying invalid code', form=dict(activationCode='badCode'))
        dumped_story = story.dumps()

    loaded_story = Story.loads(dumped_story)
    loaded_story.verify(wsgi_application)

    loaded_story.base_call.response.body = '{"a": 1}'

    with pytest.raises(CallVerifyError):
        loaded_story.verify(wsgi_application)