Exemplo n.º 1
0
    def test_creating_an_article_via_article_service(self, persisted_user,
                                                     test_domain):
        # Authenticate user to generate valid token
        command = UserAuthenticationCommand(email='*****@*****.**',
                                            password='******')
        authenticated_user = UserAuthenticationService.authenticate_user(
            command)

        command = CreateArticleCommand(
            token=authenticated_user['token'],
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"])

        article_resource = ArticleService.create_article(command)
        assert article_resource is not None
Exemplo n.º 2
0
def create_article():
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(" ")[1]
    else:
        auth_token = None

    if not auth_token:
        return '', 401

    data = request.json

    command = CreateArticleCommand(token=auth_token,
                                   title=data['article']['title'],
                                   description=data['article']['description'],
                                   body=data['article']['body'],
                                   tag_list=data['article']['tag_list'])

    article_resource = ArticleService.create_article(command)

    return jsonify(article_resource), 201
Exemplo n.º 3
0
    def test_that_article_is_persisted_in_the_article_service(
            self, persisted_user, test_domain):
        # Authenticate user to generate valid token
        command = UserAuthenticationCommand(email='*****@*****.**',
                                            password='******')
        authenticated_user = UserAuthenticationService.authenticate_user(
            command)

        command = CreateArticleCommand(
            token=authenticated_user['token'],
            title="How to train your dragon",
            description="Ever wonder how?",
            body="You have to believe",
            tag_list=["reactjs", "angularjs", "dragons"])

        article_resource = ArticleService.create_article(command)

        # FIXME Should check for this via Repository itself
        article_dao = test_domain.get_dao(Article)
        persisted_article = article_dao.get(article_resource['id'])
        assert persisted_article is not None
        assert hasattr(persisted_article, 'id')