Skip to content

Commit

Permalink
Merge pull request #2033 from uktrade/uat
Browse files Browse the repository at this point in the history
PROD Release
  • Loading branch information
depsiatwal authored Jun 10, 2024
2 parents 5481ddb + cbc133c commit 3ec90d0
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 12 deletions.
9 changes: 9 additions & 0 deletions api/cases/generated_documents/signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,22 @@ def _get_signature_text(date):


def _add_blank_page(pdf_bytes: bytes):

original_pdf_buffer = BytesIO(pdf_bytes)
original_pdf_info = PyPDF2.PdfFileReader(original_pdf_buffer).getDocumentInfo()

# Write a blank page
pdf = PyPDF2.PdfFileReader(BytesIO(pdf_bytes))
out_pdf = PyPDF2.PdfFileWriter()
out_pdf.appendPagesFromReader(pdf)
out_pdf.addBlankPage()
num_pages = out_pdf.getNumPages()

out_pdf.addMetadata(
{
"/Title": original_pdf_info.title if original_pdf_info.title else "",
}
)
# Convert back into bytes
output_buffer = BytesIO()
out_pdf.write(output_buffer)
Expand Down
6 changes: 6 additions & 0 deletions api/cases/generated_documents/tests/test_generate_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from api.cases.generated_documents.helpers import html_to_pdf
from api.letter_templates.helpers import generate_preview, DocumentPreviewError
from api.cases.generated_documents.models import GeneratedCaseDocument
from api.cases.generated_documents.signing import sign_pdf
from api.licences.enums import LicenceStatus
from api.licences.tests.factories import StandardLicenceFactory
from api.staticdata.decisions.models import Decision
Expand Down Expand Up @@ -531,9 +532,14 @@ class TestGeneratedTemplatePDF(DataTestClient):
],
)
def test_pdf_titles(self, temp, title):
# Make sure this setting is True
settings.DOCUMENT_SIGNING_ENABLED = True

case = self.create_standard_application_case(self.organisation, user=self.exporter_user)
html = generate_preview(layout=temp, case=case, text="")
pdf = html_to_pdf(html, temp, None)
pdf = sign_pdf(pdf)

with io.BytesIO(pdf) as open_pdf_file:
reader = PdfFileReader(open_pdf_file)
meta = reader.getDocumentInfo()
Expand Down
6 changes: 6 additions & 0 deletions api/conf/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ def get_paginated_response(self, data):
"results": data,
}
)


class MaxFiftyPageSizePaginator(MaxPageNumberPagination):
page_size = 50
page_size_query_param = "page_size"
max_page_size = 50
6 changes: 5 additions & 1 deletion api/external_data/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ def get_value_from_instance(self, instance, field_value_to_ignore=None):
filter=["lowercase", "asciifolding", "trim", address_stop_words_filter, ngram_filter],
)

# Previously the tokenizer was whitespace, but this was changed to standard
# as the whitespace tokenizer was splitting on hyphens and including commas in the tokens
# standard tokenizer will remove these characters

address_analyzer_no_ngram = analysis.analyzer(
"address_analyzer",
tokenizer="whitespace",
tokenizer="standard",
filter=["lowercase", "asciifolding", "trim", address_stop_words_filter],
)

Expand Down
37 changes: 37 additions & 0 deletions api/external_data/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,43 @@ def test_denial_entity_search_invalid_query(self):
response = response.json()
self.assertEqual(response["errors"]["search"], "Invalid search string")

@pytest.mark.elasticsearch
@parameterized.expand(
[
(
{"search": "address:(Street Name, Springfield)"},
[
"1000 Street <mark>Name</mark>, City <mark>Name</mark>",
"2001 Street <mark>Name</mark>, City <mark>Name</mark> 3",
"2000 Street <mark>Name</mark>, City <mark>Name</mark> 2",
],
),
(
{"search": "address:(\Example\ Avenue, Townsville)"},
["2 <mark>Example</mark> Road, <mark>Example</mark> City"],
),
({"search": "address:(road,)"}, []),
]
)
def test_denial_search_with_chars(self, query, expected_items):
call_command("search_index", models=["external_data.denialentity"], action="rebuild", force=True)
url = reverse("external_data:denial-list")
file_path = os.path.join(settings.BASE_DIR, "external_data/tests/denial_valid.csv")
with open(file_path, "rb") as f:
content = f.read()
response = self.client.post(url, {"csv_file": content}, **self.gov_headers)

self.assertEqual(response.status_code, 201)

url = reverse("external_data:denial_search-list")

response = self.client.get(url, query, **self.gov_headers)
self.assertEqual(response.status_code, 200)
response_json = response.json()
search_results = [r["address"] for r in response_json["results"]]

self.assertEqual(search_results, expected_items)

@pytest.mark.elasticsearch
def test_search(self):
Index("sanctions-alias-test").create(ignore=[400])
Expand Down
4 changes: 2 additions & 2 deletions api/external_data/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.conf import settings

from api.core.authentication import GovAuthentication
from api.conf.pagination import MaxPageNumberPagination
from api.conf.pagination import MaxFiftyPageSizePaginator
from api.core.search.validators import QueryStringValidationMixin
from api.external_data import documents, models, serializers

Expand Down Expand Up @@ -41,7 +41,7 @@ class DenialSearchView(QueryStringValidationMixin, DocumentViewSet):
document = documents.DenialEntityDocument
serializer_class = serializers.DenialSearchSerializer
authentication_classes = (GovAuthentication,)
pagination_class = MaxPageNumberPagination
pagination_class = MaxFiftyPageSizePaginator
lookup_field = "id"
filter_backends = [
filter_backends.SourceBackend,
Expand Down
7 changes: 0 additions & 7 deletions api/goods/goods_paginator.py

This file was deleted.

4 changes: 2 additions & 2 deletions api/goods/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
GoodOnApplicationInternalDocument,
)
from api.cases.libraries.delete_notifications import delete_exporter_notifications
from api.conf.pagination import MaxFiftyPageSizePaginator
from api.core.authentication import ExporterAuthentication, SharedAuthentication, GovAuthentication
from api.core.exceptions import BadRequestError
from api.core.helpers import str_to_bool
Expand All @@ -23,7 +24,6 @@
from api.documents.libraries.delete_documents_on_bad_request import delete_documents_on_bad_request
from api.documents.models import Document
from api.goods.enums import GoodStatus, GoodPvGraded, ItemCategory
from api.goods.goods_paginator import GoodListPaginator
from api.goods.helpers import (
FIREARMS_CORE_TYPES,
check_if_firearm_details_edited_on_unsupported_good,
Expand Down Expand Up @@ -67,7 +67,7 @@
class GoodList(ListCreateAPIView):
authentication_classes = (ExporterAuthentication,)
serializer_class = GoodListSerializer
pagination_class = GoodListPaginator
pagination_class = MaxFiftyPageSizePaginator

def get_serializer_context(self):
return {
Expand Down

0 comments on commit 3ec90d0

Please sign in to comment.