def test_create_post_interactor_with_valid_details():

    # Arrange
    user_id = 1
    post_content = 'New Post'
    expected_post_id = 1
    expected_post_id_dict = {
        'post_id': expected_post_id
    }
    post_storage = create_autospec(PostStorageInterface)
    presenter = create_autospec(PresenterInterface)
    interactor = CreatePostInteractor(post_storage=post_storage,
                                      presenter=presenter)

    post_storage.create_post.return_value = expected_post_id
    presenter.get_create_post_response.return_value = expected_post_id_dict

    # Act
    actual_post_id_dict = interactor.create_post(user_id=user_id,
                                                 post_content=post_content)

    # Arrange
    assert actual_post_id_dict == expected_post_id_dict
    post_storage.create_post.assert_called_once_with(user_id=user_id,
                                                     post_content=post_content)
    presenter.get_create_post_response.assert_called_once_with(
        post_id=expected_post_id
    )
Beispiel #2
0
def test_create_post_interactor():
    #arrrange
    new_post_id = 1
    user_id = 1
    post_content = "hello"
    expected_response_dict = {"post_id": 1}
    storage = create_autospec(PostStorageInterface)
    presenter = create_autospec(PresenterInterface)
    interactor = CreatePostInteractor(
        storage,
        presenter,
    )
    storage.create_post.return_value = new_post_id
    presenter.get_create_post_response.return_value = \
     expected_response_dict

    #act
    response = interactor.create_post_return_post_id(
        user_id=user_id,
        post_content=post_content,
    )

    #assert
    storage.create_post.assert_called_once_with(user_id=user_id,
                                                post_content=post_content)
    presenter.get_create_post_response.assert_called_once_with(
        post_id=new_post_id)
    assert response == expected_response_dict
def api_wrapper(*args, **kwargs):
    user = kwargs['user']
    request_data = kwargs['request_data']

    post_storage = Storage()
    presenter = Presenter()

    interactor = CreatePostInteractor(post_storage, presenter)

    response = interactor.create_post(request_data["post_content"], user.id)

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
Beispiel #4
0
def api_wrapper(*args, **kwargs):

    request_data = kwargs["request_data"]
    user = kwargs["user"]

    post_storage = PostStorageImpl()
    json_presenter = JsonPresenterImpl()
    interactor = CreatePostInteractor(post_storage, json_presenter)

    response = interactor.create_post(request_data["post_content"], user.id)

    from django.http.response import HttpResponse
    import json
    return HttpResponse(json.dumps(response), status=201)
Beispiel #5
0
    def test_new_post(self):
        post_storage_mock = Mock(spec=PostStorage)
        presenter_mock = Mock(spec=JsonPresenter)
        create_post = CreatePostInteractor(post_storage_mock, presenter_mock)

        post_id = 1

        post_storage_mock.create_post.return_value = post_id
        presenter_mock.get_create_post_response.return_value = {"post_id": 1}
        response = create_post.create_post("test post", 1)

        post_storage_mock.create_post.assert_called_once_with("test post", 1)
        presenter_mock.get_create_post_response.assert_called_once_with(
            post_id)
        assert response == {"post_id": 1}
def api_wrapper(*args, **kwargs):
    user = kwargs["user"]
    request_data = kwargs["request_data"]
    post_content = request_data["post_content"]
    presenter = PresenterImplementation()
    storage = PostStorageImplementation()
    interactor = CreatePostInteractor(storage, presenter)

    post_id_dict = interactor.create_post_return_post_id(
        user_id=user.id, post_content=post_content)

    response_data = json.dumps(post_id_dict)
    response = HttpResponse(response_data, status=201)

    return response
Beispiel #7
0
def api_wrapper(*args, **kwargs):

    user = kwargs['user']
    request_data = kwargs["request_data"]
    post_content = request_data["content"]
    user_id = user.id

    post_storage = StorageImplementation()
    presenter = PresenterImplementation()
    interactor = CreatePostInteractor(post_storage=post_storage,
                                      presenter=presenter)

    post_id_dict = interactor.create_post(user_id=user_id,
                                          post_content=post_content)

    response_data = json.dumps(post_id_dict)

    return HttpResponse(response_data, status=201)
    def test_create_post(self):
        post_storage_mock = create_autospec(PostStorage)
        presenter_mock = create_autospec(JsonPresenter)

        post_id = 1
        user_id = 1
        post_content = "This is a post"
        response_data = {"post_id": post_id}

        post_dto = PostDTO(
            post_id=post_id, user_id=user_id, post_content=post_content,
            created_time=datetime.now())

        post_storage_mock.create_post.return_value = post_dto
        presenter_mock.get_create_post_response.return_value = response_data

        create_post_interactor = CreatePostInteractor(post_storage_mock,
                                                      presenter_mock)
        response = create_post_interactor.create_post(post_content, user_id)

        post_storage_mock.create_post.assert_called_once_with(post_content,
                                                              user_id)
        presenter_mock.get_create_post_response.assert_called_once_with(post_dto)
        assert response == response_data