Exemple #1
0
def test_get_content_based_redirect(root_doc, redirect_doc, redirect_to_self,
                                    redirect_to_home, redirect_to_macros,
                                    case):
    if case == "normal":
        doc = root_doc
        expected = None
    elif case == "redirect":
        doc = redirect_doc
        expected = (
            get_s3_key(root_doc,
                       prefix_with_forward_slash=True,
                       suffix_file_extension=False),
            True,
        )
    elif case == "redirect-to-self":
        doc = redirect_to_self
        expected = None
    elif case == "redirect-to-home":
        doc = redirect_to_home
        expected = ("/en-US/", False)
    else:
        doc = redirect_to_macros
        expected = (absolutify("/en-US/dashboards/macros",
                               for_wiki_site=True), False)
    assert get_content_based_redirect(doc) == expected
Exemple #2
0
def test_publish_multiple(get_s3_bucket_mock, root_doc, redirect_doc,
                          redirect_to_home, trans_doc):
    """
    Test the publish task for multiple documents of various kinds, including
    standard documents and redirects.
    """
    trans_doc.delete()
    log_mock = mock.Mock()
    get_s3_bucket_mock.return_value = s3_bucket_mock = get_mocked_s3_bucket()
    publish(
        [trans_doc.pk, root_doc.pk, redirect_doc.pk, redirect_to_home.pk],
        log=log_mock,
        completion_message="Done!",
    )
    s3_bucket_mock.put_object.assert_has_calls([
        mock.call(
            ACL="public-read",
            Key=get_s3_key(root_doc),
            Body=json.dumps(document_api_data(root_doc)),
            ContentType="application/json",
            ContentLanguage=root_doc.locale,
        ),
        mock.call(
            ACL="public-read",
            Key=get_s3_key(redirect_doc),
            WebsiteRedirectLocation=get_s3_key(
                root_doc,
                prefix_with_forward_slash=True,
                suffix_file_extension=False,
            ),
            ContentType="application/json",
            ContentLanguage=redirect_doc.locale,
            Body=json.dumps(
                document_api_data(
                    redirect_url=get_content_based_redirect(redirect_doc)[0])),
        ),
        mock.call(
            ACL="public-read",
            Key=get_s3_key(redirect_to_home),
            Body=json.dumps(document_api_data(redirect_url="/en-US/")),
            ContentType="application/json",
            ContentLanguage=redirect_to_home.locale,
        ),
    ])
    log_mock.error.assert_called_once_with(
        "Document with pk={} does not exist".format(trans_doc.pk))
    log_mock.info.assert_has_calls([
        mock.call("Published S3 Object #1"),
        mock.call("Published S3 Object #2"),
        mock.call("Published S3 Object #3"),
        mock.call("Done!"),
    ])
Exemple #3
0
def test_publish_redirect(get_s3_bucket_mock, root_doc, redirect_doc):
    """
    Test the publish task for a document that redirects to another document
    within the S3 bucket.
    """
    log_mock = mock.Mock()
    get_s3_bucket_mock.return_value = s3_bucket_mock = get_mocked_s3_bucket()
    publish([redirect_doc.pk], log=log_mock)

    s3_bucket_mock.put_object.assert_called_once_with(
        ACL='public-read',
        Key=get_s3_key(redirect_doc),
        WebsiteRedirectLocation=get_s3_key(
            root_doc, prefix_with_forward_slash=True, suffix_file_extension=False),
        ContentType='application/json',
        ContentLanguage=redirect_doc.locale,
        Body=json.dumps(document_api_data(None, redirect_url=get_content_based_redirect(redirect_doc)[0]))
    )
    log_mock.info.assert_called_once_with('Published S3 Object #1')
Exemple #4
0
def test_get_content_based_redirect(root_doc, redirect_doc, redirect_to_self,
                                    redirect_to_home, redirect_to_macros, case):
    if case == 'normal':
        doc = root_doc
        expected = None
    elif case == 'redirect':
        doc = redirect_doc
        expected = (get_s3_key(root_doc, prefix_with_forward_slash=True), True)
    elif case == 'redirect-to-self':
        doc = redirect_to_self
        expected = None
    elif case == 'redirect-to-home':
        doc = redirect_to_home
        expected = ('/en-US/', False)
    else:
        doc = redirect_to_macros
        expected = (
            absolutify('/en-US/dashboards/macros', for_wiki_site=True), False)
    assert get_content_based_redirect(doc) == expected
Exemple #5
0
def test_get_content_based_redirect(root_doc, redirect_doc, redirect_to_self,
                                    redirect_to_home, redirect_to_macros, case):
    if case == 'normal':
        doc = root_doc
        expected = None
    elif case == 'redirect':
        doc = redirect_doc
        expected = (get_s3_key(root_doc, for_redirect=True), True)
    elif case == 'redirect-to-self':
        doc = redirect_to_self
        expected = None
    elif case == 'redirect-to-home':
        doc = redirect_to_home
        expected = ('/en-US/', False)
    else:
        doc = redirect_to_macros
        expected = (
            absolutify('/en-US/dashboards/macros', for_wiki_site=True), False)
    assert get_content_based_redirect(doc) == expected