예제 #1
0
def update_article(slug):
    if not slug:
        return '', 400

    data = request.json

    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

    kwargs = {}
    kwargs['token'] = auth_token
    kwargs['slug'] = slug
    if 'title' in data['article'] and data['article']['title']:
        kwargs['title'] = data['article']['title']
    if 'description' in data['article'] and data['article']['description']:
        kwargs['description'] = data['article']['description']
    if 'body' in data['article'] and data['article']['body']:
        kwargs['body'] = data['article']['body']
    command = UpdateArticleCommand(**kwargs)

    article_resource = ArticleService.update_article(command)

    return jsonify(article_resource), 204
예제 #2
0
    def test_updating_an_articles_title(self, persisted_article):
        command = UserAuthenticationCommand(email='*****@*****.**',
                                            password='******')
        authenticated_user = UserAuthenticationService.authenticate_user(
            command)

        command = UpdateArticleCommand(
            token=authenticated_user['token'],
            slug=persisted_article.slug,
            title='How to train your dragon - Part 2 - At Worlds End')
        updated_article = ArticleService.update_article(command)
        assert updated_article[
            'slug'] == 'how-to-train-your-dragon-part-2-at-worlds-end'