Exemplo n.º 1
0
def test_group_letters_splits_on_file_size_and_file_count(notify_api):
    letters = [
        # ends under max file size but next file is too big
        {'Key': 'A.pdf', 'Size': 1},
        {'Key': 'B.pdf', 'Size': 2},
        # ends on exactly max number of files and file size
        {'Key': 'C.pdf', 'Size': 3},
        {'Key': 'D.pdf', 'Size': 1},
        {'Key': 'E.pdf', 'Size': 1},
        # exactly max file size goes in next file
        {'Key': 'F.pdf', 'Size': 5},
        # file size is within max but number of files reaches limit
        {'Key': 'G.pdf', 'Size': 1},
        {'Key': 'H.pdf', 'Size': 1},
        {'Key': 'I.pdf', 'Size': 1},
        # whatever's left goes in last list
        {'Key': 'J.pdf', 'Size': 1},
    ]

    with set_config_values(notify_api, {
        'MAX_LETTER_PDF_ZIP_FILESIZE': 5,
        'MAX_LETTER_PDF_COUNT_PER_ZIP': 3
    }):
        x = group_letters(letters)

        assert next(x) == [{'Key': 'A.pdf', 'Size': 1}, {'Key': 'B.pdf', 'Size': 2}]
        assert next(x) == [{'Key': 'C.pdf', 'Size': 3}, {'Key': 'D.pdf', 'Size': 1}, {'Key': 'E.pdf', 'Size': 1}]
        assert next(x) == [{'Key': 'F.pdf', 'Size': 5}]
        assert next(x) == [{'Key': 'G.pdf', 'Size': 1}, {'Key': 'H.pdf', 'Size': 1}, {'Key': 'I.pdf', 'Size': 1}]
        assert next(x) == [{'Key': 'J.pdf', 'Size': 1}]
        # make sure iterator is exhausted
        assert next(x, None) is None
Exemplo n.º 2
0
def test_group_letters_includes_pdf_files(key):
    letters = [{'Key': key, 'Size': 1, 'ServiceId': '123'}]
    assert list(group_letters(letters)) == [[{
        'Key': key,
        'Size': 1,
        'ServiceId': '123'
    }]]
Exemplo n.º 3
0
def test_group_letters_splits_on_file_size(notify_api, mocker):
    mocker.patch('app.celery.letters_pdf_tasks.letter_in_created_state', return_value=True)
    letters = [
        # ends under max but next one is too big
        {'Key': 'A.pdf', 'Size': 1}, {'Key': 'B.pdf', 'Size': 2},
        # ends on exactly max
        {'Key': 'C.pdf', 'Size': 3}, {'Key': 'D.pdf', 'Size': 1}, {'Key': 'E.pdf', 'Size': 1},
        # exactly max goes in next file
        {'Key': 'F.pdf', 'Size': 5},
        # if it's bigger than the max, still gets included
        {'Key': 'G.pdf', 'Size': 6},
        # whatever's left goes in last list
        {'Key': 'H.pdf', 'Size': 1}, {'Key': 'I.pdf', 'Size': 1},
    ]

    with set_config_values(notify_api, {'MAX_LETTER_PDF_ZIP_FILESIZE': 5}):
        x = group_letters(letters)

        assert next(x) == [{'Key': 'A.pdf', 'Size': 1}, {'Key': 'B.pdf', 'Size': 2}]
        assert next(x) == [{'Key': 'C.pdf', 'Size': 3}, {'Key': 'D.pdf', 'Size': 1}, {'Key': 'E.pdf', 'Size': 1}]
        assert next(x) == [{'Key': 'F.pdf', 'Size': 5}]
        assert next(x) == [{'Key': 'G.pdf', 'Size': 6}]
        assert next(x) == [{'Key': 'H.pdf', 'Size': 1}, {'Key': 'I.pdf', 'Size': 1}]
        # make sure iterator is exhausted
        assert next(x, None) is None
