Skip to content

Commit

Permalink
Merge pull request #15 from nationalarchives/AYR-384/record-metadata-…
Browse files Browse the repository at this point in the history
…view

Ayr 384/record metadata view
  • Loading branch information
anthonyhashemi authored Oct 30, 2023
2 parents c68ebb3 + 529137f commit be2670a
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 66 deletions.
6 changes: 5 additions & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@


def null_to_dash(value):
return "—" if value == "null" else value
if value == "null":
return "-"
if value is None:
return "-"
return value


def create_app(config_class=Config):
Expand Down
36 changes: 36 additions & 0 deletions app/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def poc_search():
search_logic.generate_open_search_client_and_make_poc_search(query)
)
results = open_search_response["hits"]["hits"]
session["search_results"] = results

num_records_found = len(results)

Expand All @@ -110,6 +111,41 @@ def poc_search():
)


@bp.route("/record", methods=["GET"])
def record():
"""
Render the record details page.
This function retrieves search results from the session, looks for a specific
record based on the 'record_id' provided in the query parameters, and renders
the record details on the 'record.html' template.
Returns:
A rendered HTML page with record details.
"""
# Retrieve the search results from the session
results = session.get("search_results", [])

# Get the record_id from the query parameters
record_id = request.args.get("record_id")

if not record_id:
return render_template("404.html")

# Find the specific record in the search results
record_details = None

for result in results:
if result["_source"]["id"] == record_id:
record_details = result["_source"]
break

if not record_details:
return render_template("404.html")

return render_template("record.html", consignment_files=record_details)


@bp.route("/browse", methods=["GET"])
def browse():
return render_template("browse.html")
Expand Down
2 changes: 1 addition & 1 deletion app/templates/main/poc-search.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h2 class="govuk-heading-m">{{ num_records_found }} records found</h2>
<tbody class="govuk-table__body">
{% for record in results %}
<tr class="govuk-table__row">
<td class="govuk-table__cell govuk-body govuk-!-font-size-14"><a href="{{'#'}}">{{ record._source.file_name }}</a></td>
<td class="govuk-table__cell govuk-body govuk-!-font-size-14"><a href="{{ url_for('main.record', record_id=record._source.id) }}">{{ record._source.file_name }}</a></td>
<td class="govuk-table__cell govuk-body govuk-!-font-size-14">{{ record._source.description }}</td>
<td class="govuk-table__cell govuk-body govuk-!-font-size-14">{{ record._source.date_last_modified }}</td>
<td class="govuk-table__cell govuk-body govuk-!-font-size-14">{{ record._source.legal_status }}</td>
Expand Down
102 changes: 51 additions & 51 deletions app/templates/main/record.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
{% block pageTitle %}Record – {{config['SERVICE_NAME']}} – GOV.UK{% endblock %}

{% block beforeContent %}
{{ super() }}
{{ govukBackLink({
'text': "Back",
'href': url_for('main.index')
}) }}
{{ super() }}
{{ govukBackLink({
'text': "Back",
'href': url_for('main.poc_search')
}) }}
{% endblock %}

{% block content %}
Expand All @@ -20,54 +20,54 @@
<h1 class="govuk-heading-xl">Record metadata</h1>
<div class="govuk-grid-row">
<div class="govuk-grid-column">
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">ID</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.id | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Source organisation</dt>
<dd class="govuk-summary-list__value">{{ consignment._source.Source_Organization | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Consignment ID</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.join_field.parent | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">File name</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.file_name | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Description</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.description | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Rights copyright</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.rights_copyright | null_to_dash }}</dd>
<dl class="govuk-summary-list">
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">ID</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.id | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Legal status</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.legal_status | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Held by</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.held_by | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Last modified</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.date_last_modified | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Closure type</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.closure_type | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Language</dt>
<dd class="govuk-summary-list__value">{{ consignment_files._source.language | null_to_dash }}</dd>
</div>
</dl>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Source organisation</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.Source_Organization | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Consignment ID</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.join_field.parent | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">File name</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.file_name | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Description</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.description | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Rights copyright</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.rights_copyright | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Legal status</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.legal_status | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Held by</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.held_by | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Last modified</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.date_last_modified | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Closure type</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.closure_type | null_to_dash }}</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">Language</dt>
<dd class="govuk-summary-list__value">{{ consignment_files.language | null_to_dash }}</dd>
</div>
</dl>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
76 changes: 63 additions & 13 deletions e2e_tests/test_record_metadata.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,67 @@
# import re
# from playwright.sync_api import Page, expect
import re
import time

from playwright.sync_api import Page, expect

# def test_page_title_and_header(page: Page):
# page.goto("/record")
# expect(page).to_have_title(
# re.compile("Record – AYR - Access Your Records – GOV.UK")
# )
# expect(page.get_by_text("Record metadata")).to_be_visible()

def test_page_title_and_header(page: Page):
"""
Given the user accesses AYR
When the user loads the record page
Then the AYR record title should be displayed
"""
page.goto("http://localhost:5000/record")
expect(page).to_have_title(
re.compile("Page not found – AYR - Access Your Records – GOV.UK")
)
expect(page.get_by_text("Page not found")).to_be_visible()

# def test_back_link(page: Page):
# page.goto("/record")
# page.get_by_role("link", name="Back", exact=True).click()
# page.wait_for_url("/")
# page.close()

def test_invalid_record(page: Page):
"""
Given the user accesses AYR
When the user loads an invalid record page
Then the AYR 404 page should be displayed
"""
page.goto("http://localhost:5000/record")
expect(page.get_by_text("Page not found")).to_be_visible()


def test_back_link(page: Page):
"""
Given a user is on the record page
When the user selects the back button / breadcrumb
Then the user should be navigated back to the the results page
"""
page.goto("http://localhost:5000/poc-search-view")
page.locator("#searchInput").click()
page.locator("#searchInput").fill("public record")
page.get_by_role("button", name="Search").click()
expect(page.get_by_text("records found")).to_be_visible()
page.get_by_role("link", name="file-b2.txt").click()
page.get_by_role("link", name="Back", exact=True).click()
page.wait_for_url("/poc-search-view")
page.close()


def test_searched_record_metadata(page: Page):
"""
Given the user has clicked on a result displayed on the search page with results displayed.
When the user is on the record page
Then the table should display the relevant metadata for the record such as
"Source organisation" and "Consignment ID,"
"""
time.sleep(10)
page.goto("http://localhost:5000/poc-search-view")
page.locator("#searchInput").click()
page.locator("#searchInput").fill("public record")
page.get_by_role("button", name="Search").click()
expect(page.get_by_text("records found")).to_be_visible()
page.get_by_role("link", name="file-b2.txt").click()

# Verify if the expected metadata is visible on the record page
assert page.locator("dt:has-text('Source organisation') + dd").is_visible()
assert page.locator("dt:has-text('Consignment ID') + dd").is_visible()

# Close the page
page.close()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ readme = "README.md"

[tool.bandit]
exclude_dirs = ['*_test.py', '*/test_*.py', 'venv']
skips = ["B105"]

[tool.poetry.dependencies]
python = "^3.11"
Expand Down
1 change: 1 addition & 0 deletions testing_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

class TestingConfig(Config):
TESTING = True
SECRET_KEY = "TEST_SECRET_KEY" # pragma: allowlist secret
WTF_CSRF_ENABLED = False

0 comments on commit be2670a

Please sign in to comment.