Beispiel #1
0
def test_article_read_manager_not_clear_session_on_api_error(
        mock_bulk_create_article_read, sso_request, sso_user):
    session_key = helpers.SessionArticlesViewedManager.SESSION_KEY
    sso_request.session[session_key] = [1, 2, 3]
    mock_bulk_create_article_read.return_value = create_response(
        400, content='validation error')

    with pytest.raises(AssertionError) as execinfo:
        helpers.ArticlesViewedManagerFactory(sso_request)

    assert sso_request.session[session_key] == [1, 2, 3]
    assert str(execinfo.value) == 'validation error'
Beispiel #2
0
def test_article_read_manager_handles_no_read_articles_on_synchronisation(
    mock_bulk_create_article_read,
    sso_request,
    sso_user,
):
    session_key = helpers.SessionArticlesViewedManager.SESSION_KEY
    sso_request.session[session_key] = []
    mock_bulk_create_article_read.return_value = create_response(200)

    helpers.ArticlesViewedManagerFactory(sso_request)

    # call the api method anyway - because the response contains the list of
    # read articles
    assert mock_bulk_create_article_read.call_count == 1

    assert sso_request.session[session_key] == []
Beispiel #3
0
def test_article_read_manager_synchronises_articles(
    mock_bulk_create_article_read,
    sso_request,
    sso_user,
):
    session_key = helpers.SessionArticlesViewedManager.SESSION_KEY
    sso_request.session[session_key] = [1, 2, 3]
    mock_bulk_create_article_read.return_value = create_response(200)

    helpers.ArticlesViewedManagerFactory(sso_request)

    assert mock_bulk_create_article_read.call_count == 1
    assert mock_bulk_create_article_read.call_args == call(
        article_uuids=frozenset([1, 2, 3]),
        sso_session_id=sso_user.session_id,
    )

    assert sso_request.session[session_key] == []
Beispiel #4
0
 def create_article_manager(self, request):
     return helpers.ArticlesViewedManagerFactory(
         request=request, current_article=self.article)
Beispiel #5
0
def test_database_get_view_progress_for_groups(mock_bulk_create_article_read,
                                               sso_request, articles_read):
    mock_bulk_create_article_read.return_value = create_response(
        200, json_body=articles_read)
    # trigger the caching of the articles
    sso_request.session[helpers.SessionArticlesViewedManager.SESSION_KEY] = [1]

    manager = helpers.ArticlesViewedManagerFactory(sso_request)

    actual = manager.get_view_progress_for_groups()
    assert actual == {
        'all': {
            'read': 3,
            'total': 45
        },
        'business_planning': {
            'read': 0,
            'total': 11
        },
        'customer_insights': {
            'read': 0,
            'total': 4
        },
        'finance': {
            'read': 0,
            'total': 7
        },
        'getting_paid': {
            'read': 2,
            'total': 5
        },
        'market_research': {
            'read': 0,
            'total': 5
        },
        'operations_and_compliance': {
            'read': 1,
            'total': 10
        },
        'persona_new': {
            'read': 2,
            'total': 18
        },
        'persona_occasional': {
            'read': 2,
            'total': 38
        },
        'persona_regular': {
            'read': 0,
            'total': 18
        },
        'custom_persona_new': {
            'read': 2,
            'total': 18
        },
        'custom_persona_occasional': {
            'read': 2,
            'total': 38
        },
        'custom_persona_regular': {
            'read': 0,
            'total': 18
        },
    }
Beispiel #6
0
def test_session_get_view_progress_for_groups(anon_request, articles_read):

    key = helpers.SessionArticlesViewedManager.SESSION_KEY
    anon_request.session[key] = [i['article_uuid'] for i in articles_read]

    manager = helpers.ArticlesViewedManagerFactory(anon_request)
    actual = manager.get_view_progress_for_groups()

    assert actual == {
        'all': {
            'read': 3,
            'total': 45
        },
        'business_planning': {
            'read': 0,
            'total': 11
        },
        'customer_insights': {
            'read': 0,
            'total': 4
        },
        'finance': {
            'read': 0,
            'total': 7
        },
        'getting_paid': {
            'read': 2,
            'total': 5
        },
        'market_research': {
            'read': 0,
            'total': 5
        },
        'operations_and_compliance': {
            'read': 1,
            'total': 10
        },
        'persona_new': {
            'read': 2,
            'total': 18
        },
        'persona_occasional': {
            'read': 2,
            'total': 38
        },
        'persona_regular': {
            'read': 0,
            'total': 18
        },
        'custom_persona_new': {
            'read': 2,
            'total': 18
        },
        'custom_persona_occasional': {
            'read': 2,
            'total': 38
        },
        'custom_persona_regular': {
            'read': 0,
            'total': 18
        },
    }