Exemplo n.º 4
0
def test_group_letters_splits_on_file_count(notify_api):
    letters = [
        {'Key': 'A.pdf', 'Size': 1, 'ServiceId': '123'},
        {'Key': 'B.pdf', 'Size': 2, 'ServiceId': '123'},
        {'Key': 'C.pdf', 'Size': 3, 'ServiceId': '123'},
        {'Key': 'D.pdf', 'Size': 1, 'ServiceId': '123'},
        {'Key': 'E.pdf', 'Size': 1, 'ServiceId': '123'},
        {'Key': 'F.pdf', 'Size': 5, 'ServiceId': '123'},
        {'Key': 'G.pdf', 'Size': 6, 'ServiceId': '123'},
        {'Key': 'H.pdf', 'Size': 1, 'ServiceId': '123'},
        {'Key': 'I.pdf', 'Size': 1, 'ServiceId': '123'},
    ]

    with set_config_values(notify_api, {'MAX_LETTER_PDF_COUNT_PER_ZIP': 3}):
        x = group_letters(letters)

        assert next(x) == [
            {'Key': 'A.pdf', 'Size': 1, 'ServiceId': '123'},
            {'Key': 'B.pdf', 'Size': 2, 'ServiceId': '123'},
            {'Key': 'C.pdf', 'Size': 3, 'ServiceId': '123'}
        ]
        assert next(x) == [
            {'Key': 'D.pdf', 'Size': 1, 'ServiceId': '123'},
            {'Key': 'E.pdf', 'Size': 1, 'ServiceId': '123'},
            {'Key': 'F.pdf', 'Size': 5, 'ServiceId': '123'}
        ]
        assert next(x) == [
            {'Key': 'G.pdf', 'Size': 6, 'ServiceId': '123'},
            {'Key': 'H.pdf', 'Size': 1, 'ServiceId': '123'},
            {'Key': 'I.pdf', 'Size': 1, 'ServiceId': '123'}
        ]
        # make sure iterator is exhausted
        assert next(x, None) is None
Exemplo n.º 5
0
def test_group_letters_splits_on_file_count(notify_api, mocker):
    mocker.patch('app.celery.letters_pdf_tasks.letter_in_created_state', return_value=True)
    letters = [
        {'Key': 'A.pdf', 'Size': 1},
        {'Key': 'B.pdf', 'Size': 2},
        {'Key': 'C.pdf', 'Size': 3},
        {'Key': 'D.pdf', 'Size': 1},
        {'Key': 'E.pdf', 'Size': 1},
        {'Key': 'F.pdf', 'Size': 5},
        {'Key': 'G.pdf', 'Size': 6},
        {'Key': 'H.pdf', 'Size': 1},
        {'Key': 'I.pdf', 'Size': 1},
    ]

    with set_config_values(notify_api, {'MAX_LETTER_PDF_COUNT_PER_ZIP': 3}):
        x = group_letters(letters)

        assert next(x) == [{'Key': 'A.pdf', 'Size': 1}, {'Key': 'B.pdf', 'Size': 2}, {'Key': 'C.pdf', 'Size': 3}]
        assert next(x) == [{'Key': 'D.pdf', 'Size': 1}, {'Key': 'E.pdf', 'Size': 1}, {'Key': 'F.pdf', 'Size': 5}]
        assert next(x) == [{'Key': 'G.pdf', 'Size': 6}, {'Key': 'H.pdf', 'Size': 1}, {'Key': 'I.pdf', 'Size': 1}]
        # make sure iterator is exhausted
        assert next(x, None) is None
