Skip to content

Commit

Permalink
feat(engines): create template test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Louis Fuchs committed May 30, 2022
1 parent d34b70e commit 8c4cad1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Binary file not shown.
47 changes: 46 additions & 1 deletion document_merge_service/api/tests/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import os

import openpyxl
import pytest
from django.urls import reverse
from docx import Document
Expand Down Expand Up @@ -111,6 +112,46 @@ def test_template_download_url(db, client, template):
@pytest.mark.parametrize(
"template_name,engine,status_code,group,require_authentication,authenticated",
[
(
"xlsx-template.xlsx",
models.Template.XLSX_TEMPLATE,
status.HTTP_201_CREATED,
None,
False,
False,
),
(
"xlsx-template.xlsx",
models.Template.XLSX_TEMPLATE,
status.HTTP_201_CREATED,
None,
True,
True,
),
(
"xlsx-template.xlsx",
models.Template.XLSX_TEMPLATE,
status.HTTP_401_UNAUTHORIZED,
None,
True,
False,
),
(
"xlsx-template.xlsx",
models.Template.XLSX_TEMPLATE,
status.HTTP_400_BAD_REQUEST,
"unknown",
True,
True,
),
(
"xlsx-template.xlsx",
models.Template.XLSX_TEMPLATE,
status.HTTP_201_CREATED,
"admin",
True,
True,
),
(
"docx-template.docx",
models.Template.DOCX_TEMPLATE,
Expand Down Expand Up @@ -215,7 +256,11 @@ def test_template_create(
template_link = data["template"]
response = client.get(template_link)
assert response.status_code == status.HTTP_200_OK
Document(io.BytesIO(response.content))
file_ = io.BytesIO(response.content)
if engine == "xlsx-template":
openpyxl.load_workbook(file_)
else:
Document(file_)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 8c4cad1

Please sign in to comment.