コード例 #1
0
ファイル: test_inspector.py プロジェクト: atbentley/plank
def test_materialise_tasks_replaces_task_names_with_actual_tasks(inspector):
    task_a = create_mock(pre_req_tasks=['task_b'])
    task_b = create_mock(pre_req_tasks=[])
    inspector.tasks = {'task_a': task_a, 'task_b': task_b}
    inspector.materialise_tasks()

    assert task_a.pre_req_tasks == [task_b]
コード例 #2
0
    def test_should_create_mock_with_three_properties_when_three_properties_given(
            self):

        actual = create_mock(foo='bar', spam='eggs', hello='world')

        assert_that(actual.foo, equal_to('bar'))
        assert_that(actual.spam, equal_to('eggs'))
コード例 #3
0
    def test_should_create_mock_using_given_specification(self):
        class SpecificationClass(object):
            pass

        actual = create_mock(SpecificationClass)

        assert_that(actual, instance_of(SpecificationClass))
コード例 #4
0
    def test_should_create_mock_using_given_specification(self):

        class SpecificationClass(object):
            pass

        actual = create_mock(SpecificationClass)

        assert_that(actual, instance_of(SpecificationClass))
コード例 #5
0
async def test_put_should_return_404_when_property_does_not_exist(
        endpoint: PropertyEndpoint, model_1: Model):
    request = create_mock(
        method='PUT', json=coroutine(lambda: {'does_not_exist': 'vertical'}))

    response = await endpoint.put(request, model_1.id, 'does_not_exist')

    assert response.status == 404
コード例 #6
0
    def test_should_create_mock_using_given_specification_and_properties(self):
        class SpecificationClass(object):
            pass

        actual = create_mock(SpecificationClass, bar='foo', eggs='spam')

        assert_that(actual, instance_of(SpecificationClass))
        assert_that(actual.bar, equal_to('foo'))
        assert_that(actual.eggs, equal_to('spam'))
コード例 #7
0
async def test_put_should_overwrite_property(endpoint: PropertyEndpoint, model_1: Model):
    request = create_mock(method='PUT', json=coroutine(lambda: {'name': 'vertical'}))

    response = await endpoint.put(request, model_1.id, 'name')

    assert model_1.name == 'vertical'
    assert json.loads(response.body.decode('utf-8')) == {'name': 'vertical'}
    assert response.status == 200
    assert response.content_type == 'application/json'
コード例 #8
0
async def test_put_should_overwrite_existing_model(endpoint: InstanceEndpoint, model_1: Model, models: dict):
    request = create_mock(method='PUT', json=coroutine(lambda: {'name': 'john', 'age': 3}))

    response = await endpoint.put(request, instance_id=model_1.id)

    assert len(models) == 2
    assert models[model_1.id].name == 'john' and models[model_1.id].age == 3
    assert response.status == 201
    assert response.content_type == 'application/json'
コード例 #9
0
async def test_put_should_create_a_new_model(endpoint: InstanceEndpoint, models: dict):
    instance_id = uuid.uuid4().hex
    request = create_mock(method='PUT', json=coroutine(lambda: {'name': 'john', 'age': 3}))

    response = await endpoint.put(request, instance_id=instance_id)

    assert [model for model in models.values() if model.id == instance_id and model.name == 'john' and model.age == 3]
    assert response.status == 201
    assert response.content_type == 'application/json'
コード例 #10
0
    def test_should_create_mock_using_given_specification_and_properties(self):

        class SpecificationClass(object):
            pass

        actual = create_mock(SpecificationClass, bar='foo', eggs='spam')

        assert_that(actual, instance_of(SpecificationClass))
        assert_that(actual.bar, equal_to('foo'))
        assert_that(actual.eggs, equal_to('spam'))
コード例 #11
0
async def test_put_should_overwrite_property(endpoint: PropertyEndpoint,
                                             model_1: Model):
    request = create_mock(method='PUT',
                          json=coroutine(lambda: {'name': 'vertical'}))

    response = await endpoint.put(request, model_1.id, 'name')

    assert model_1.name == 'vertical'
    assert json.loads(response.body.decode('utf-8')) == {'name': 'vertical'}
    assert response.status == 200
    assert response.content_type == 'application/json'
コード例 #12
0
async def test_post_with_id_defined_should_raise_401(
        endpoint: CollectionEndpoint):
    request = create_mock(method='POST',
                          json=coroutine(lambda: {
                              'name': 'henry',
                              'age': 469,
                              'id': 123
                          }))

    with pytest.raises(HttpBadRequest):
        await endpoint.post(request)
コード例 #13
0
async def test_post_should_create_new_model(endpoint: CollectionEndpoint, resource: RestResource, models):
    request = create_mock(method='POST', json=coroutine(lambda: {'name': 'henry', 'age': 469}))

    response = await endpoint.post(request)
    assert response.status == 201
    assert response.content_type == 'application/json'
    person = json.loads(response.body.decode('utf-8'))
    assert response.headers['LOCATION'] == '/{name}/{id}'.format(name=resource.name, id=person['id'])
    assert person['name'] == 'henry'
    assert person['age'] == 469
    assert person in [resource.render(model) for model in models.values()]
    assert len(models) == 3
コード例 #14
0
async def test_put_should_overwrite_existing_model(endpoint: InstanceEndpoint,
                                                   model_1: Model,
                                                   models: dict):
    request = create_mock(method='PUT',
                          json=coroutine(lambda: {
                              'name': 'john',
                              'age': 3
                          }))

    response = await endpoint.put(request, instance_id=model_1.id)

    assert len(models) == 2
    assert models[model_1.id].name == 'john' and models[model_1.id].age == 3
    assert response.status == 201
    assert response.content_type == 'application/json'