Exemplo n.º 6
0
def test_group_letters_splits_on_file_size(notify_api):
    letters = [
        # ends under max but next one is too big
        {'Key': 'A.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'B.pdf', 'Size': 2, 'ServiceId': '123'},
        # ends on exactly max
        {'Key': 'C.pdf', 'Size': 3, 'ServiceId': '123'},
        {'Key': 'D.pdf', 'Size': 1, 'ServiceId': '123'},
        {'Key': 'E.pdf', 'Size': 1, 'ServiceId': '123'},
        # exactly max goes in next file
        {'Key': 'F.pdf', 'Size': 5, 'ServiceId': '123'},
        # if it's bigger than the max, still gets included
        {'Key': 'G.pdf', 'Size': 6, 'ServiceId': '123'},
        # whatever's left goes in last list
        {'Key': 'H.pdf', 'Size': 1, 'ServiceId': '123'}, {'Key': 'I.pdf', 'Size': 1, 'ServiceId': '123'},
    ]

    with set_config_values(notify_api, {'MAX_LETTER_PDF_ZIP_FILESIZE': 5}):
        x = group_letters(letters)

        assert next(x) == [
            {'Key': 'A.pdf', 'Size': 1, 'ServiceId': '123'},
            {'Key': 'B.pdf', 'Size': 2, 'ServiceId': '123'}
        ]
        assert next(x) == [
            {'Key': 'C.pdf', 'Size': 3, 'ServiceId': '123'},
            {'Key': 'D.pdf', 'Size': 1, 'ServiceId': '123'},
            {'Key': 'E.pdf', 'Size': 1, 'ServiceId': '123'}
        ]
        assert next(x) == [{'Key': 'F.pdf', 'Size': 5, 'ServiceId': '123'}]
        assert next(x) == [{'Key': 'G.pdf', 'Size': 6, 'ServiceId': '123'}]
        assert next(x) == [
            {'Key': 'H.pdf', 'Size': 1, 'ServiceId': '123'},
            {'Key': 'I.pdf', 'Size': 1, 'ServiceId': '123'}
        ]
        # make sure iterator is exhausted
        assert next(x, None) is None
Exemplo n.º 7
0
def test_group_letters_with_no_letters():
    assert list(group_letters([])) == []
Exemplo n.º 8
0
def test_group_letters_ignores_non_pdfs(key):
    letters = [{'Key': key, 'Size': 1}]
    assert list(group_letters(letters)) == []
Exemplo n.º 9
0
def test_group_letters_with_no_letters(notify_api, mocker):
    mocker.patch("app.celery.letters_pdf_tasks.letter_in_created_state",
                 return_value=True)
    assert list(group_letters([])) == []
Exemplo n.º 10
0
def test_group_letters_ignores_notifications_already_sent(notify_api, mocker):
    mock = mocker.patch("app.celery.letters_pdf_tasks.letter_in_created_state",
                        return_value=False)
    letters = [{"Key": "A.pdf"}]
    assert list(group_letters(letters)) == []
    mock.assert_called_once_with("A.pdf")
Exemplo n.º 11
0
def test_group_letters_ignores_non_pdfs(notify_api, mocker):
    mocker.patch("app.celery.letters_pdf_tasks.letter_in_created_state",
                 return_value=True)
    letters = [{"Key": "A.zip"}]
    assert list(group_letters(letters)) == []
Exemplo n.º 12
0
def test_group_letters_splits_on_file_size_and_file_count(notify_api, mocker):
    mocker.patch("app.celery.letters_pdf_tasks.letter_in_created_state",
                 return_value=True)
    letters = [
        # ends under max file size but next file is too big
        {
            "Key": "A.pdf",
            "Size": 1
        },
        {
            "Key": "B.pdf",
            "Size": 2
        },
        # ends on exactly max number of files and file size
        {
            "Key": "C.pdf",
            "Size": 3
        },
        {
            "Key": "D.pdf",
            "Size": 1
        },
        {
            "Key": "E.pdf",
            "Size": 1
        },
        # exactly max file size goes in next file
        {
            "Key": "F.pdf",
            "Size": 5
        },
        # file size is within max but number of files reaches limit
        {
            "Key": "G.pdf",
            "Size": 1
        },
        {
            "Key": "H.pdf",
            "Size": 1
        },
        {
            "Key": "I.pdf",
            "Size": 1
        },
        # whatever's left goes in last list
        {
            "Key": "J.pdf",
            "Size": 1
        },
    ]

    with set_config_values(
            notify_api,
        {
            "MAX_LETTER_PDF_ZIP_FILESIZE": 5,
            "MAX_LETTER_PDF_COUNT_PER_ZIP": 3
        },
    ):
        x = group_letters(letters)

        assert next(x) == [{
            "Key": "A.pdf",
            "Size": 1
        }, {
            "Key": "B.pdf",
            "Size": 2
        }]
        assert next(x) == [
            {
                "Key": "C.pdf",
                "Size": 3
            },
            {
                "Key": "D.pdf",
                "Size": 1
            },
            {
                "Key": "E.pdf",
                "Size": 1
            },
        ]
        assert next(x) == [{"Key": "F.pdf", "Size": 5}]
        assert next(x) == [
            {
                "Key": "G.pdf",
                "Size": 1
            },
            {
                "Key": "H.pdf",
                "Size": 1
            },
            {
                "Key": "I.pdf",
                "Size": 1
            },
        ]
        assert next(x) == [{"Key": "J.pdf", "Size": 1}]
        # make sure iterator is exhausted
        assert next(x, None) is None
Exemplo n.º 13
0
def test_group_letters_splits_on_file_count(notify_api, mocker):
    mocker.patch("app.celery.letters_pdf_tasks.letter_in_created_state",
                 return_value=True)
    letters = [
        {
            "Key": "A.pdf",
            "Size": 1
        },
        {
            "Key": "B.pdf",
            "Size": 2
        },
        {
            "Key": "C.pdf",
            "Size": 3
        },
        {
            "Key": "D.pdf",
            "Size": 1
        },
        {
            "Key": "E.pdf",
            "Size": 1
        },
        {
            "Key": "F.pdf",
            "Size": 5
        },
        {
            "Key": "G.pdf",
            "Size": 6
        },
        {
            "Key": "H.pdf",
            "Size": 1
        },
        {
            "Key": "I.pdf",
            "Size": 1
        },
    ]

    with set_config_values(notify_api, {"MAX_LETTER_PDF_COUNT_PER_ZIP": 3}):
        x = group_letters(letters)

        assert next(x) == [
            {
                "Key": "A.pdf",
                "Size": 1
            },
            {
                "Key": "B.pdf",
                "Size": 2
            },
            {
                "Key": "C.pdf",
                "Size": 3
            },
        ]
        assert next(x) == [
            {
                "Key": "D.pdf",
                "Size": 1
            },
            {
                "Key": "E.pdf",
                "Size": 1
            },
            {
                "Key": "F.pdf",
                "Size": 5
            },
        ]
        assert next(x) == [
            {
                "Key": "G.pdf",
                "Size": 6
            },
            {
                "Key": "H.pdf",
                "Size": 1
            },
            {
                "Key": "I.pdf",
                "Size": 1
            },
        ]
        # make sure iterator is exhausted
        assert next(x, None) is None
Exemplo n.º 14
0
def test_group_letters_splits_on_file_size(notify_api, mocker):
    mocker.patch("app.celery.letters_pdf_tasks.letter_in_created_state",
                 return_value=True)
    letters = [
        # ends under max but next one is too big
        {
            "Key": "A.pdf",
            "Size": 1
        },
        {
            "Key": "B.pdf",
            "Size": 2
        },
        # ends on exactly max
        {
            "Key": "C.pdf",
            "Size": 3
        },
        {
            "Key": "D.pdf",
            "Size": 1
        },
        {
            "Key": "E.pdf",
            "Size": 1
        },
        # exactly max goes in next file
        {
            "Key": "F.pdf",
            "Size": 5
        },
        # if it's bigger than the max, still gets included
        {
            "Key": "G.pdf",
            "Size": 6
        },
        # whatever's left goes in last list
        {
            "Key": "H.pdf",
            "Size": 1
        },
        {
            "Key": "I.pdf",
            "Size": 1
        },
    ]

    with set_config_values(notify_api, {"MAX_LETTER_PDF_ZIP_FILESIZE": 5}):
        x = group_letters(letters)

        assert next(x) == [{
            "Key": "A.pdf",
            "Size": 1
        }, {
            "Key": "B.pdf",
            "Size": 2
        }]
        assert next(x) == [
            {
                "Key": "C.pdf",
                "Size": 3
            },
            {
                "Key": "D.pdf",
                "Size": 1
            },
            {
                "Key": "E.pdf",
                "Size": 1
            },
        ]
        assert next(x) == [{"Key": "F.pdf", "Size": 5}]
        assert next(x) == [{"Key": "G.pdf", "Size": 6}]
        assert next(x) == [{
            "Key": "H.pdf",
            "Size": 1
        }, {
            "Key": "I.pdf",
            "Size": 1
        }]
        # make sure iterator is exhausted
        assert next(x, None) is None