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

        list_command = ListArticlesCommand(token=authenticated_user['token'],
                                           tag='tag1')
        article_resources = ArticleService.list_articles(list_command)
        if len(article_resources) > 1:
            assert 'tag1' in article_resources[0]['tag_list']

        list_command = ListArticlesCommand(token=authenticated_user['token'],
                                           tag='tag17')
        article_resources = ArticleService.list_articles(list_command)
        if len(article_resources) > 1:
            assert 'tag17' in article_resources[0]['tag_list']

        list_command = ListArticlesCommand(token=authenticated_user['token'],
                                           tag='tag24')
        article_resources = ArticleService.list_articles(list_command)
        if len(article_resources) > 1:
            assert 'tag24' in article_resources[0]['tag_list']
Exemplo n.º 2
0
    def test_listing_articles_without_query_filters(self, persisted_user,
                                                    persisted_articles):
        # Authenticate user to generate valid token
        command = UserAuthenticationCommand(email='*****@*****.**',
                                            password='******')
        authenticated_user = UserAuthenticationService.authenticate_user(
            command)

        list_command = ListArticlesCommand(token=authenticated_user['token'])
        article_resources = ArticleService.list_articles(list_command)
        assert len(article_resources) == 20
Exemplo n.º 3
0
    def test_listing_articles_with_author_filter(self, persisted_user, user1,
                                                 user2, persisted_articles):
        # Authenticate user to generate valid token
        command = UserAuthenticationCommand(email='*****@*****.**',
                                            password='******')
        authenticated_user = UserAuthenticationService.authenticate_user(
            command)

        list_command = ListArticlesCommand(token=authenticated_user['token'],
                                           author=user1.username)
        article_resources = ArticleService.list_articles(list_command)
        if len(article_resources) > 1:
            assert article_resources[0]['author']['username'] == user1.username
        no_of_user1_articles = len(article_resources)

        list_command = ListArticlesCommand(token=authenticated_user['token'],
                                           author=user2.username)
        article_resources = ArticleService.list_articles(list_command)
        if len(article_resources) > 1:
            assert article_resources[0]['author']['username'] == user2.username
        no_of_user2_articles = len(article_resources)

        assert no_of_user1_articles + no_of_user2_articles == 30
Exemplo n.º 4
0
def list_articles():
    auth_header = request.headers.get('Authorization')
    if auth_header:
        auth_token = auth_header.split(" ")[1]
    else:
        auth_token = None

    tag = request.args.get('tag')
    author = request.args.get('author')
    favorited = request.args.get('favorited')
    limit = request.args.get('limit')
    offset = request.args.get('offset')

    command = ListArticlesCommand(token=auth_token,
                                  tag=tag,
                                  author=author,
                                  favorited=favorited,
                                  limit=limit,
                                  offset=offset)
    article_resources = ArticleService.list_articles(command)

    return jsonify(article_resources), 200
Exemplo n.º 5
0
    def test_listing_articles_with_favorited_filter(self, persisted_user,
                                                    user1, user2,
                                                    persisted_articles):
        command = UserAuthenticationCommand(email=user1.email,
                                            password=user1.password)
        authenticated_user = UserAuthenticationService.authenticate_user(
            command)

        favorite_command = FavoriteArticleCommand(
            token=authenticated_user['token'], slug=persisted_articles[5].slug)
        UserFavoritingService.favorite_article(favorite_command)

        command = UserAuthenticationCommand(email='*****@*****.**',
                                            password='******')
        authenticated_user = UserAuthenticationService.authenticate_user(
            command)

        list_command = ListArticlesCommand(token=authenticated_user['token'],
                                           favorited=user1.username)
        article_resources = ArticleService.list_articles(list_command)
        assert len(article_resources) == 1
        assert article_resources[0]['slug'] == persisted_articles[5].slug