コード例 #15
0
async def test_put_should_create_a_new_model(endpoint: InstanceEndpoint,
                                             models: dict):
    instance_id = uuid.uuid4().hex
    request = create_mock(method='PUT',
                          json=coroutine(lambda: {
                              'name': 'john',
                              'age': 3
                          }))

    response = await endpoint.put(request, instance_id=instance_id)

    assert [
        model for model in models.values()
        if model.id == instance_id and model.name == 'john' and model.age == 3
    ]
    assert response.status == 201
    assert response.content_type == 'application/json'
コード例 #16
0
async def test_post_should_create_new_model(endpoint: CollectionEndpoint,
                                            resource: RestResource, models):
    request = create_mock(method='POST',
                          json=coroutine(lambda: {
                              'name': 'henry',
                              'age': 469
                          }))

    response = await endpoint.post(request)
    assert response.status == 201
    assert response.content_type == 'application/json'
    person = json.loads(response.body.decode('utf-8'))
    assert response.headers['LOCATION'] == '/{name}/{id}'.format(
        name=resource.name, id=person['id'])
    assert person['name'] == 'henry'
    assert person['age'] == 469
    assert person in [resource.render(model) for model in models.values()]
    assert len(models) == 3
コード例 #17
0
ファイル: test_runner.py プロジェクト: atbentley/plank
def circular_dependency_task():
    task = create_mock(Task)
    when(task).has_circular_dependency().then_return(True)
    return task
コード例 #18
0
async def test_dispatch_raises_method_not_allowed_when_verb_not_matched(endpoint: RestEndpoint):
    request = create_mock(method='NO_METHOD')

    with pytest.raises(HttpMethodNotAllowed):
        await endpoint.dispatch(request)
コード例 #19
0
async def test_dispatch_raises_bad_request_when_match_info_does_not_exist(endpoint: RestEndpoint):
    endpoint.register_method('BAD_MATCH_INFO', coroutine(lambda no_match: no_match))
    request = create_mock(method='BAD_MATCH_INFO', match_info={})

    with pytest.raises(HttpBadRequest):
        await endpoint.dispatch(request)
コード例 #20
0
async def test_dispatch_passes_match_info_when_required(endpoint: RestEndpoint):
    endpoint.register_method('MATCH_INFO', coroutine(lambda prop1, prop2: (prop2, prop1)))
    request = create_mock(method='MATCH_INFO', match_info={'prop1': 1, 'prop2': 2})

    assert await endpoint.dispatch(request) == (2, 1)
コード例 #21
0
async def test_dispatch_passes_request_when_required(endpoint: RestEndpoint):
    endpoint.register_method('REQUEST', coroutine(lambda request: request))
    request = create_mock(method='REQUEST', match_info={})

    assert await endpoint.dispatch(request) == request
コード例 #22
0
async def test_dispatch_uses_correct_handler_for_verb(endpoint: RestEndpoint):
    endpoint.register_method('VERB1', coroutine(lambda: 5))
    endpoint.register_method('VERB2', coroutine(lambda: 17))

    assert await endpoint.dispatch(create_mock(method='VERB1', match_info={})) == 5
    assert await endpoint.dispatch(create_mock(method='VERB2', match_info={})) == 17
コード例 #23
0
async def test_put_should_return_404_when_property_does_not_exist(endpoint: PropertyEndpoint, model_1: Model):
    request = create_mock(method='PUT', json=coroutine(lambda: {'does_not_exist': 'vertical'}))

    response = await endpoint.put(request, model_1.id, 'does_not_exist')

    assert response.status == 404
コード例 #24
0
    def test_should_create_a_simple_mock(self):

        actual = create_mock()

        assert_that(actual, instance_of(Mock))
コード例 #25
0
    def test_should_create_mock_with_property_from_given_keyword_argument(self):

        actual = create_mock(foo='bar')

        assert_that(actual.foo, equal_to('bar'))
コード例 #26
0
    def test_should_create_mock_with_property_from_given_keyword_argument(
            self):

        actual = create_mock(foo='bar')

        assert_that(actual.foo, equal_to('bar'))
コード例 #27
0
    def test_should_create_a_simple_mock(self):

        actual = create_mock()

        assert_that(actual, instance_of(Mock))
コード例 #28
0
async def test_post_with_id_defined_should_raise_401(endpoint: CollectionEndpoint):
    request = create_mock(method='POST', json=coroutine(lambda: {'name': 'henry', 'age': 469, 'id': 123}))

    with pytest.raises(HttpBadRequest):
        await endpoint.post(request)
コード例 #29
0
ファイル: test_runner.py プロジェクト: atbentley/plank
def inspector(happy_task, circular_dependency_task):
    inspector = create_mock(Inspector)
    when(inspector).get_tasks().then_return({'happy_task': happy_task,
                                             'circular_dependency_task': circular_dependency_task})
    return inspector
コード例 #30
0
ファイル: test_runner.py プロジェクト: atbentley/plank
def happy_task():
    task = create_mock(Task)
    when(task).has_circular_dependency().then_return(False)
    return task
コード例 #31
0
    def test_should_create_mock_with_three_properties_when_three_properties_given(self):

        actual = create_mock(foo='bar', spam='eggs', hello='world')

        assert_that(actual.foo, equal_to('bar'))
        assert_that(actual.spam, equal_to('eggs'))